Datasheet
9
The intField command creates an integer field. The -width flag sets the field width in
pixels. The
-value flag sets a default value that appears in the field. -minValue and -maxValue
flags set lower and upper field limits. The
-changeCommand flag executes a command when
the value in the field is changed (and the Enter key is pressed). The command, appearing
between quotes, is the declaration of a variable:
int $cam_lens = `intField -query
-value enteredValuea`
A variable named $cam_lens is created. It’s defined as an integer (a whole number with
no decimal places) by including the
int option. The variable is equal to everything within
the single, back-facing quotes. In this case,
intField is used again; this time, however, the
-query flag forces it to output whatever the user entered into the field. Thus, if you enter
50,
$cam_lens becomes 50. The $cam_lens variable is used again in each of the button com-
mands, as in this example:
button -label “1 Node” -command “camera
-focalLength $cam_lens -farClipPlane $far_clip;
objectMoveCommand; cameraMakeNode 1 \”\””;
When the 1 Node button is clicked, it creates a camera with the camera command. The
focal length of the camera is determined by the
-focalLength flag. The focal length value
is provided by the
$cam_lens variable. objectMoveCommand is normally provided by Maya
in order to keep the new camera selected and is necessary in this situation. Note that it is
possible to have multiple commands within the button command quotation marks so long
as they’re separated by semicolons. The two backslashes at the end of the line are known as
escapes and are necessary when there are quotes within quotes. If the escapes are not present,
Maya becomes confused. To see what the 1-node camera command normally looks like in the
Script Editor, choose Create
➔ Cameras ➔ Camera.
As demonstrated with this example, variables are often necessary in MEL scripting. Three
simple types of variables exist:
int, float, and string. While int rounds off a number to a whole
value,
float maintains all the decimal places. string, on the other hand, stores words and
phrases, such as “hello there.” A variable is always signified by the initial
$ sign. For more com-
plex examples of variables and variable use within expressions and MEL scripts, see Chapter 3.
a
Creating an Autosave MEL Script
One of the first features that users of Autodesk 3ds Max miss when switching to Maya is the
autosave function. Although Maya has no autosave feature at this point, you can write one
with a MEL script. This requires a MEL command that can sit in the background and wait for
an opportune moment to save the file or to remind the user to save.
scriptJob does just that.
Creating an Autosave MEL Script
07405c01.indd 907405c01.indd 9 1/17/07 8:30:50 PM1/17/07 8:30:50 PM