Scripting in Maya With Python and MEL: Script Editor, maya.cmds, Loops, Batch Tasks and Simple Tools

Autodesk MAYA 65 min min read Updated: Nov 17, 2026 Advanced
Scripting in Maya With Python and MEL: Script Editor, maya.cmds, Loops, Batch Tasks and Simple Tools
Advanced Topic 1 of 3

Why Script?

  • Rename hundreds of objects
  • Place many objects by a rule
  • Build tools for your team
  • Export files in batches

The Script Editor

  • Open it with the Script Editor button at the bottom right
  • Use the MEL tab or the Python tab
  • Turn on History > Echo All Commands to see the code for what you do in the UI
  • Select code and middle-mouse drag it onto a shelf to make a button

A Simple Python Script

python import maya.cmds as cmds # Make 5 cubes in a row for i in range(1, 6): cube = cmds.polyCube(w=20, h=20, d=20, name="Box_%02d" % i)[0] cmds.move(i * 30, 0, 0, cube)

It loops five times, creates a cube, names it and moves it along X. Run it by selecting the code and pressing Ctrl + Enter in the Script Editor.

Not run in Maya I could not run Maya here, so this script follows the documented maya.cmds pattern but was not run. Test it in a new scene.

MEL

MEL is Maya's older scripting language. It is still found in many studio tools and in the Script Editor history, so learn to read it. Python is usually the better choice for new code.

Batch Rename Logic

python ames = ["pCube1", "pCube2", "pSphere3", "pCylinder4"] renamed = [] for i, n in enumerate(names, 1): base = "".join(c for c in n if c.isalpha())[1:] # drop the leading p and numbers renamed.append("%s_%02d" % (base, i)) print(renamed)
Result

['Cube_01', 'Cube_02', 'Sphere_03', 'Cylinder_04']

The logic strips the prefix and numbers and adds a clean counter. In Maya you would loop over cmds.ls(selection=True) and call cmds.rename.

Save before running scripts A script can change many objects at once. Save your scene first and test on a copy.

Practice

  1. Turn on Echo All Commands and create a sphere
  2. Run the five-cube script
  3. Change it to ten spheres in a ring
  4. Write a loop that renames the selection

Conclusion

Scripts automate repeated jobs. Use Echo All Commands to learn the commands and start with small tests.

Quick Summary: Why script; Script Editor; Python; MEL; batch logic.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators