Maya – Remove unknown nodes/plugins
Maya files from old scenes or different workstations with different plugins can clutter up the Maya scene with “requirements” that no longer exist or are not even supported anymore. Maya will check for these nodes and plugins when loading a file. Cleaning them up makes everything run a lot smoother.
import logging
from maya import cmds
# Find and remove unknown nodes
unknown_nodes = cmds.ls(type="unknown")
if unknown_nodes:
cmds.delete(unknown_nodes)
# Find and remove unknown plugins
unknown_plugins = cmds.unknownPlugin(query=True, list=True)
if unknown_plugins:
for plugin in unknown_plugins:
try:
cmds.unknownPlugin(plugin, remove=True)
except Exception as error:
# Oddly enough, even if a plugin is unknown, it can still have a dependency in the scene.
# So in this case, we log the error to look at after.
logging.warning("Unknown plugin cannot be removed due to ERROR: {}".format(error))