Bases: MayaInstancePlugin
Validate nodes in look have no reference edits to cbId.
Note
This only validates the cbId edits on the referenced nodes that are used in the look. For example, a transform can have its cbId changed without being invalidated when it is not used in the look's assignment.
Source code in client/ayon_maya/plugins/publish/validate_look_id_reference_edits.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 | class ValidateLookIdReferenceEdits(plugin.MayaInstancePlugin):
"""Validate nodes in look have no reference edits to cbId.
Note:
This only validates the cbId edits on the referenced nodes that are
used in the look. For example, a transform can have its cbId changed
without being invalidated when it is not used in the look's assignment.
"""
order = ValidateContentsOrder
families = ['look']
label = 'Look Id Reference Edits'
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):
invalid = self.get_invalid(instance)
if invalid:
raise PublishValidationError("Invalid nodes %s" % (invalid,))
@staticmethod
def get_invalid(instance):
# Collect all referenced members
references = defaultdict(set)
relationships = instance.data["lookData"]["relationships"]
for relationship in relationships.values():
for member in relationship['members']:
node = member["name"]
if cmds.referenceQuery(node, isNodeReferenced=True):
ref = cmds.referenceQuery(node, referenceNode=True)
references[ref].add(node)
# Validate whether any has changes to 'cbId' attribute
invalid = list()
for ref, nodes in references.items():
edits = cmds.referenceQuery(editAttrs=True,
editNodes=True,
showDagPath=True,
showNamespace=True,
onReferenceNode=ref)
for edit in edits:
# Ensure it is an attribute ending with .cbId
# thus also ignore just node edits (like parenting)
if not edit.endswith(".cbId"):
continue
# Ensure the attribute is 'cbId' (and not a nested attribute)
node, attr = edit.split(".", 1)
if attr != "cbId":
continue
if node in nodes:
invalid.append(node)
return invalid
@classmethod
def repair(cls, instance):
invalid = cls.get_invalid(instance)
# Group invalid nodes by reference node
references = defaultdict(set)
for node in invalid:
ref = cmds.referenceQuery(node, referenceNode=True)
references[ref].add(node)
# Remove the reference edits on the nodes per reference node
for ref, nodes in references.items():
for node in nodes:
# Somehow this only works if you run the removal
# per edit command.
for command in ["addAttr",
"connectAttr",
"deleteAttr",
"disconnectAttr",
"setAttr"]:
cmds.referenceEdit("{}.cbId".format(node),
removeEdits=True,
successfulEdits=True,
failedEdits=True,
editCommand=command,
onReferenceNode=ref)
|