Skip to content

Instantly share code, notes, and snippets.

@JanPhKoch
Last active March 21, 2024 04:14
Show Gist options
  • Save JanPhKoch/182de7177ebc50cd2c0eff8454e9a0f4 to your computer and use it in GitHub Desktop.
Save JanPhKoch/182de7177ebc50cd2c0eff8454e9a0f4 to your computer and use it in GitHub Desktop.
Finds and deletes all unknown references within the maya scene.
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