Merge pull request #575 from ynput/bugfix/maya-invalid-reference-check-in-maya2022

Maya: check for invalid reference compatible with Maya 2022
This commit is contained in:
Ondřej Samohel 2024-06-18 22:48:25 +02:00 committed by GitHub
commit 4c84c474db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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:
@ -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()