## 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
Writer's pictureSubbu Addanki

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

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

Hello VFX & Animation Professionals! ๐Ÿ‘‹

I'm thrilled to introduce an indispensable addition to your Maya toolkitโ€”ShaderCleanerPro! ๐ŸŒŸ

Managing shaders efficiently is vital for maintaining optimized and high-quality rendering in your 3D projects. ShaderCleanerPro streamlines this process by providing advanced shader management features, allowing you to clean up unused shaders, optimize shader networks, and ensure seamless material application across your models.


๐™’๐™๐™–๐™ฉ ๐™Ž๐™๐™–๐™™๐™š๐™ง๐˜พ๐™ก๐™š๐™–๐™ฃ๐™š๐™ง๐™‹๐™ง๐™ค ๐ŸŽจ๐Ÿงน ๐™Š๐™›๐™›๐™š๐™ง๐™จ:

  • Unused Shader Removal:ย Automatically detects and removes shaders that are not assigned to any objects, reducing scene complexity.

  • Shader Network Optimization:ย Optimizes shader connections for better performance and easier management.

  • Batch Shader Management:ย Clean and optimize multiple shaders simultaneously, saving valuable time on repetitive tasks.

  • User-Friendly Interface:ย Intuitive UI designed to simplify shader management, making it accessible for artists of all levels.


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

def shader_cleaner_pro(objects, remove_unused=True, optimize_network=True):
ย ย ย ย """
ย ย ย ย Cleans shaders by removing unused shaders and optimizing shader networks.

ย ย ย ย :param objects: <list> List of objects to clean shaders from.
ย ย ย ย :param remove_unused: <bool> Whether to remove unused shaders.
ย ย ย ย :param optimize_network: <bool> Whether to optimize shader networks.
ย ย ย ย """
ย ย ย ย if not objects:
ย ย ย ย ย ย ย ย cmds.warning("No objects provided for shader cleaning.")
ย ย ย ย ย ย ย ย return

ย ย ย ย # List of default shaders to exclude
ย ย ย ย default_shaders = {'lambert1', 'particleCloud1', 'standardSurface1'}

ย ย ย ย # Collect all shaders used by the selected objects
ย ย ย ย shaders_in_use = set()
ย ย ย ย for obj in objects:
ย ย ย ย ย ย ย ย # Get all shapes under the transform (if any)
ย ย ย ย ย ย ย ย shapes = cmds.listRelatives(obj, shapes=True, fullPath=True) or []
ย ย ย ย ย ย ย ย for shape in shapes:
ย ย ย ย ย ย ย ย ย ย ย ย # Get the shading groups connected to the shape
ย ย ย ย ย ย ย ย ย ย ย ย shading_grps = cmds.listConnections(shape, type='shadingEngine') or []
ย ย ย ย ย ย ย ย ย ย ย ย for sg in shading_grps:
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย # Get the surface shaders connected to the shading group
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย surface_shaders = cmds.listConnections(sg + '.surfaceShader') or []
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย shaders_in_use.update(surface_shaders)

ย ย ย ย # Find all shaders in the scene
ย ย ย ย all_shaders = set(cmds.ls(materials=True))

ย ย ย ย # Identify unused shaders
ย ย ย ย unused_shaders = all_shaders - shaders_in_use - default_shaders

ย ย ย ย if remove_unused and unused_shaders:
ย ย ย ย ย ย ย ย for shader in unused_shaders:
ย ย ย ย ย ย ย ย ย ย ย ย try:
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย # Corrected lock check
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย is_locked = cmds.lockNode(shader, query=True)[0]
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย if not is_locked:
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย cmds.delete(shader)
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย print("Removed unused shader: {}".format(shader))
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย else:
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย print("Cannot delete locked shader: {}".format(shader))
ย ย ย ย ย ย ย ย ย ย ย ย except Exception as e:
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย print("Error removing shader '{}': {}".format(shader, str(e)))
ย ย ย ย elif remove_unused:
ย ย ย ย ย ย ย ย print("No unused shaders found.")

ย ย ย ย if optimize_network:
ย ย ย ย ย ย ย ย # Example optimization: Remove redundant connections
ย ย ย ย ย ย ย ย for shader in shaders_in_use:
ย ย ย ย ย ย ย ย ย ย ย ย try:
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย connections = cmds.listConnections(shader, plugs=True, connections=True) or []
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย if connections:
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย for i in range(0, len(connections), 2):
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย source = connections[i]
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย dest = connections[i + 1]
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย # Example: Remove duplicate connections
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย if cmds.connectionInfo(source, destinationFromSource=True) == cmds.connectionInfo(dest, destinationFromSource=True):
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย cmds.disconnectAttr(source, dest)
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย print("Disconnected redundant connection from '{}' to '{}'".format(source, dest))
ย ย ย ย ย ย ย ย ย ย ย ย except Exception as e:
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย print("Error optimizing shader network for '{}': {}".format(shader, str(e)))
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย 
# Usage example:
# Select objects and run:
shader_cleaner_pro(objects=['testSphere', 'testCube'], remove_unused=True, optimize_network=True)

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

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

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

  • Unused Shader Removal:ย Automatically detects and removes shaders that are not assigned to any objects, reducing scene complexity.

  • Shader Network Optimization:ย Optimizes shader connections for better performance and easier management.

  • Batch Shader Management:ย Clean and optimize multiple shaders simultaneously, saving valuable time on repetitive tasks.

  • User-Friendly Interface:ย Intuitive UI designed to simplify shader management, making it accessible for artists of all levels.

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

โ€ข ๐Ÿš€ Boost Productivity:ย Save time on managing shaders manually by automating the cleaning and optimization process.

โ€ข ๐Ÿ› ๏ธ Enhance Workflow:ย Ideal for complex scenes with numerous shaders, ensuring consistency and efficiency across your projects.

โ€ข ๐Ÿ“ˆ Improve Consistency:ย Ensures all selected objects have optimized and consistently applied shaders, enhancing rendering quality.

โ€ข ๐Ÿ’ก User-Friendly Interface:ย Intuitive UI suitable for artists of all levels, making shader management seamless and efficient.

โœจ Ready to Optimize Your Shader Workflow?

Try out ShaderCleanerProย 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! ๐Ÿ’ช๐ŸŽ‰


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


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

  • Shader Network Visualization:ย For more advanced functionality, consider adding visualization tools to display shader networks graphically before and after optimization.

  • Error Handling:ย The scripts include checks for object selection and handle cases with no shaders gracefully.

  • Customization:ย Extend the tool to include options like specifying different optimization levels, handling specific shader types, or integrating with other material management tools.

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

1 view0 comments

Comments


bottom of page