Mel
|
Introduction
This tutorial presents code that demonstrates how the state or
value of user interface (UI) widgets can be queried. These notes
assume the reader is using Cutter and that their Mel scripts will be
executed via a port. If the reader is not familiar with Cutter's
facilities they should review the following tutorials.
M:/mel/sliderUI.mel The script could then be run by entering the following command in Maya's script editor window. source "M:/mel/sliderUI.mel"; Of course Mel scripts can also be pasted directly into the script editor and executed by pressing the "enter" key on the numeric keypad. |
Creating a Window & Adding UI Widgets
The code to create a window and add two UI widgets is shown in listing 1.
The |
Listing 1 (sliderUI.mel)
Copy and paste the code into a new document in Cutter. Save it as sliderUI.mel. It may be necessary to wait a moment while Cutter reads its database of Mel commands. A progress bar will indicate when the commnands have been read. |
Querying a SliderThe code in listing 2 implements a proc that is called when the user clicks the "Get Slider Value" button. |
Listing 2
|
Use the keyboard shortcut Alt + e, Control + e or Apple + e to execute the Mel script. Maya will open a simple window containing a float value slider. The results of querying the slider ie. float $v = `floatSliderGrp -q -v $slider1`;
is echoed in the history pane of the script window. Note the
use of the variable |
|
Querying a Checkbox from a callback
Listing 3 shows how a callback procedure is registered with a checkbox.
When the checkbox is clicked, a callback named |
Listing 3 (checkBoxUI.mel)
|
Sliders and callbacks
Listing 4 shows how two callback procedures can be registered with a
slider. One callback, |
Listing 4 (sliderCallBackUI.mel)
|
Text Fields and callbacksListing 5 shows how a callback procedure can be registered with a textFieldGrp. The callback is invoked after the user has changed the text of the textFieldGrp and has subsequently pressed the enter key. |
Listing 5 (textFieldUI.mel)
|
© 2002- Malcolm Kesson. All rights reserved.