Adverti horiz upsell
Conversational MEL Part 1
Conversational MEL Part 1
JamesPiechota, updated 2006-11-29 07:04:17 UTC 47,092 views  Rating:
(7 ratings)
Page 3 of 4

Mel Command Syntax

Now that you�ve mastered the art of the cut, paste, drag, drop, and click - it�s time to move on to something that is probably either more or less exciting than it sounds: MEL syntax. As we saw before only certain words are valid MEL commands, if you use an invalid MEL command Maya throws an error. Maya runs a tight ship and there are other rules you have to satisfy as well. The first is so simple it�s easy to forget:

Every line must end in a semi-colon �;�

This is not quite so important if you�re only executing a single MEL command, but imperative for anything more. This is so that Maya knows when one MEL command ends and another begins. Take a scan up through the History Pane and you should see that every non-comment line ends in a semi-colon. You may also notice that each command is on its own line - this, however is not required. Except for a few exceptions Maya treats spaces, carriage returns, and tabs the same (collectively called whitespace). The move commands from before could have been written like:

move -r 0 0 -1.941666; move -r 0 1.192061 0;

Or like

move -r 0 0 -1.941666      
; move
-r 0                      1.192061 0 ;

And they would have worked fine so long as semi-colons were used in the right places. The next rule concerns the structure of MEL commands. Your typical MEL command is composed of three main parts:

commandName   flagsAndArguments   target

 A flag is word or series of letters preceded by a dash. In the file command from earlier:

file -f -new;
both �-f� and �-new� are flags. A flag is a way to specify the details about how a command should function. Continuing the analogy to spoken commands, instead of just telling your dog to �Sit� you could say �Sit here�. Since the �file� command can perform dozens of operations (save, open, import, etc...), the �-new� flag here indicates that the command is not saving or opening a file but rather creating a new scene.

All flags have two forms, a short form and a long form. In the move command above:

move -r 0 0 -1.941666;

 �-r� is the short form of the �-relative� flag which indicates that the command target should be moved relative to its current position. In contrast the �-a� or �-absolute� flag indicates that the command target should be moved to the provided location regardless of where it is now.

move -r 0 0 -1.941666;


move -relative 0 0 -1.941666;

are exactly the same commands and will have exactly the same effect. Coupled with flags are arguments. Some flags like �-new� on the �file� command don�t need arguments as there�s really only one way to create a new scene.

If you take a look at the �polySphere� command, however:

polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -tx 2 -ch 1;

you�ll see that every flag used is followed by one or more numbers. These numbers are flag arguments and they provide even more detail about how the command should function. To really geek up the spoken command examples from before: when you tell your dog to �Sit here� or �Sit over there� you�re really telling him to �Sit in a location that is here� or �Sit in a location that is over there� (good luck getting him to obey if you do, though).

In this case �Sit� is the command �in a location that is� is acting like a command flag and �here� is the argument to that flag. If there were a �sit� MEL command it might look like:

sit -location �here�;

In the �polySphere� command above, the �-sx� and �-sy� flags indicate the number of subdivisions in the x and y directions (their long forms are �-subdivisionsX� and �-subdivisionsY�). In this case each of the flags is passed the argument 20 indicating it will create a sphere that has 20 subdivisions in the x direction and 20 subdivisions in the y direction. A given command can take any number of flags and arguments, although, each command has a well defined list of acceptable flags. It�s also important to mention that all of the elements of the command must be separated by whitespace:


This is so that Maya can distinguish between the different parts of the command - if it were instead written like:

move -r 00-1.941666;


move-r 00-1.941666;


move -r0 0 -1.94 1666;

Maya might think the command had only one argument (first example), that the command name was actually �move-r� not �move� (second example), or that the flag �-r0� had three arguments 0, -1.94, 1666 (third example).

To recap:
  • The command name indicates the sort of action you will perform.
  • Flags specify ways in which that action will be customized.
  • Flag arguments provide additional details about how the flag will customize the action.
  • Whitespace is used to separate each element of a command.
  • Semicolons are used to separate commands.

And that leaves us with the command target. The command target can serve a number of purposes. For simple commands it might act just like a flag argument: it provides additional details about what the command will do. For those commands that modify objects or UI elements (like �move� and �scale�) - the command target indicates which object or UI element will be modified.

At the risk of beating a dead horse, we can expand our canine example to include a feline. If you had two pets but only really wanted your dog to sit you might say �Sit Bowser� to make it clear that Fluffy can go on doing as she pleases. Likewise if you want to move your sphere around the scene you would issue a command like:

move -r 0 10 0 pSphere1;

Indicating that pSphere1 should be moved up 10 units.

Huh? What�s that you say? The move command from the first example doesn�t have a target? Yep, that�s right:

move -r 0 0 -1.941666 ;

Many of the commands that require targets have backup plans to handle situations when one isn�t provided. The �move� command, for example, will try to act on whatever object is selected if no command target is provided. There�s loads more syntax to cover, and like a gazillion MEL commands to explore - but that�ll have to wait for later cause now it�s time to leave our spheres behind and make a (slightly more) useful example!