Skip to content

validate_no_null_transforms

ValidateNoNullTransforms

Bases: MayaInstancePlugin, OptionalPyblishPluginMixin

Ensure no null transforms are in the scene.

Warning

Transforms with only intermediate shapes are also considered null transforms. These transform nodes could potentially be used in your construction history, so take care when automatically fixing this or when deleting the empty transforms manually.

Source code in client/ayon_maya/plugins/publish/validate_no_null_transforms.py
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
80
81
82
83
84
85
86
87
88
89
90
class ValidateNoNullTransforms(plugin.MayaInstancePlugin,
                               OptionalPyblishPluginMixin):
    """Ensure no null transforms are in the scene.

    Warning:
        Transforms with only intermediate shapes are also considered null
        transforms. These transform nodes could potentially be used in your
        construction history, so take care when automatically fixing this or
        when deleting the empty transforms manually.

    """

    order = ValidateContentsOrder
    families = ['model']
    label = 'No Empty/Null Transforms'
    actions = [RepairAction,
               ayon_maya.api.action.SelectInvalidAction]
    optional = False

    @staticmethod
    def get_invalid(instance):
        """Return invalid transforms in instance"""

        transforms = cmds.ls(instance, type='transform', long=True)

        invalid = []
        for transform in transforms:
            if not has_shape_children(transform):
                invalid.append(transform)

        return invalid

    def process(self, instance):
        """Process all the transform nodes in the instance """
        if not self.is_active(instance.data):
            return
        invalid = self.get_invalid(instance)
        if invalid:
            raise PublishValidationError(
                "Empty transforms found without shapes:\n\n{0}".format(
                    _as_report_list(sorted(invalid))
                ),
                title="Empty transforms"
            )

    @classmethod
    def repair(cls, instance):
        """Delete all null transforms.

        Note: If the node is used elsewhere (eg. connection to attributes or
        in history) deletion might mess up things.

        """
        invalid = cls.get_invalid(instance)
        if invalid:
            cmds.delete(invalid)

get_invalid(instance) staticmethod

Return invalid transforms in instance

Source code in client/ayon_maya/plugins/publish/validate_no_null_transforms.py
54
55
56
57
58
59
60
61
62
63
64
65
@staticmethod
def get_invalid(instance):
    """Return invalid transforms in instance"""

    transforms = cmds.ls(instance, type='transform', long=True)

    invalid = []
    for transform in transforms:
        if not has_shape_children(transform):
            invalid.append(transform)

    return invalid

process(instance)

Process all the transform nodes in the instance

Source code in client/ayon_maya/plugins/publish/validate_no_null_transforms.py
67
68
69
70
71
72
73
74
75
76
77
78
def process(self, instance):
    """Process all the transform nodes in the instance """
    if not self.is_active(instance.data):
        return
    invalid = self.get_invalid(instance)
    if invalid:
        raise PublishValidationError(
            "Empty transforms found without shapes:\n\n{0}".format(
                _as_report_list(sorted(invalid))
            ),
            title="Empty transforms"
        )

repair(instance) classmethod

Delete all null transforms.

Note: If the node is used elsewhere (eg. connection to attributes or in history) deletion might mess up things.

Source code in client/ayon_maya/plugins/publish/validate_no_null_transforms.py
80
81
82
83
84
85
86
87
88
89
90
@classmethod
def repair(cls, instance):
    """Delete all null transforms.

    Note: If the node is used elsewhere (eg. connection to attributes or
    in history) deletion might mess up things.

    """
    invalid = cls.get_invalid(instance)
    if invalid:
        cmds.delete(invalid)