2010

Table Of Contents
In this next section, well also create a new tempMEL tab so youll have a place
to test commands as you learn them.
To store the names of the currently selected objects as a variable
1 Create a new MEL tab (Command > New Tab in the Script Editor).
2 Rename it tempMEL (Command > Rename Tab in the Script Editor)
3 Type the following in the tempMEL tab:
select -allDagObjects;
This command selects all scene objects.
4 Type the following in the tempMEL tab:
$all_selected_objects =`ls -selection`;
This command lists currently-selected objects and outputs their names
to a variable.
5 Type the following in the tempMEL tab:
print $all_selected_objects;
This command outputs the list of stored objects to the Script Editor.
6 Execute the commands in the tempMEL tab.
The following is output to the Script Editor:
roll_Cube pPlane1
The variable $all_selected_objects is an array of strings. That is, it stores
multiple strings within the variable. Values in an array are called elements.
NOTE Arrays are used frequently in programming to manage large sets of data.
If arrays were not used to store large sets of data, you would need to create a
variable for each element of data, making scripts hard to maintain and taking up
lots of memory. For more information on arrays, see Arrays in the MEL and
Expressions guide.
Reduce your selection by extracting a single value from an array using an array
index.
To reduce the selection to one object
1 In the tempMEL tab, type the following:
$first_selected_object=$all_selected_objects[0];
select $first_selected_object;
696 | Chapter 13 Scripting in Maya