GUI
Controls in MEL
Controls include
buttons, text fields, sliders, radio buttons, etc.
Controls
can be added once you have created one or more Layouts
Some basic controls are covered here. See the MEL
command reference for full descriptions of the numerous controls available.
Check
Box -- Control
Groups -- Radio Button Group -- Slider
Group
|
Check
box:
Every control can be individually defined and placed in a window's
layout. A good candidate for this is the checkbox. This example includes
the -onCommand and -offCommand feature, allowing an event
to occur when the state of the checkbox changes.
//
checkbox
string $chkbxState = "not checked";
window -title "new window" -widthHeight 300 200 myWindow;
formLayout
-numberOfDivisions 100 myForm;
checkBox -label "check me"
-onCommand
"$chkbxState = \"checked\""
-offCommand
"$chkbxState = \"not checked\""
myChkBx;
button -label "print check box state"
-command "print $chkbxState" myBtn1;
formLayout -edit
-attachForm myChkBx "top" 10
-attachForm myChkBx "left" 10
-attachForm myBtn1 "bottom"
10
-attachForm myBtn1 "left" 10
myForm;
showWindow myWindow;
|
 |
Control
Groups:
MEL also features commands that put controls in groups
with convenient additions of labels and interaction between buttons, fields
and sliders.

This example uses
the checkBoxGrp command. A button calls the "makeObj"
procedure to query the state of each checkBox
control. This may appear more complex, but it is much easier and more
common than attempting to embed long scripts in the -command argument
for controls.
//
checkbox group
window -title "new window" -widthHeight 300 200 myWindow;
formLayout -numberOfDivisions
100 myForm;
checkBoxGrp
-numberOfCheckBoxes
3
-label "select
type"
-labelArray3
"sphere" "cylinder" "cube"
myChkBxGrp;
button -label "create object type"
-command "makeObj()" myBtn1;
formLayout -edit
-attachForm myChkBxGrp "top"
10
-attachForm myChkBxGrp "left"
-50
-attachForm myBtn1 "bottom"
10
-attachForm myBtn1 "left" 10
myForm;
showWindow myWindow;
proc makeObj() {
if (`checkBoxGrp -q -value1 myChkBxGrp`)
sphere;
if (`checkBoxGrp -q -value2 myChkBxGrp`)
cylinder;
if (`checkBoxGrp -q -value3 myChkBxGrp`)
polyCube;
}
|
Radio
button group
Radio buttons in a group are exclusive, meaning only
one can be selected and the others turn off.
Note the "-select" flag in the creation command, allowing you
to set a default selection.

//
radio button group
window -title "new window" -widthHeight 300 200 myWindow;
formLayout -numberOfDivisions 100 myForm;
radioButtonGrp
-numberOfRadioButtons
3
-label "select
type"
-labelArray3
"sphere" "cylinder" "cube"
-select
1
myRadBtnGrp;
button -label "create object type"
-command "makeObj()" myBtn1;
formLayout -edit
-attachForm myRadBtnGrp "top"
10
-attachForm myRadBtnGrp "left"
-50
-attachForm myBtn1 "bottom"
10
-attachForm myBtn1 "left" 10
myForm;
showWindow
myWindow;
proc makeObj() {
if (`radioButtonGrp -q -select myRadBtnGrp`
== 1) sphere;
if (`radioButtonGrp -q -select myRadBtnGrp`
== 2) cylinder;
if (`radioButtonGrp -q -select myRadBtnGrp`
== 3) polyCube;
}
|
Slider
group
A slider can be integers (intSliderGrp) or float
(floatSliderGrp).
In this case, "group" does not mean multiple sliders, but instead
it is grouped with a input field that reflects the current value of the
slider.

In this example, a floatSliderGrp has been added to the same script
above, allowing the user to set the scale of the objects when they are
created.
//
slider group
window -title "new window" -widthHeight 300 200 myWindow;
formLayout -numberOfDivisions 100 myForm;
radioButtonGrp
-numberOfRadioButtons
3
-label "select
type"
-labelArray3
"sphere" "cylinder" "cube"
-select
1
myRadBtnGrp;
floatSliderGrp -label "size"
-field true
-minValue
1.0 -maxValue 100.0
-value 1
mySlider;
button -label "create object type"
-command "makeObj()" myBtn1;
formLayout -edit
-attachForm myRadBtnGrp "top"
10
-attachForm myRadBtnGrp "left"
-50
-attachForm mySlider "top" 40
-attachForm mySlider "left"
-50
-attachForm myBtn1 "bottom"
10
-attachForm myBtn1 "left" 10
myForm;
showWindow myWindow;
proc makeObj() {
if (`radioButtonGrp -q -select myRadBtnGrp`
== 1) sphere;
if (`radioButtonGrp -q -select myRadBtnGrp`
== 2) cylinder;
if (`radioButtonGrp -q -select myRadBtnGrp`
== 3) polyCube;
float $scaleVal = `floatSliderGrp -q -value
mySlider`;
scale $scaleVal $scaleVal $scaleVal;
}
|