Some basic concepts

 
 
 

The following section introduces some basic concepts that help you understand what’s going on when you use scripting in Maya.

The command architecture

Maya has a command-based architecture for handling all of its operations. The commands for all of Maya’s functionality are accessed through scripting language commands tied to the Maya user interface—menus, tools, dialog boxes; in fact, just about anything you interact with in Maya. As well, you can explicitly enter Maya commands in the scripting languages that Maya supports.

Every Maya command has multiple arguments that set the way in which the command executes. Arguments and their implicit or explicit values are required for a command to execute.

To set argument values, the scripting languages in Maya use flags. Flags tell the scripting language which argument of the Maya command is set with what value. The value that is assigned to the argument follows the flag.

Flags have short and long names in MEL and Python. Commands execute identically whether or not you use the short or long name of the flag. Long names are often descriptive and useful for new users; short names abbreviate flag names for power users.

Scripting languages in Maya

Maya supports two scripting languages:

Maya’s user interface is built using scripts that execute (call) Maya commands. As Python is a recent addition to Maya, the majority of the scripts accessed through the user interface are written in MEL.

For example, when you click the sphere icon on the Shelf or select an item from a menu, Maya calls MEL commands to create a sphere or execute the command associated with the menu item.

Entering commands in Maya

There are several ways to explicitly enter scripting commands in Maya.

You can also load external MEL and Python files and run them using the Script Editor. For more information, see Loading a script file.

What MEL looks like

Invoking commands in MEL has the basic structure of a command followed by a combination of flags and arguments. Flags are prefaced by the hyphen character in MEL.

All MEL commands are case-sensitive; SPHERE is not the same as sphere (and returns an error message).

If no flags are provided, the command executes with default arguments. The command fails if it requires arguments that it did not get.

Note

MEL also has an alternate syntax, which implements commands and flags in a method similar to the C programming language. For more information, see MEL for Programmers in the Maya User Guide.

Getting help on MEL

You can get help with MEL in three ways:

Basics of Python

Python and MEL are scripting languages with equal prominence and capabilities in Maya. Python can access all the Maya commands that MEL does.

Python accesses Maya commands through the Python module maya.cmds. Modules in Python are sets of commands that add functionality to Python, and must be imported before using any of the commands from a module.

Flags in Python are implemented through Python’s named arguments. You specify which argument to modify and use the assignment operator (=) to assign a new value to the argument.

In order to run this or any example command, you must have imported the Python module first. Enter import maya.cmds before starting to enter Python commands.

All Python commands are case-sensitive; maya.cmds.SPHERE is not the same as maya.cmds.sphere (and returns an error message).

Getting help on Python

You can get help with Python in several different ways: