CG Wizards > Maya > Scripts > Maya: Delete Unknown Nodes And Plugins
Maya: Delete Unknown Nodes And Plugins
Description
Delete all unknown nodes and plugins in your scene.
How It Works
Delete Unknown Nodes and Plugins Script: Will remove all unknown nodes and plugins in your scene and notify you if there are any exceptions.
List Unknown Nodes and Plugins Script: Lists all unknown nodes and plugins in your scene and prints it out to the script editor.
Application: Maya
Application Compatibility: 2015 and up.
Script Type: Python
Always save and version up your file before running any script.
Scripts Walkthrough
Delete Unknown Nodes and Plugins Script
import maya.cmds as cmds
def delete_unknown_plugins_and_nodes():
unknown_nodes = cmds.ls(type=["unknown", "unknownDag", "unknownTransform"], long=True)
unknown_plugins = cmds.unknownPlugin(q=True, l=True)
if unknown_plugins:
for plugin in unknown_plugins:
cmds.unknownPlugin(plugin, r=True)
if cmds.ls(type="reference"):
cmds.confirmDialog(title="Delete Unknown Plugins", message="Deleted unknown plugins. However if the referenced files have unknown plugins you will need to remove them from each of the referenced files and then remove it from this file.", button=["Ok"])
flag_user = False
if unknown_nodes:
for each_node in unknown_nodes:
if cmds.objExists(each_node):
cmds.lockNode(each_node, l=False)
try:
cmds.delete(each_node)
except:
flag_user = True
if flag_user:
cmds.confirmDialog(title="Delete Unknown Nodes", message="Deleted unknown nodes. However some nodes were unable to be deleted due to them being referenced. Please delete the unknown nodes within the unknown ve them from each of the referenced files and then remove it from this file.", button=["Ok"])
cmds.confirmDialog(title="Delete Unknown Nodes and Plugins", message="Script Completed.", button=["Ok"])
delete_unknown_plugins_and_nodes()
List Unknown Nodes and Plugins Script
import maya.cmds as cmds
def list_unknown_plugins_and_nodes():
# get a list of all unknown nodes
unknown_nodes = cmds.ls(type=["unknown", "unknownDag", "unknownTransform"])
unknown_plugins = cmds.unknownPlugin(q=True, l=True)
print("\nUNKNOWN NODES")
print("-------------")
#loop through each unknown node and print its name
if unknown_nodes:
for each_node in unknown_nodes:
print(each_node)
number_of_nodes = len(unknown_nodes)
else:
number_of_nodes = 0
print("\nUNKNOWN PLUGINS")
print("-------------")
#loop through each unknown plugin and print its name
if unknown_plugins:
for each_plugin in unknown_plugins:
print(each_plugin)
number_of_plugins = len(unknown_plugins)
else:
number_of_plugins = 0
#print out total number of unknown nodes
print("\n-------------\n")
print("Total Unknown Nodes: %s" % number_of_nodes)
print("Total Unknown Plugins: %s" % number_of_plugins)
list_unknown_plugins_and_nodes()