Last active
March 21, 2024 04:14
-
-
Save JanPhKoch/182de7177ebc50cd2c0eff8454e9a0f4 to your computer and use it in GitHub Desktop.
Finds and deletes all unknown references within the maya scene.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.cmds as cmds | |
def check_unknown_refs(): | |
""" | |
Checks unknown references. | |
:return: unknown_references: list of all unknown references within the scene. | |
""" | |
all_references = cmds.ls(type='reference') | |
unknown_references = [] | |
for ref in all_references: | |
try: | |
ref_path = cmds.referenceQuery(ref, filename=True) | |
except RuntimeError: | |
unknown_references.append(ref) | |
return unknown_references | |
def delete_unknown_refs(unknown_references): | |
""" | |
Unlocks and deletes all unknown reference nodes. | |
:return: | |
""" | |
for ref in unknown_references: | |
cmds.lockNode(ref, lock=False) | |
cmds.delete(ref) | |
if __name__ == '__main__': | |
delete_unknown_refs(check_unknown_refs()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment