## popup message -A disappearing message def popupMessage(function_name): """ Displays an in-view message indicating that a function has been copied to the clipboard. :param function_name: #The name of the function that has been copied. :return: """ mc.inViewMessage(amg="Copied!!\nFunction name '{0}' has been copied to the clipboard.".format(function_name), pos='midCenter', fade=True) # Test function is provided to test main function popupMessage def test_popupMessage(): popupMessage(function_name='exampleFunction') # Since mc.inViewMessage affects the UI, manual verification is required. print("popupMessage executed successfully.") test_popupMessage()
top of page

โœจ๐ŸŽฏ ๐˜ฟ๐™–๐™ฎ14 -100-๐˜ฟ๐™–๐™ฎ๐™จ ๐˜พ๐™ค๐™™๐™š ๐˜พ๐™๐™–๐™ก๐™ก๐™š๐™ฃ๐™œ๐™š ๐Ÿš€๐ŸŽจ

Writer's picture: Subbu AddankiSubbu Addanki

โœจ๐ŸŽฌ ๐™‰๐™š๐™ฌ ๐™๐™ค๐™ค๐™ก ๐™„๐™ฃ๐™ฉ๐™ง๐™ค: "๐™Œ๐™ช๐™ž๐™˜๐™ ๐˜ผ๐™ก๐™ž๐™œ๐™ฃ" ๐Ÿงฒ

Hello VFX & Animation Professionals! ๐Ÿ‘‹

I'm excited to introduce a handy addition to your Maya toolkitโ€”QuickAlign! ๐ŸŒŸ

Aligning multiple objects to a target object can be time-consuming, especially when dealing with complex scenes. QuickAlign simplifies this process by allowing you to quickly align selected objects to a target object's position, rotation, and scale with customizable options.


๐™’๐™๐™–๐™ฉ ๐™Œ๐™ช๐™ž๐™˜๐™ ๐˜ผ๐™ก๐™ž๐™œ๐™ฃ ๐™Š๐™›๐™›๐™š๐™ง๐™จ:

  • Automation: Instantly align objects to a target object's attributes.

  • Customization: Choose which attributes to alignโ€”position, rotation, scale.

  • User-Friendly Interface:ย Streamlines alignment tasks, saving you time.

๐Ÿ› ๏ธ ๐™Œ๐™ช๐™ž๐™˜๐™ ๐˜ผ๐™ก๐™ž๐™œ๐™ฃ ๐Ÿงฒ (๐™ข๐™–๐™ฎ๐™–.๐™˜๐™ข๐™™๐™จ ๐™‘๐™š๐™ง๐™จ๐™ž๐™ค๐™ฃ):

import maya.cmds as mc

def quickAlign(target_object, align_translate=True, align_rotate=True, align_scale=False):

"""

Aligns selected objects to the target object's attributes.

:param target_object: <str> The name of the target object.

:param align_translate: <bool> Align translation if True.

:param align_rotate: <bool> Align rotation if True.

:param align_scale: <bool> Align scale if True.

:return: <None>

"""

if not mc.objExists(target_object):

mc.warning("Target object '{}' does not exist.".format(target_object))

return

selected_objects = mc.ls(selection=True)

if not selected_objects:

mc.warning("No objects selected for alignment.")

return

selected_objects = [obj for obj in selected_objects if obj != target_object]

target_translate = mc.xform(target_object, query=True, translation=True, worldSpace=True)

target_rotate = mc.xform(target_object, query=True, rotation=True, worldSpace=True)

target_scale = mc.xform(target_object, query=True, scale=True, relative=True)

for obj in selected_objects:

if align_translate:

mc.xform(obj, translation=target_translate, worldSpace=True)

if align_rotate:

mc.xform(obj, rotation=target_rotate, worldSpace=True)

if align_scale:

mc.xform(obj, scale=target_scale, relative=True)

print("Aligned '{}' to '{}'.".format(obj, target_object))

# Usage example:

# Select the objects to align, then run:

# quickAlign('locator2', align_translate=True, align_rotate=True, align_scale=False)


# Test function is provided to test main function quickAlign

def test_quickAlign():

# Create target object

target_object = mc.spaceLocator(name='locator2')[0]

# Set target object's attributes

mc.xform(target_object, translation=(10, 20, 30), worldSpace=True)

mc.xform(target_object, rotation=(45, 0, 90), worldSpace=True)

# Create objects to align

obj1 = mc.polySphere(name='sphere1')[0]

obj2 = mc.polyCube(name='cube1')[0]

# Select objects to align

mc.select(obj1, obj2)

# Run the quickAlign function

quickAlign(target_object, align_translate=True, align_rotate=True, align_scale=False)

# Query the aligned objects' translation and rotation

obj1_translate = mc.xform(obj1, query=True, translation=True, worldSpace=True)

obj2_translate = mc.xform(obj2, query=True, translation=True, worldSpace=True)

obj1_rotate = mc.xform(obj1, query=True, rotation=True, worldSpace=True)

obj2_rotate = mc.xform(obj2, query=True, rotation=True, worldSpace=True)

# Assert translations match target

assert obj1_translate == [10, 20, 30], "Translation of sphere1 did not align correctly."

assert obj2_translate == [10, 20, 30], "Translation of cube1 did not align correctly."

# Assert rotations match target

target_rotate = mc.xform(target_object, query=True, rotation=True, worldSpace=True)

assert obj1_rotate == target_rotate, "Rotation of sphere1 did not align correctly."

assert obj2_rotate == target_rotate, "Rotation of cube1 did not align correctly."

# Assert scale remains unchanged if align_scale=False

obj1_scale = mc.xform(obj1, query=True, scale=True, relative=True)

obj2_scale = mc.xform(obj2, query=True, scale=True, relative=True)

assert obj1_scale == [1, 1, 1], "Scale of sphere1 was incorrectly modified."

assert obj2_scale == [1, 1, 1], "Scale of cube1 was incorrectly modified."

print("All tests for quickAlign passed successfully.")

test_quickAlign()

๐Ÿ› ๏ธ ๐™Œ๐™ช๐™ž๐™˜๐™ ๐˜ผ๐™ก๐™ž๐™œ๐™ฃ ๐Ÿงฒ (๐™‹๐™ฎ๐™Ž๐™ž๐™™๐™š2 ๐™‘๐™š๐™ง๐™จ๐™ž๐™ค๐™ฃ):



[Todayโ€™s Challenge is to take this simple code to next level.. I am sharing images of these advanced codes...]

๐Ÿ” ๐™’๐™๐™–๐™ฉ ๐™Œ๐™ช๐™ž๐™˜๐™ ๐˜ผ๐™ก๐™ž๐™œ๐™ฃ ๐™Š๐™›๐™›๐™š๐™ง๐™จ:

  • Efficiency: Quickly align multiple objects to a target without manual adjustments.

  • Customization: Choose which attributes to alignโ€”translation, rotation, or scale.

  • Flexibility:ย Works with any objects in your scene.


๐Ÿ”ง ๐™†๐™š๐™ฎ ๐˜ฝ๐™š๐™ฃ๐™š๐™›๐™ž๐™ฉ๐™จ:

โ€ข ๐Ÿš€ Boost Productivity:ย Save time on aligning objects manually.

โ€ข ๐Ÿ› ๏ธ Enhance Workflow:ย Ideal for positioning props, aligning cameras, or setting up scenes.

โ€ข ๐Ÿ“ˆ Improve Consistency:ย Ensures objects are accurately aligned to the target.

โ€ข ๐Ÿ’ก User-Friendly Interface:ย Intuitive UI suitable for artists of all levels.

โœจ Ready to Simplify Your Alignment Tasks?

Try out QuickAlignย today and enhance your Maya workflow! Feel free to reach out or comment below to see it in action. Letโ€™s continue to elevate our Maya scripting together! ๐Ÿ’ช๐ŸŽ‰

๐™Ž๐™ช๐™—๐™—๐™ช'๐™จ ๐™‡๐™ž๐™ฃ๐™ ๐™จ :

๐Ÿ› ๏ธ๐˜ผ๐™™๐™™๐™ž๐™ฉ๐™ž๐™ค๐™ฃ๐™–๐™ก ๐™๐™ž๐™ฅ๐™จ:

  • Error Handling:ย The scripts include checks for target object existence and selection to prevent errors.

  • Customization:ย Extend the tool to include alignment to pivot points or bounding boxes.

  • Integration:ย Add this tool to your Maya shelf or integrate it into existing scripts for quick access.

3 views0 comments

ใ‚ณใƒกใƒณใƒˆ


bottom of page