MEL - Maya UI Building


anyone heard about this??

Neoreel online MEL library…is a free plugin, which has a wonderful tool called visual ui builder…which is really nice for fast ui building …check it out


I want to create a set of buttons dynamicaly! Let me explain…

      I have my tree in outliner:
 From that tree I want to create buttons in my UI.
--> plastic would be a text --> under this "headline" it creates 3 buttons labeled "material1", "material2", ...
--> next "headline" --> button creation --> ...

My problem is to find out the nodes/groups under -geo- and of course the materials under their "headline"-node (plastic, etc.)

I hope some of you understand my problem. :smiley: Thanks in advance!


This is generally how to do it…I’ve left out any error checking, so it’ll just break if you don’t have an object named ‘GEO’

global proc makeWindow()
	string $sGeoNode = "GEO";
	string $saMatTypes[] = `listRelatives -children $sGeoNode`;

	string $sWin = "mw_UI";
	if (`window -q -exists $sWin`)
		deleteUI $sWin;

	window -w 200 -h 500 -rtf 1 $sWin;

	for ($sMatType in $saMatTypes)
		columnLayout ($sMatType+"_colName");
		string $saMaterials[] = `listRelatives -children $sMatType`;
		text -l $sMatType ($sMatType+"_textLabelName");

		for ($sMaterial in $saMaterials)
			button -l $sMaterial ($sMaterial+"_buttonName");

	showWindow $sWin;



Usually MEL Interfaces can become quite complex - this renders them hard to understand at first as the UI layouts are nested into a hierarchy.

This hierarchy is usually not represented visually by the code itself, but its only indicated by “setParent” statements.
Not only that this makes the reading ( and thus maintenance ) more difficult, but it can easily cause errors during development too due to forgotten and misplaced “setParent” statements.

The following code example shows how the scope operator is used to directly represent the underlying layout hierarchy. It also shows how the UI has been split up into sub-areas that are handled by respective functions - this helps not to distract from the actual structure/layout of the UI and facilitates reading.


   string $mainForm = 
    // -------------------------------
    `formLayout (mainLayout($id))`;
    // -------------------------------
    	int $valuePercent = 30
    	string $mainPane = 
    	// -----------------------------------------
    	`paneLayout -configuration "vertical2" 
    			-ps 1 ($valuePercent) 100
    	// -----------------------------------------
    		// hide or show the respective portion
    		// This will make look everything much better
    		if( $valuePercent == 0 )
    			// CONTENT FORM
    			// --------------------------------------------------
    			string $content = createContentForm( $id, $opts );
    			// --------------------------------------------------
    			// OUTLINER
    			// --------------------------------------------------
    			string $outliner = createOutlinerForm( $id, $opts );
    			// --------------------------------------------------
    			// OUTLINER
    			// --------------------------------------------------
    			string $outliner = createOutlinerForm( $id, $opts );
    			// --------------------------------------------------
    			// CONTENT FORM
    			// --------------------------------------------------
    			string $content = createContentForm( $id, $opts );
    			// --------------------------------------------------
    	}// END MAIN PANe
    	setParent ..;
    	// --------------------------------------------------
    	string $lines = createLineForm( $id, $opts );
    	// --------------------------------------------------
    	int $m = 2;
    	formLayout -e 
    		-af		$mainPane	"top"		 $m
    		-af		$mainPane	"left"		$m
    		-ac		$mainPane	"bottom"		$m	$lines
    		-af		$mainPane	"right"	   $m		
    		-an	   $lines	"top"			
    		-af		$lines	"left"		$m
    		-af		$lines	"bottom"   $m
    		-af		$lines	"right"	   $m
    setParent ..;


Hey Byron! Nice to read from you! :slight_smile:

Yea! I do that UI-indentation as well in the code but only without the {}!
But surely melstudio for instance would take some work from you if you’d do so. I mean type { and the next line is automatically indented… plus you have bracket-highlighting!

hmm… I’m thinkin about that when scripting next time ;]

wow, I took a look at your website now. seems you have something really huge up your sleeve!


hi there…anybody knows how i can put a BG image on my mel window? i want to make it look fancy and cute


I once hacked together a test with a completely custom button and background: I never really used it but seems it works:

window kasgkfWin;
   formLayout -w 300 -h 300 hbresavaForm;
   shelfButton -w 100 -h 100 -marginWidth 0 -marginHeight 0
   	-image "test_n.bmp"
   	-highlightImage "test_h.bmp"
   	-selectionImage "test_p.bmp"
   	-command "print\"HUHU!\
   image -w 300 -h 300 -image "C:/Do ...MAYAUSERFOLDER...  /maya/7.0/prefs/icons/test_bg.bmp"
   setParent ..;
   formLayout -edit
   	-af owahButton top 99
   	-af owahButton left 99
   	-af qwdfqwfBG top 0
   	-af qwdfqwfBG left 0
   window -e -w 300 -h 300 kasgkfWin;
   showWindow kasgkfWin;

Trick is to set the image after the button! this way its kept in background for some reason.
The paths to the shelftButtons images could be set relatively. That seemed not to work for the background image. But try for yourself. I think you’d manage to create a background and the button images. _n is for normal state, _h for mouseover and _p for pressed.


thanks! exactly what i needed :smiley: can i buy you a beer?


sure! :beer: cheers!


Im building a GUI and looking for a control to initiate the fileBrowser command. I know that I can create my own button and have it execute the fileBrowser command, but I thought that if maya has a premade control…that would be nice.

ps, Im on Linux and finder; is deffinately not what Im after.



Created my own thx


how did you do it?
screenshot or it didn’t happen! :smiley:


I used a textField and a symbolButton.


Great stuff here guys, I know this is a sticky thread so I thought I would say that a couple posts with links on the first page don’t even exist anymore.

Maybe we should do a new sticky thread with Python and MEL integration.



I made a mel script with three “symbolCheckBox” (Edit: sorry!). I like reset the other buttons to default value (off) when I turn on one button but I can’t do it…

Press Button1 -------> Button2 and Button3 turn off



symbolButtons don’t have an “off” status…?! do you mean symbolCheckBox? or do you mean you want to disable them…?

well, either way, your buttons have a press command right? so, in the command for button1 you just do something to the other buttons (using the -edit flag)…

for example:

symbolButton -c "symbolButton -e -vis 0 myButton2;symbolButton -e -vis 0 myButton3" myButton1;
symbolButton myButton2;
symbolButton myButton3;

this would create 3 symbol buttons, pressing the first makes the second and third invisible.


oops… …


Sorry NaughtyNathan! I’m wrong, my buttons are “symbolCheckBox”.

My problem is this, I Press button1:

[Button1] ON
[Button2] OFF
[Button3] OFF

Then I press Button2:

[Button1] ON -> I like this button turn off when I press Button2 (the same with button3)
[Button2] ON
[Button3] OFF


well you just do the same thing with each button command… turn the others off…

but it sounds like what you want is RADIO BUTTON behaviour… there’s no point manually hacking in a behaviour system that’s already present… don’t use symbol buttons, use iconText…Buttons as they are more versatile.

Take a look at iconTextRadioButton as this will probably be better for what you want.



Thanks! iconTextRadioButton works perfect!