From b70462b555eab9b605318cf937eacbbea2e50910 Mon Sep 17 00:00:00 2001 From: Toke Jepsen Date: Tue, 11 Jun 2019 07:05:07 +0100 Subject: [PATCH] Validate shading engine naming. Shading engines should be named after their surface shader to bring clarity to the look manager. --- pype/plugins/maya/publish/collect_look.py | 4 +- .../publish/validate_look_shading_group.py | 58 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 pype/plugins/maya/publish/validate_look_shading_group.py diff --git a/pype/plugins/maya/publish/collect_look.py b/pype/plugins/maya/publish/collect_look.py index d4302414c1..614e5b44a4 100644 --- a/pype/plugins/maya/publish/collect_look.py +++ b/pype/plugins/maya/publish/collect_look.py @@ -389,7 +389,9 @@ class CollectLook(pyblish.api.InstancePlugin): # Collect changes to "custom" attributes node_attrs = get_look_attrs(node) - self.log.info(node_attrs) + self.log.info( + "Node \"{0}\" attributes: {1}".format(node, node_attrs) + ) # Only include if there are any properties we care about if not node_attrs: diff --git a/pype/plugins/maya/publish/validate_look_shading_group.py b/pype/plugins/maya/publish/validate_look_shading_group.py new file mode 100644 index 0000000000..91558390bc --- /dev/null +++ b/pype/plugins/maya/publish/validate_look_shading_group.py @@ -0,0 +1,58 @@ +from maya import cmds + +import pyblish.api +import pype.api +import pype.maya.action + + +class ValidateShadingEngine(pyblish.api.InstancePlugin): + """Validate all shading engines are named after the surface material. + + Shading engines should be named "{surface_shader}SG" + """ + + order = pype.api.ValidateContentsOrder + families = ["look"] + hosts = ["maya"] + label = "Look Shading Engine Naming" + actions = [ + pype.maya.action.SelectInvalidAction, pype.api.RepairAction + ] + + # The default connections to check + def process(self, instance): + + invalid = self.get_invalid(instance) + if invalid: + raise RuntimeError( + "Found shading engines with incorrect naming:" + "\n{}".format(invalid) + ) + + @classmethod + def get_invalid(cls, instance): + shapes = cmds.ls(instance, type=["nurbsSurface", "mesh"], long=True) + invalid = [] + for shape in shapes: + shading_engines = cmds.listConnections( + shape, destination=True, type="shadingEngine" + ) or [] + for shading_engine in shading_engines: + name = ( + cmds.listConnections(shading_engine + ".surfaceShader")[0] + + "SG" + ) + if shading_engine != name: + invalid.append(shading_engine) + + return list(set(invalid)) + + @classmethod + def repair(cls, instance): + shading_engines = cls.get_invalid(instance) + for shading_engine in shading_engines: + name = ( + cmds.listConnections(shading_engine + ".surfaceShader")[0] + + "SG" + ) + cmds.rename(shading_engine, name)