Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maya: check for invalid reference compatible with Maya 2022 #575

Merged
merged 7 commits into from
Jun 18, 2024
11 changes: 10 additions & 1 deletion server_addon/maya/client/ayon_maya/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ def is_valid_reference_node(reference_node):
Reference node 'reference_node' is not associated with a reference file.

Note that this does *not* check whether the reference node points to an
existing file. Instead it only returns whether maya considers it valid
existing file. Instead, it only returns whether maya considers it valid
and thus is not an unassociated reference node

Arguments:
Expand All @@ -1731,9 +1731,18 @@ def is_valid_reference_node(reference_node):
bool: Whether reference node is a valid reference

"""
# maya 2022 is missing `isValidReference` so the check needs to be
# done in different way.
if cmds.about(version=True) < 2023:
try:
cmds.referenceQuery(reference_node, filename=True)
return True
except RuntimeError:
return False
sel = OpenMaya.MSelectionList()
sel.add(reference_node)
depend_node = sel.getDependNode(0)

return OpenMaya.MFnReference(depend_node).isValidReference()


Expand Down