Skip to content

validate_node_ids_unique

ValidateNodeIdsUnique

Bases: MayaInstancePlugin

Validate the nodes in the instance have a unique Colorbleed Id

Here we ensure that what has been added to the instance is unique

Source code in client/ayon_maya/plugins/publish/validate_node_ids_unique.py
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 ValidateNodeIdsUnique(plugin.MayaInstancePlugin):
    """Validate the nodes in the instance have a unique Colorbleed Id

    Here we ensure that what has been added to the instance is unique
    """

    order = ValidatePipelineOrder
    label = 'Non Duplicate Instance Members (ID)'
    families = ["model",
                "look",
                "rig",
                "yetiRig"]

    actions = [ayon_maya.api.action.SelectInvalidAction,
               ayon_maya.api.action.GenerateUUIDsOnInvalidAction]

    @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 meshes"""

        # Ensure all nodes have a cbId
        invalid = self.get_invalid(instance)
        if invalid:
            label = "Nodes found with non-unique folder ids"
            raise PublishValidationError(
                message="{}, see log".format(label),
                title="Non-unique folder ids on nodes",
                description="{}\n- {}".format(label,
                                              "\n- ".join(sorted(invalid)))
            )

    @classmethod
    def get_invalid(cls, instance):
        """Return the member nodes that are invalid"""

        # Check only non intermediate shapes
        # todo: must the instance itself ensure to have no intermediates?
        # todo: how come there are intermediates?
        instance_members = cmds.ls(instance, noIntermediate=True, long=True)

        # Collect each id with their members
        ids = defaultdict(list)
        for member in instance_members:
            object_id = lib.get_id(member)
            if not object_id:
                continue
            ids[object_id].append(member)

        # Take only the ids with more than one member
        invalid = list()
        for members in ids.values():
            if len(members) > 1:
                members_text = "\n".join(
                    "- {}".format(member) for member in sorted(members)
                )
                cls.log.error(
                    "ID found on multiple nodes:\n{}".format(members_text)
                )
                invalid.extend(members)

        return invalid

get_invalid(instance) classmethod

Return the member nodes that are invalid

Source code in client/ayon_maya/plugins/publish/validate_node_ids_unique.py
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
@classmethod
def get_invalid(cls, instance):
    """Return the member nodes that are invalid"""

    # Check only non intermediate shapes
    # todo: must the instance itself ensure to have no intermediates?
    # todo: how come there are intermediates?
    instance_members = cmds.ls(instance, noIntermediate=True, long=True)

    # Collect each id with their members
    ids = defaultdict(list)
    for member in instance_members:
        object_id = lib.get_id(member)
        if not object_id:
            continue
        ids[object_id].append(member)

    # Take only the ids with more than one member
    invalid = list()
    for members in ids.values():
        if len(members) > 1:
            members_text = "\n".join(
                "- {}".format(member) for member in sorted(members)
            )
            cls.log.error(
                "ID found on multiple nodes:\n{}".format(members_text)
            )
            invalid.extend(members)

    return invalid

process(instance)

Process all meshes

Source code in client/ayon_maya/plugins/publish/validate_node_ids_unique.py
36
37
38
39
40
41
42
43
44
45
46
47
48
def process(self, instance):
    """Process all meshes"""

    # Ensure all nodes have a cbId
    invalid = self.get_invalid(instance)
    if invalid:
        label = "Nodes found with non-unique folder ids"
        raise PublishValidationError(
            message="{}, see log".format(label),
            title="Non-unique folder ids on nodes",
            description="{}\n- {}".format(label,
                                          "\n- ".join(sorted(invalid)))
        )