## 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

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

Writer's picture: Subbu AddankiSubbu Addanki

โœจ๐ŸŽฌ ๐™‰๐™š๐™ฌ ๐™๐™ค๐™ค๐™ก ๐™„๐™ฃ๐™ฉ๐™ง๐™ค: "๐˜พ๐™ค๐™ก๐™ค๐™ง๐™Ž๐™ฌ๐™–๐™ฅ๐™ฅ๐™š๐™ง" ๐ŸŽจ

Hello VFX & Animation Professionals! ๐Ÿ‘‹

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

When working with complex scenes, you might need to quickly change the display colors of multiple objects for better visualization or organization. ColorSwapperย automates this process by allowing you to assign random or specific colors to selected objects.



๐˜ž๐˜ฉ๐˜ข๐˜ต ๐˜พ๐™ค๐™ก๐™ค๐™ง๐™Ž๐™ฌ๐™–๐™ฅ๐™ฅ๐™š๐™ง ๐™Š๐™›๐™›๐™š๐™ง๐™จ:

  • Automation: Quickly change the display colors of multiple objects.

  • Customization: Choose specific colors or apply random colors.

  • User-Friendly Interface:ย Simplifies color assignments, saving you time.

๐Ÿ› ๏ธ ๐˜พ๐™ค๐™ก๐™ค๐™ง๐™Ž๐™ฌ๐™–๐™ฅ๐™ฅ๐™š๐™ง ๐ŸŽจ (๐™ข๐™–๐™ฎ๐™–.๐™˜๐™ข๐™™๐™จ ๐™‘๐™š๐™ง๐™จ๐™ž๐™ค๐™ฃ):

import maya.cmds as cmds
import random
def colorSwapper(randomize=False, colorIndex=17):
ย ย ย ย """
ย ย ย ย Changes the display color of selected objects.
ย ย ย ย 
ย ย ย ย :param randomize: <bool> If True, assigns random colors.
ย ย ย ย :param colorIndex: <int> The color index to assign if randomize is False.
ย ย ย ย """
ย ย ย ย selected_objects = cmds.ls(selection=True)
ย ย ย ย if not selected_objects:
ย ย ย ย ย ย ย ย cmds.warning("No objects selected.")
ย ย ย ย ย ย ย ย return
ย ย ย ย 
ย ย ย ย for obj in selected_objects:
ย ย ย ย ย ย ย ย if randomize:
ย ย ย ย ย ย ย ย ย ย ย ย colorIndex = random.randint(1, 31)
ย ย ย ย ย ย ย ย cmds.setAttr(obj + ".overrideEnabled", 1)
ย ย ย ย ย ย ย ย cmds.setAttr(obj + ".overrideColor", colorIndex)
ย ย ย ย ย ย ย ย print("Changed color of '{}' to index {}.".format(obj, colorIndex))
# Usage example:
# Select objects and run:
# colorSwapper(randomize=True)

# Test function is provided to test main function colorSwapper
def test_colorSwapper():
ย ย ย ย # Create necessary objects in the scene
ย ย ย ย obj1 = cmds.polyCube(name='test_obj1')[0]
ย ย ย ย obj2 = cmds.polySphere(name='test_obj2')[0]
ย ย ย ย 
ย ย ย ย # Select the objects to be tested
ย ย ย ย cmds.select(obj1, obj2)
ย ย ย ย 
ย ย ย ย # Apply colorSwapper with randomize=True
ย ย ย ย colorSwapper(randomize=True)
ย ย ย ย 
ย ย ย ย # Verify that overrideEnabled is set to 1
ย ย ย ย override_enabled_obj1 = cmds.getAttr("{}.overrideEnabled".format(obj1))
ย ย ย ย override_enabled_obj2 = cmds.getAttr("{}.overrideEnabled".format(obj2))
ย ย ย ย assert override_enabled_obj1 == 1, "Override Enabled for obj1 was not set correctly."
ย ย ย ย assert override_enabled_obj2 == 1, "Override Enabled for obj2 was not set correctly."
ย ย ย ย 
ย ย ย ย # Verify that overrideColor is within valid range
ย ย ย ย override_color_obj1 = cmds.getAttr("{}.overrideColor".format(obj1))
ย ย ย ย override_color_obj2 = cmds.getAttr("{}.overrideColor".format(obj2))
ย ย ย ย assert 1 <= override_color_obj1 <= 31, "Override Color for obj1 is out of valid range."
ย ย ย ย assert 1 <= override_color_obj2 <= 31, "Override Color for obj2 is out of valid range."
ย ย ย ย 
ย ย ย ย print("colorSwapper executed successfully with randomize=True.")

test_colorSwapper()

๐Ÿ› ๏ธ ๐˜พ๐™ค๐™ก๐™ค๐™ง๐™Ž๐™ฌ๐™–๐™ฅ๐™ฅ๐™š๐™ง ๐ŸŽจ (๐™‹๐™ฎ๐™Ž๐™ž๐™™๐™š2 ๐™‘๐™š๐™ง๐™จ๐™ž๐™ค๐™ฃ):


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

๐Ÿ” ๐™’๐™๐™–๐™ฉ ๐˜พ๐™ค๐™ก๐™ค๐™ง๐™Ž๐™ฌ๐™–๐™ฅ๐™ฅ๐™š๐™ง ๐™Š๐™›๐™›๐™š๐™ง๐™จ:

  • Efficiency: Quickly change colors without manually adjusting each object.

  • Customization: Assign specific colors or randomize for variety.

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



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

โ€ข ๐Ÿš€ Boost Productivity:ย Save time on color assignment tasks.

โ€ข ๐Ÿ› ๏ธ Enhance Scene Organization:ย Use colors to categorize objects visually.

โ€ข ๐ŸŽจ Improve Visualization:ย Makes complex scenes easier to manage and navigate.

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

โœจ Ready to Simplify Your Color Management?

Try out ColorSwapperย 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 object selection to prevent errors.

  • Customization:ย Extend the tool to include a color picker for precise color selection.

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

3 views0 comments

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


bottom of page