Pymel scene cleanup tricks

For what it’s worth. This isn’t only pymel related, but more relates to the Maya cleanUpScene mel command and how to run it from code.

Consider the below as Pseudocode - didn’t run it. :slight_smile:

You can also run it from Python without Pymel or with just mel:

MAYA PYTHON: cleanUpScene

from maya import cmds
from maya import mel
import os

# Set the maya option vars, e.g. displayLayerOption
cmds.optionVar(intValue=("displayerLayerOption", 1))

# Disable the "Verifying Action" pop-up prompt
os.environ["MAYA_TESTING_CLEANUP"] = "1"

# Run clean up scene mel command
mel.eval("performCleanUpScene()")

# Remove the override from the environment variables
del os.environ["MAYA_TESTING_CLEANUP"]

MAYA MEL: cleanUpScene

optionVar -intValue "displayerLayerOption" 1;
putenv "MAYA_TESTING_CLEANUP" "1";
performCleanUpScene();
3 Likes

After some checking, cleanUpScene(1) seems to be safer as it will ensure all used optionVars exist before running performCleanUpScene() internally anyway.

1 Like

This has been very useful, thanks everyone.