Skip to content

validate_node_ids_deformed_shapes

ValidateNodeIdsDeformedShape

Bases: MayaInstancePlugin

Validate if deformed shapes have related IDs to the original shapes.

When a deformer is applied in the scene on a referenced mesh that already had deformers then Maya will create a new shape node for the mesh that does not have the original id. This validator checks whether the ids are valid on all the shape nodes in the instance.

Source code in client/ayon_maya/plugins/publish/validate_node_ids_deformed_shapes.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class ValidateNodeIdsDeformedShape(plugin.MayaInstancePlugin):
    """Validate if deformed shapes have related IDs to the original shapes.

    When a deformer is applied in the scene on a referenced mesh that already
    had deformers then Maya will create a new shape node for the mesh that
    does not have the original id. This validator checks whether the ids are
    valid on all the shape nodes in the instance.

    """

    order = ValidateContentsOrder
    families = ['look']
    label = 'Deformed shape ids'
    actions = [
        ayon_maya.api.action.SelectInvalidAction,
        RepairAction
    ]

    @classmethod
    def apply_settings(cls, project_settings):
        # Disable plug-in if cbId workflow is disabled
        if not project_settings["maya"].get("use_cbid_workflow", True):
            cls.enabled = False
            return

    def process(self, instance):
        """Process all the nodes in the instance"""

        # Ensure all nodes have a cbId and a related ID to the original shapes
        # if a deformer has been created on the shape
        invalid = self.get_invalid(instance)
        if invalid:
            raise PublishValidationError(
                ("Shapes found that are considered 'Deformed'"
                 "without object ids: {0}").format(invalid))

    @classmethod
    def get_invalid(cls, instance):
        """Get all nodes which do not match the criteria"""

        shapes = cmds.ls(instance[:],
                         dag=True,
                         leaf=True,
                         shapes=True,
                         long=True,
                         noIntermediate=True)

        invalid = []
        for shape in shapes:
            history_id = lib.get_id_from_sibling(shape)
            if history_id:
                current_id = lib.get_id(shape)
                if current_id != history_id:
                    invalid.append(shape)

        return invalid

    @classmethod
    def repair(cls, instance):

        for node in cls.get_invalid(instance):
            # Get the original id from history
            history_id = lib.get_id_from_sibling(node)
            if not history_id:
                cls.log.error("Could not find ID in history for '%s'", node)
                continue

            lib.set_id(node, history_id, overwrite=True)

get_invalid(instance) classmethod

Get all nodes which do not match the criteria

Source code in client/ayon_maya/plugins/publish/validate_node_ids_deformed_shapes.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
@classmethod
def get_invalid(cls, instance):
    """Get all nodes which do not match the criteria"""

    shapes = cmds.ls(instance[:],
                     dag=True,
                     leaf=True,
                     shapes=True,
                     long=True,
                     noIntermediate=True)

    invalid = []
    for shape in shapes:
        history_id = lib.get_id_from_sibling(shape)
        if history_id:
            current_id = lib.get_id(shape)
            if current_id != history_id:
                invalid.append(shape)

    return invalid

process(instance)

Process all the nodes in the instance

Source code in client/ayon_maya/plugins/publish/validate_node_ids_deformed_shapes.py
37
38
39
40
41
42
43
44
45
46
def process(self, instance):
    """Process all the nodes in the instance"""

    # Ensure all nodes have a cbId and a related ID to the original shapes
    # if a deformer has been created on the shape
    invalid = self.get_invalid(instance)
    if invalid:
        raise PublishValidationError(
            ("Shapes found that are considered 'Deformed'"
             "without object ids: {0}").format(invalid))