Skip to content

validate_vray_referenced_aovs

Validate if there are AOVs pulled from references.

ValidateVrayReferencedAOVs

Bases: MayaInstancePlugin, OptionalPyblishPluginMixin

Validate whether the V-Ray Render Elements (AOVs) include references.

This will check if there are AOVs pulled from references. If Vray Use Referenced Aovs is checked on render instance, u must add those manually to Render Elements as Pype will expect them to be rendered.

Source code in client/ayon_maya/plugins/publish/validate_vray_referenced_aovs.py
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
class ValidateVrayReferencedAOVs(plugin.MayaInstancePlugin,
                                 OptionalPyblishPluginMixin):
    """Validate whether the V-Ray Render Elements (AOVs) include references.

    This will check if there are AOVs pulled from references. If
    `Vray Use Referenced Aovs` is checked on render instance, u must add those
    manually to Render Elements as Pype will expect them to be rendered.

    """

    order = pyblish.api.ValidatorOrder
    label = 'VRay Referenced AOVs'
    families = ['renderlayer']
    actions = [RepairContextAction]
    optional = False

    def process(self, instance):
        """Plugin main entry point."""
        if not self.is_active(instance.data):
            return
        if instance.data.get("renderer") != "vray":
            # If not V-Ray ignore..
            return

        ref_aovs = cmds.ls(
            type=["VRayRenderElement", "VRayRenderElementSet"],
            referencedNodes=True)
        ref_aovs_enabled = ValidateVrayReferencedAOVs.maya_is_true(
            cmds.getAttr("vraySettings.relements_usereferenced"))

        if not instance.data.get("vrayUseReferencedAovs"):
            if ref_aovs_enabled and ref_aovs:
                self.log.warning((
                    "Referenced AOVs are enabled in Vray "
                    "Render Settings and are detected in scene, but "
                    "AYON render instance option for referenced AOVs is "
                    "disabled. Those AOVs will be rendered but not published "
                    "by Pype."
                ))
                self.log.warning(", ".join(ref_aovs))
        else:
            if not ref_aovs:
                self.log.warning((
                    "Use of referenced AOVs enabled but there are none "
                    "in the scene."
                ))
            if not ref_aovs_enabled:
                self.log.error((
                    "'Use referenced' not enabled in Vray Render Settings."
                ))
                raise PublishValidationError("Invalid render settings")

    @classmethod
    def repair(cls, context):
        """Repair action."""
        vray_settings = cmds.ls(type="VRaySettingsNode")
        if not vray_settings:
            node = cmds.createNode("VRaySettingsNode")
        else:
            node = vray_settings[0]

        cmds.setAttr("{}.relements_usereferenced".format(node), True)

    @staticmethod
    def maya_is_true(attr_val):
        """Whether a Maya attr evaluates to True.

        When querying an attribute value from an ambiguous object the
        Maya API will return a list of values, which need to be properly
        handled to evaluate properly.

        Args:
            attr_val (mixed): Maya attribute to be evaluated as bool.

        Returns:
            bool: cast Maya attribute to Pythons boolean value.

        """
        if isinstance(attr_val, bool):
            return attr_val
        elif isinstance(attr_val, (list, types.GeneratorType)):
            return any(attr_val)
        else:
            return bool(attr_val)

maya_is_true(attr_val) staticmethod

Whether a Maya attr evaluates to True.

When querying an attribute value from an ambiguous object the Maya API will return a list of values, which need to be properly handled to evaluate properly.

Parameters:

Name Type Description Default
attr_val mixed

Maya attribute to be evaluated as bool.

required

Returns:

Name Type Description
bool

cast Maya attribute to Pythons boolean value.

Source code in client/ayon_maya/plugins/publish/validate_vray_referenced_aovs.py
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
@staticmethod
def maya_is_true(attr_val):
    """Whether a Maya attr evaluates to True.

    When querying an attribute value from an ambiguous object the
    Maya API will return a list of values, which need to be properly
    handled to evaluate properly.

    Args:
        attr_val (mixed): Maya attribute to be evaluated as bool.

    Returns:
        bool: cast Maya attribute to Pythons boolean value.

    """
    if isinstance(attr_val, bool):
        return attr_val
    elif isinstance(attr_val, (list, types.GeneratorType)):
        return any(attr_val)
    else:
        return bool(attr_val)

process(instance)

Plugin main entry point.

Source code in client/ayon_maya/plugins/publish/validate_vray_referenced_aovs.py
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
def process(self, instance):
    """Plugin main entry point."""
    if not self.is_active(instance.data):
        return
    if instance.data.get("renderer") != "vray":
        # If not V-Ray ignore..
        return

    ref_aovs = cmds.ls(
        type=["VRayRenderElement", "VRayRenderElementSet"],
        referencedNodes=True)
    ref_aovs_enabled = ValidateVrayReferencedAOVs.maya_is_true(
        cmds.getAttr("vraySettings.relements_usereferenced"))

    if not instance.data.get("vrayUseReferencedAovs"):
        if ref_aovs_enabled and ref_aovs:
            self.log.warning((
                "Referenced AOVs are enabled in Vray "
                "Render Settings and are detected in scene, but "
                "AYON render instance option for referenced AOVs is "
                "disabled. Those AOVs will be rendered but not published "
                "by Pype."
            ))
            self.log.warning(", ".join(ref_aovs))
    else:
        if not ref_aovs:
            self.log.warning((
                "Use of referenced AOVs enabled but there are none "
                "in the scene."
            ))
        if not ref_aovs_enabled:
            self.log.error((
                "'Use referenced' not enabled in Vray Render Settings."
            ))
            raise PublishValidationError("Invalid render settings")

repair(context) classmethod

Repair action.

Source code in client/ayon_maya/plugins/publish/validate_vray_referenced_aovs.py
67
68
69
70
71
72
73
74
75
76
@classmethod
def repair(cls, context):
    """Repair action."""
    vray_settings = cmds.ls(type="VRaySettingsNode")
    if not vray_settings:
        node = cmds.createNode("VRaySettingsNode")
    else:
        node = vray_settings[0]

    cmds.setAttr("{}.relements_usereferenced".format(node), True)