Stop Clicking: Automating Maya Scene Cleanup with maya.cmds vs. OpenMaya
Batch-renaming and re-exporting hundreds of Maya assets by hand is a day of clicking. Here's how to automate it with maya.cmds — and when the OpenMaya API is worth its steeper learning curve.
28 Jul 2026, 10:42 UTC

The job is boring and enormous: 300 rigged character assets came back from a vendor with names like final_CHAR_v2_FINAL.ma, transform nodes called pCube47, and every file needs a validated naming pass plus a fresh FBX export before it can enter the asset library. Done by hand, that's a full day of clicking per artist. Done with a script, it's a coffee break.
This is the practical case for learning Maya's Python layers — and for understanding the real engineering decision underneath: maya.cmds or the OpenMaya API. They're not interchangeable, and picking the wrong one for the job has consequences.
Two APIs, two philosophies
Maya exposes Python in two flavors. maya.cmds is a thin wrapper over MEL: everything is string-based, commands look like the UI operations they mirror (cmds.ls(), cmds.rename(), cmds.file()), and it's forgiving to write. OpenMaya — specifically Python API 2.0, maya.api.OpenMaya — is object-oriented: you work with MObject handles and function sets, and it's what Autodesk documents for new plug-in development.
The trade-off is real. cmds is fast to write but slow to run, because every call goes through string parsing and the command layer. OpenMaya operates directly on the dependency graph, so it scales to huge scenes — but it demands more boilerplate and more care. A rename loop over 300 nodes will run fine in either; a per-vertex operation over a 2-million-poly mesh will make the difference painfully obvious.
A worked example: validate, rename, export
Here's a self-contained cmds script — appropriate for this task, since node counts are modest and readability matters for pipeline maintenance. Run it in Maya's Script Editor (Python tab) for interactive use, or headlessly via mayapy for batch processing:
import maya.cmds as cmds
import re
import os
PATTERN = re.compile(r'^[A-Z][A-Za-z0-9]*_(geo|grp|jnt|ctrl)$')
def validate_and_fix():
transforms = cmds.ls(type='transform', long=True)
fixed = []
for node in transforms:
short = node.split('|')[-1]
if PATTERN.match(short):
continue
# Skip internal/default nodes
if cmds.objectType(node, isType='transform') and \
cmds.listRelatives(node, shapes=True):
new_name = 'Asset_%s_geo' % short
renamed = cmds.rename(node, new_name)
fixed.append((short, renamed))
return fixed
def export_fbx(output_dir):
if not os.path.isdir(output_dir):
os.makedirs(output_dir)
out = os.path.join(output_dir, 'export.fbx')
cmds.file(out, force=True, type='FBX export',
exportAll=True, options='v=0')
fixes = validate_and_fix()
print('Renamed %d nodes' % len(fixes))
export_fbx('/path/to/output') # replace with your export directoryA few things to note before running this anywhere near production. The FBX export type requires Maya's FBX plug-in to be loaded (cmds.loadPlugin('fbxmaya') if it isn't). The rename logic above is deliberately naive — it will mangle namespaces and collide on duplicate names, so treat it as a skeleton, not a finished validator. Test on a copy of a scene, never the original.
For headless runs, invoke it with mayapy your_script.py from a shell. Note that batch execution still consumes a Maya license in most configurations — that affects the cost math if you're planning CI-style automation on a render farm.
Where OpenMaya earns its complexity
Switch to OpenMaya when the operation is hot: iterating mesh components, evaluating rigs across many frames, or processing scenes with tens of thousands of nodes. Instead of strings, you hold MObject references that stay valid as you work, and you avoid the command layer entirely. The catch, beyond verbosity, is undo: cmds operations are undoable by default, while raw OpenMaya edits are not unless you route them through MDGModifier or an MPxCommand. Mixing the two carelessly — some edits via cmds, some via direct API calls — can leave the undo stack lying to you about scene state. In an interactive tool, that's a bug users will find in the first hour.
Version caveats and how to verify
Maya moved to Python 3 in recent releases; older pipeline snippets written for Python 2 will fail on import or on print statements. Check your installed version's documentation (Help menu) for the exact Python and API versions before porting legacy tools. To sanity-check everything above: open the Script Editor, run cmds.ls(type='transform'), and confirm you get a list of node names back. Then run the rename script on a throwaway scene with a few deliberately misnamed cubes — the printed rename count should match your violations, and the FBX should appear in your output directory.
The actionable takeaway: default to cmds for pipeline glue, reach for OpenMaya when profiling proves you need it, and never mix them inside one undoable operation. That one discipline will save you more debugging time than any other Maya scripting habit.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.