Updated on March 22 2013
back to MEL
Resources
Creating a GUI in MEL
Disclaimer: This page is to get you started and
is by no means complete or extensive. It's intention is to compare
the concepts learned in VSFX 705 in python as they would relate to
MEL.
We have studies the syntax of mel for scripting, however we
also need to add user level controls to our project. Again, there
are various ways to go about creating GUI.
This site is handy here but my preferred method to
find out windowing options is to type into the script editor
help window and then hit
ctrl-enter to give you the available list of commands
To make a window
window
-title "Kermit" -widthHeight 300 200 myWindow;
showWindow myWindow;
The problem is, if you run this again, it will say it is not
unique, so you need to delete it if you are doing to bring it up
again.
// Error:
line 1: Object's name 'myWindow' is not unique. //
So add the line above the previous code to do
just that.
if
(`window -exists myWindow`) deleteUI myWindow;
Layout of your window
Columns
if
(`window -exists myWindow`) deleteUI myWindow;
window
-title "Kermit" myWindow;
columnLayout -columnAttach "both" 5 -rowSpacing
5 -columnWidth 100;
button -label "make sphere" -command "sphere";
button -label "make cube" -command "polyCube";
showWindow myWindow;
Rows
if
(`window -exists myWindow`) deleteUI myWindow;
window
-title "Kermit" myWindow;
rowLayout
-numberOfColumns 2
-columnWidth 120 120
-columnAlign2 "center"
"center";
button
-label "make sphere" -command "sphere";
button -label "make cube" -command "polyCube";
showWindow myWindow;
Similarly you can use ie. gridLayout
-numberOfColumns2 -cellWidthHeight 80 20
frameLayout (creates boxes) and setParent command - ends the
definition of layout controls to be children of the previous
layout.
formLayout (exact positions)
Dialogs
How
to make your application respond to your GUI?
Here is a simple example to use as a starting point
if (`window -exists
myWindow`) deleteUI myWindow;
window -title "Kermit" -widthHeight 500 200
myWindow;
intSliderGrp -label "amount" -min 1 -max 60 -value 10 -field true
-changeCommand "phyllotaxis" total;
showWindow myWindow;
proc phyllotaxis()
{
int $total = `intSliderGrp -q -value total`;
print $total;
print "\n";
}
phyllotaxis();
Here is my exercise - completed code.