Skip to content

validate_unique_names

ValidateUniqueNames

Bases: MayaInstancePlugin, OptionalPyblishPluginMixin

transform names should be unique

ie: using cmds.ls(someNodeName) should always return shortname

Source code in client/ayon_maya/plugins/publish/validate_unique_names.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
class ValidateUniqueNames(plugin.MayaInstancePlugin,
                          OptionalPyblishPluginMixin):
    """transform names should be unique

    ie: using cmds.ls(someNodeName) should always return shortname

    """

    order = ValidateContentsOrder
    families = ["model"]
    label = "Unique transform name"
    actions = [ayon_maya.api.action.SelectInvalidAction]
    optional = True

    @staticmethod
    def get_invalid(instance):
        """Returns the invalid transforms in the instance.

        Returns:
            list: Non-unique name transforms.

        """
        # Check whether Maya's 'short name' includes a longer path than just
        # the node name to check whether it's unique in the full scene.
        non_unique_transforms_in_instance = [
            tr for tr in cmds.ls(instance, type="transform")
            if '|' in tr
        ]

        # Only invalidate if the clash is within the current instance
        count = Counter()
        for transform in non_unique_transforms_in_instance:
            short_name = transform.rsplit("|", 1)[-1]
            count[short_name] += 1

        invalid = []
        for transform in non_unique_transforms_in_instance:
            short_name = transform.rsplit("|", 1)[-1]
            if count[short_name] >= 2:
                invalid.append(transform)

        return invalid

    def process(self, instance):
        """Process all the nodes in the instance "objectSet"""
        if not self.is_active(instance.data):
            return
        invalid = self.get_invalid(instance)
        if invalid:
            raise PublishValidationError(
                "Nodes found with non-unique names:\n{0}".format(invalid))

get_invalid(instance) staticmethod

Returns the invalid transforms in the instance.

Returns:

Name Type Description
list

Non-unique name transforms.

Source code in client/ayon_maya/plugins/publish/validate_unique_names.py
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
@staticmethod
def get_invalid(instance):
    """Returns the invalid transforms in the instance.

    Returns:
        list: Non-unique name transforms.

    """
    # Check whether Maya's 'short name' includes a longer path than just
    # the node name to check whether it's unique in the full scene.
    non_unique_transforms_in_instance = [
        tr for tr in cmds.ls(instance, type="transform")
        if '|' in tr
    ]

    # Only invalidate if the clash is within the current instance
    count = Counter()
    for transform in non_unique_transforms_in_instance:
        short_name = transform.rsplit("|", 1)[-1]
        count[short_name] += 1

    invalid = []
    for transform in non_unique_transforms_in_instance:
        short_name = transform.rsplit("|", 1)[-1]
        if count[short_name] >= 2:
            invalid.append(transform)

    return invalid

process(instance)

Process all the nodes in the instance "objectSet

Source code in client/ayon_maya/plugins/publish/validate_unique_names.py
56
57
58
59
60
61
62
63
def process(self, instance):
    """Process all the nodes in the instance "objectSet"""
    if not self.is_active(instance.data):
        return
    invalid = self.get_invalid(instance)
    if invalid:
        raise PublishValidationError(
            "Nodes found with non-unique names:\n{0}".format(invalid))