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

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

Writer's picture: Subbu AddankiSubbu Addanki

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

Hello VFX & Animation Professionals! ๐Ÿ‘‹

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

Over time, Maya scenes can become cluttered with unused nodes, empty groups, orphaned shaders, and other unnecessary elements that bloat file size and slow down performance. CleanupTool helps you tidy up your scenes by automatically identifying and removing these unwanted items, ensuring your projects run smoothly.



๐™’๐™๐™–๐™ฉ ๐˜พ๐™ก๐™š๐™–๐™ฃ๐™ช๐™ฅ๐™๐™ค๐™ค๐™ก ๐™Š๐™›๐™›๐™š๐™ง๐™จ:

  • Automated Cleanup:ย Removes unused nodes, empty groups, orphaned shaders, and more.

  • Selective Cleaning:ย Choose which types of nodes to clean for granular control.

  • Performance Boost:ย Streamlines your scene for faster load times and smoother interactions.

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


import maya.cmds as mc


def cleanupScene(delete_unused_nodes=True, delete_empty_groups=True, DEBUG=False):

"""

Cleans up the Maya scene by deleting unused nodes, empty transform groups, and unused shaders,

while preserving constraints and effectors.

:param delete_unused_nodes: <bool> Deletes unused nodes if True.

:param delete_empty_groups: <bool> Deletes empty transform groups if True.

:param DEBUG: <bool> If True, prints detailed debugging information.

:return: <None>

"""

if delete_unused_nodes:

# Delete 'unknown' nodes

unknown_nodes = mc.ls(type='unknown')

if unknown_nodes:

try:

mc.delete(unknown_nodes)

print("Deleted 'unknown' nodes.")

if DEBUG:

print("List of deleted 'unknown' nodes:", unknown_nodes)

except Exception as e:

if DEBUG:

print("Failed to delete 'unknown' nodes:", e)

# Delete 'unknownDag' nodes

unknownDag_nodes = mc.ls(type='unknownDag')

if unknownDag_nodes:

try:

mc.delete(unknownDag_nodes)

print("Deleted 'unknownDag' nodes.")

if DEBUG:

print("List of deleted 'unknownDag' nodes:", unknownDag_nodes)

except Exception as e:

if DEBUG:

print("Failed to delete 'unknownDag' nodes:", e)

# Delete 'unknownTransform' nodes

unknownTransform_nodes = mc.ls(type='unknownTransform')

if unknownTransform_nodes:

try:

mc.delete(unknownTransform_nodes)

print("Deleted 'unknownTransform' nodes.")

if DEBUG:

print("List of deleted 'unknownTransform' nodes:", unknownTransform_nodes)

except Exception as e:

if DEBUG:

print("Failed to delete 'unknownTransform' nodes:", e)

if delete_empty_groups:

all_transforms = mc.ls(type='transform')

for obj in all_transforms:

# Skip default Maya transforms

if obj in ['root', 'persp', 'front', 'side', 'top', 'back', 'left', 'right']:

continue

if mc.objExists(obj):

children = mc.listRelatives(obj, children=True)

if not children:

# Check if the group has any connections

connections = mc.listConnections(obj, connections=True, plugs=True) or []

if connections:

if DEBUG:

print("Skipping deletion of group '{}' because it has connections.".format(obj))

continue


# Check for critical node types connected to this group

connected_nodes = mc.listConnections(obj, type=True, plugs=False) or []

# Define node types that should prevent deletion

critical_node_types = ['constraint', 'ikEffector', 'joint', 'controller', 'blendShape', 'nurbsCurve']

has_critical = False

for connected_node in connected_nodes:

node_type = mc.nodeType(connected_node)

if node_type in critical_node_types:

has_critical = True

if DEBUG:

print("Skipping deletion of group '{}' because it has a connected '{}' node.".format(obj, node_type))

break

if has_critical:

continue


# If no connections and no critical nodes, delete the empty group

try:

mc.delete(obj)

print("Deleted empty group: '{}'".format(obj))

except Exception as e:

if DEBUG:

print("Failed to delete group '{}': {}".format(obj, e))

print("Scene cleanup completed.")


# Example usage:

# To run without debugging information

cleanupScene()


# To run with debugging information

# cleanupScene(DEBUG=True)

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

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

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

  • Streamlined Scenes:ย Keeps your scenes clean and organized by removing unnecessary elements.

  • Improved Performance:ย Reduces file size and memory usage, leading to faster load times.

  • User-Friendly Interface:ย Simple and intuitive UI for quick scene cleanup.



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

โ€ข ๐Ÿš€ Boost Efficiency:ย Save time by automating the tedious task of manual cleanup.

โ€ข ๐Ÿ› ๏ธ Enhance Workflow:ย Focus on creative work without worrying about scene clutter.

โ€ข ๐Ÿ“ˆ Optimize Performance:ย Ensure your scenes run smoothly, even with complex projects.

โ€ข ๐Ÿ’ก User-Friendly:ย Accessible for artists of all levels, with easy-to-use options.

โœจ Ready to Keep Your Scenes Clean and Efficient?

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


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

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

  • Backup Your Scene:ย Before running cleanup operations, it's good practice to save a backup of your scene.

  • Selective Cleanup:ย Use the checkboxes to control which elements are deleted, giving you flexibility.

  • Extend Functionality:ย Customize the script to include additional cleanup options like deleting unused nodes or optimizing meshes.

15 views0 comments

Comments


bottom of page