MEL - Maya UI Building


Hello again! (sorry, 'i’m very noob in mel script ‘_’)

I have a checkbox and one button. I like change the command button when checkbox is on or off.

For example:
[checkbox ON] -> Button command: setKey;
[checkbox OFF] -> Button command: BreakdownKey;


I would add a proc to the -changeCommand flag that basically queries the state of the checkBox and saves this in an optionVar. Than in your button command query the optionVar to know if the user wants a key or a breakdown. The advantage of storing it in an optionVar is, that you can retrieve this info later, even in a new maya session to restore your GUI to the configuration the user has used it the last time. I hope that makes sense.


Thanks Buexe! I’m trying use the optionVar and -changeCommand but I can’t do it. I’m very noob. Can you write a short example? or any web information where I can learn the basic.


here’s one way of doing it… personally, I’d do it a slightly more sophisticated way than this, but this is the simplest way I could think to explain it as you do seem to be having trouble with a controls -c “” flag…

global proc doFunction()
 int $isOn = `optionVar -q myOptionVarA`;
 if ($isOn)
  // do the thing that happens when the checkbox is ON
  // do the thing that happens when the checkbox is OFF
 checkBox -v `optionVar -q myOptionVarA` -cc "optionVar -iv myOptionVarA #1";
 button -c "doFunction";

hopefully you can decipher this easily enough… The only confusing bit is the #1… this simply represents the controls value (i.e. on or off), so every time the checkbox is changed (-cc) the optionVar is set the the checkboxes current value (#1)



Alright, this is for example your GUI:

 global proc myGUI () 
//bla bla, create layouts etc
global string $myCheckBox;
$myCheckBox = `checkBox -cc changeCheckboxProc`;
button -command myButtonCmd;
// bla bla, rest of GUI

Now when you click on you checkbox this proc will fire and store the optionVar

 global proc changeCheckboxProc() 
global string $myCheckBox;
int $value = `checkBox -q $myCheckBox`;
optionVar -iv $value myOptionVar;

This is your button command which will query the optionVar

 global proc  myButtonCmd() 
int $value = `optionVar -q myOptionVar`; 
print ("CheckBox state: " + $value + "

I hope this helps


shame on you Buexe, for encouraging a n00b to use global variables!! tsk :smiley: :wink:


Thanks! :stuck_out_tongue:


didn´t do it on purpose, guess i should turn off my auto-pilot once in a while : )


Hello again! :blush:

How can I create this “tab scroll”?



I’m trying to add a menu to the mainWindow menus. I’m able to get it up there but I would like for it to be up there on start-up. I don’t know what to add to the userPrefs.mel to call upon the script that adds the menu to the mainWindow on start up. I would like some assistance in this matter, please.


create a proc that adds your menu and add the name of that proc to the userSetup.mel file in some script dir Maya can find. Create a file with this name if there is not already one.


dear MEL ppls.

I am strugling with the layout. could any one help me with this plz?

window -t “controls” -resizeToFitChildren true;
rowLayout -numberOfColumns 5 ;
columnLayout -columnAttach “both” 12 -rowSpacing 8 -columnWidth 400;
setAttr “Craneturn.rotateY” 0;

string $mainturn;
$mainturn = “Craneturn”;
attrFieldSliderGrp -l “Main rotate” -min 0 -max 360 -at ($mainturn+".ry");

string $Lift;
$lift = “Liftingcontrol”;
attrFieldSliderGrp -l “Lifting” -at ($lift+".LIFTING");

string $Mainhooklow;
$Mainhooklow = “grotehaak”;
attrFieldSliderGrp -l “Main hook LOW” -at ($Mainhooklow+".Grote Haak");

string $Mainhookrot;
$Mainhookrot = “mainhookrotate”;
attrFieldSliderGrp -l “Main hook ROT” -at ($Mainhookrot+".Mainhookswing");

string $smallhooklow;
$smallhooklow = “kleinehaak”;
attrFieldSliderGrp -l “kleine hook LOW” -at ($smallhooklow +".kleinelower");

string $smallhookrot;
$smallhookrot = “kleinrotate”;
attrFieldSliderGrp -l “kleine hook ROT” -at ($smallhookrot +".smallsling");

string $trollyslide;
$trollyslide = “trollycontrol”;
attrFieldSliderGrp -l “Trolly slider” -at ($trollyslide +".trollyupdown");

setParent …;
columnLayout -columnAttach “right” 2 -rowSpacing 8 -columnWidth 100;
button -l “select” -w 100 -c “select -r Craneturn”;

setParent …;

columnLayout -columnAlign “both” -rowSpacing 8 -columnWidth 100;

button -l “key” -w 100 -command “setKeyframe Craneturn”;

setParent …;


I f i test this then the sliders are oke but the SELECT button and the KEY button are on the top slider. but i want them to be to the right of that slider.
how can i do that?


There are usually more than a few ways to lay out a UI but I think the smallest change that you could make to get things going would be to change your rowLayout call to this:

 	rowLayout -numberOfColumns 3 
 		-adjustableColumn 1 
 		-columnAlign  1 "left"
 		-columnAttach 1 "left"  0
 		-columnAttach 2 "left"  0
 		-columnAttach 3 "left"  0;


I dont get it…

window -t “controls” -resizeToFitChildren true;

rowLayout -numberOfColumns 3
-adjustableColumn 1
-columnAlign 1 “left”
-columnAttach 1 “left” 0
-columnAttach 2 “left” 0
-columnAttach 3 “left” 0;
[size=1]setParent …;
setAttr “Craneturn.rotateY” 0;
string $mainturn;
$mainturn = “Craneturn”;
attrFieldSliderGrp -l “Main rotate” -min 0 -max 360 -at ($mainturn+".ry");


it stays the same as before? … and what does the 0 mean at the end of the lines


How can you create a floating window that will pop-up at your mouse’s pointer position (when key is pressed) and is there a way to make it vanish by pressing the same keystroke that made it appear or something similar ?


Unfortunately there is no simple way (and simply no way with MEL-only) of determing the current cursor position. But you can create custom popupMenus under the mouse cursor no prob!


Cool ! What do you mean when you say popupMenus, though ?

Appreciate the reply.


have a look at the popupMenu docs or maybe try that:

opens a window clicking left or right anywhere in the window pops up a menu under the cursor:

	popupMenu -button 1;
		menuItem -divider 1;
	popupMenu -button 3 -markingMenu 1;
		menuItem -radialPosition N;
		menuItem -radialPosition W;
		menuItem -radialPosition E;
		menuItem -radialPosition S;

Its a window with columnLayout but actually you can put a popupMenu to any control or layout in Maya!


Thanks a ton ewerybody !

Sorry it took a little bit to reply but I was trying to mess with it a little more before I did. But now, I’ve been trying more to switch the track/pan from alt+mmb to alt+rmb. So, I’ve just started reading some C++ to see if I could use it for this situation.

But when I’m done with that (hopefully I will get it done-lol), I will focus more on windows ! I appreciate your help.


string $example_window = window;

string $example_form = formLayout -numberOfDivisions 100;

string $Ftrust_grp = `floatSliderGrp -l “draai”

-field false

minValue 0.0 -maxValue 10.0

string $Ftrustsel = button -l "SELECT";

string $Ftrustkey = button -l "KEY";

formLayout -edit

-attachPosition $Ftrust_grp “top” 10

-attachForm $Ftrust_grp “left” 10

-attachNone $Ftrust_grp “bottom”

-attachForm $Ftrust_grp “right” 10

-attachPosition $Ftrustsel “top” 20

-attachForm $Ftrustsel “left” 10

-attachNone $Ftrustsel “bottom”

-attachForm $Ftrustsel “right” 10

-attachPosition $Ftrustkey “top” 30

-attachForm $Ftrustkey “left” 10

-attachNone $Ftrustkey “bottom”

-attachForm $Ftrustkey “right” 10


showWindow $example_window;

gives me the next error?

// Error: string $Ftrustsel = button -l "SELECT"; //

// Error: Line 6.17: Syntax error //