Beginning MEL scripting: exploring commands

Exploring commands

There are three types of commands in Maya: runtime commands, MEL procedures, and Maya MEL commands.

A runtime command is a command that comprises other commands or scripts, for example, Maya commands and MEL procedures. It is like a one-line wrapper that lets you execute long scripts (or set of scripts) on the MEL command line with a short label. Many (but not all) menu items and icons that are executable use a runtime command to launch.

To explore more, click at the bottom right corner of Maya to open the Script Editor, and select History > Echo All Commands. When this option is enabled, all commands that are executed appear in the top pane of the Script Editor.

  1. Select a menu, for example, create and select a polygon and select Edit Mesh > Add Divisions. Many commands appear in the top pane of the Script Editor. Scroll through this history, and you will see these lines printed (towards the top):

    SubdividePolygon;
    performPolySubdivide "" 0;
    polySubdivideFacet -dv 1 -m 0 -ch 1 pSphere1;
  2. Type in the bottom pane:

    whatIs SubdividePolygon;

    Select this text and click Ctrl+Enter to execute it.

    The Script Editor prints this in the top pane:

    // Result: Run Time Command // 

    The whatIs command allows you to query the type of your string (in this case, SubdividePolygon).

    You have now confirmed that SubdividePolygon is a runtime command.

  3. Now type in the bottom pane:

    whatIs performPolySubdivide;

    The result is as follows:

    // Result: Mel procedure found in: C:/Program Files/Autodesk/Maya201x/scripts/others/performPolySubdivide.mel // 

    When the runtime command is called, this MEL procedure is executed.

    Furthermore, you can go into your Maya installation directory, open the specified .mel file in a text editor, and explore what this MEL procedure does.

    Browsing through the script reveals that this is the command that is executed:

    polySubdivideFacet

    Recall that this command was also listed in the Script Editor history.

    polySubdivideFacet -dv 1 -m 0 -ch 1 pSphere1;

    Refer to the Technical Documentation, MEL Commands section. polySubdivideFacet is a listed MEL command, and its command documentation also provides the description for the flags listed above: for example, -dv 1 to set the number of divisions, and -ch 1 to enable construction history.

  4. Note: When writing your own script, if you want your script to extend beyond the behavior of the menu item, you must use MEL procedures or the MEL commands (instead of runtime commands).

    To learn more, see defaultRunTimeCommands.mel in the scripts\startup folder of the Maya installation directory.

    All runtime commands are listed in this file, along with the menu item and MEL procedure/Maya MEL command that is associated with each runtime command.

Related topics