Loading a script file
 
 
 

You can read and edit script files other people have created in the Script Editor. In this section, you open a script that contains a completed user interface for the makeRoll procedure. However, the user interface is only a layout, and does not contain any functionality.

To prepare to open the script

  1. In the Script Editor, ensure that Command > Show Line Numbers is checked.

    When Show Line Numbers is on, line numbers appear beside the commands in the Script Editor. The lesson occasionally refers to line numbers to tell you where to make a modification to the script. When line numbers are referred to in the lesson, they are always the line numbers of the original script.

  2. Create a new tab in the Script Editor by selecting Command > New Tab.

    A pop-up window asks you in which language should the commands entered in this tab execute in.

  3. Click the MEL button on the pop-up window.

    You created a second MEL tab in the Script Editor.

  4. Select Command > Rename Tab.
  5. Enter MEL2.

    The tab is renamed.

In the next steps, you load a user interface script into both MEL tabs. The MEL tab will contain the original script, and the MEL2 tab will contain the user interface script with your modifications. This way, line numbers can be referenced from the original script to inform you where to make a modification.

To open a script file in the Script Editor

  1. Select the MEL tab.
  2. In the Script Editor, select File > Load Script.
  3. Select the MEL script named Mel_UI_Start.mel.

    This file can be found in the GettingStarted directory that you set as your Maya project, within the mel sub-directory.

    The contents of the MEL file are displayed in the Script Editor.

  4. Load the same MEL script into the MEL2 tab by repeating the above procedure.
  5. In the MEL tab, highlight the script by selecting Edit > Select All from the Script Editor menu bar.
  6. Execute the script by pressing Ctrl+Enter.

    A user interface is created for the makeRoll procedure. There is a control in the user interface for each argument of the makeRoll procedure.

    (You can leave this window open as we’ll be doing some testing with it, though it doesn’t do anything yet.)

Discussion: what the script does

  1. The controls in the user interface are created by various commands. Below,

the script has been broken up into sections to describe the various user interface controls and their flags. The user interface controls and commands that you used earlier in the lesson are described only briefly below.

Conditional statement

if(`window -exists makeRoll_Window`==1) { 	deleteUI makeRoll_Window; }

The conditional statement checks if a window with the specified name exists. If the window exists, it deletes it.

Window command

window -resizeToFitChildren 1 makeRoll_Window;

The window command creates a user interface window to contain the controls. For more information, see Creating a window.

Column layout

columnLayout;

The columnLayout command creates a layout that arranges the controls within it in a column. For more information, see Referencing controls.

Text field commands

$obj_name_text = 	`textField 	-editable 0 	-width 400 	-text name_Of_Object`;

The command textField creates an editable text field. The text field command has multiple flags. The name and path of the text field are stored as a variable. See Storing control names.

Slider commands

$ground_int= `intSliderGrp 	-minValue -20 	-maxValue 20 	-value 0 	-fieldMinValue -20 	-fieldMaxValue 20 	-field 1 	-label "Ground Plane"`; $diameter_float= `floatSliderGrp 	-value 1.0 	-minValue 1.0 	-fieldMinValue 1.0 -field 1 	-label "Diameter"`;

The commands intSliderGrp and floatSliderGrp create sliders. Commands ending in Grp create a group of linked controls. The slider commands create controls for a label, a value box and a slider. The slider command has multiple flags. The name and path of the slider are stored as a variable. See Storing control names.

Separator commands

separator -height 20 -width 120;

The command separator creates a horizontal line. It is used to space the controls vertically in the window. The separator command has multiple flags.

Check box commands

$box_sim_checkbox = 	`checkBox 	-value 1 	-label "Box Simulation"`; $sphere_sim_checkbox = 	`checkBox 	-value 0 	-label "Sphere Simulation"`; separator -height 20 -width 120; $execution_button= 	`button 	-label "Execute!" 	-command "print (\"something\");"`;

The command checkBox creates a check box. The check box command has multiple flags. The name and path of the check box are stored as a variable. See Storing control names.

ShowWindow command

showWindow;

This command enables the last created window’s visibility. For more information, see Creating a window.

NoteIn the script above, you do not explicitly declare your variables. This is because the return type of user interface creation commands is known to be a string, and cannot be any other data type. Later in the lesson, you will allow a data type to be implied, as you do not know what data type the return will be.