The final concept vital to a basic understanding of MEL is that of command grouping . The most basic use of command grouping is to have MEL execute a number of statements and commands where normally MEL would only allow one statement. To group commands together, use curly braces ({}). In Example 4.40, we want to execute multiple commands during the execution of a for-in loop, so we enclose all those commands in curly braces.
Example 4.40: Grouping commands together.
for ($each in $selectionList) { $x = `getAttr ($each + ".translateX")`; rename $each ($each + $x); }
Notice that each statement within the curly braces is terminated with a semicolon, but there was no semicolon following the curly braces themselves .
We can also place grouped commands within other groups, which we see in Example 4.41. In this example, we iterate through an array with a for-in loop, and then use an if statement as a conditional statement. The commands within the curly braces are only executed if the type of object stored in the current index of the array $selectionList is a transform node.
Example 4.41: Nesting command groups.
for ($each in $selectionList) { if (`nodeType $each` == "transform") { select replace $each masterGroup; parent; } print ($each + "\n"); }
This process, called nesting , is the fundamental element of the MEL script, the procedure.