MEL - Maya UI Building


#101

well its actually the uv texture window…i’ve appended another menu to the end of it. and originally i had it as a column layout but the seperator did not close for it. as a gridLayout it works nicer but looks messier.
the texture window uses grid and form layout alot but the script i added is a uv set display radio button collection thing, and it updates every selection change, and being new to MEL i wasn’t sure how form layout would react to this…plus i don’t know much about formLayout.

thanks for the hug…ahhh


#102

I was looking through the binary for syflex, and noticed that their UI code is programmed using mel rather than API code. How can you call mel code (and have it compiled into the plugin) from within an api program?


#103

Thanks Mikademius - I’ll look into it pronto.

I got sort of a hacked version for me to work back in July for the animators down stairs, but it got reported back to me recently that that version doesn’t work consistently. For some of them, the window height is five buttons; for others it’s like 2.

I’ll post a stripped down version of my script in a bit if I can’t get it to work

Thanks, again.


#104

Well, here’s what I have for the UI script (including Mikademius’ suggestion):


         
  //populates the grid layout with a bunch of buttons determined at runtime
  global proc MakeButtons()
  {
  	for ($i=0; $i < 50; $i++)
  	{
  		string $itemname = string($i);
  		button -al left -ann $itemname -p "griddy" -label $itemname;
  	}
  }
  
  global proc ScrollResizeCommand()
  {
  	//for debugging purposes - find the area of the scroll area I am trying to fix
  	int $value[] = `scrollLayout -query -scrollAreaValue "animscroll"`;
  	$value[2] = `scrollLayout -q -saw "animscroll"`;
  	$value[3] = `scrollLayout -q -sah "animscroll"`;
  
  	intField -e -v $value[0] scrolll;
  	intField -e -v $value[1] scrollt;
  	intField -e -v $value[2] scrollw;
  	intField -e -v $value[3] scrollh;
  }
  
  //makes a window with a grid inside of a tab inside of a column.
  global proc MakeAWindow()
  {
  	if (`window -q -ex layoutwin`) deleteUI layoutwin;
  
  	window -t "Anim Palette" -mnb on -rtf true layoutwin;
  		columnLayout -columnAttach "both" 5 -adj true jm2al;
 			text -l "";	//place holder for other controls	
  
 			$tabs = `tabLayout -cr true /*-scr true*/ -imh 5 -imw 5 -h 800 palettetab`;
  			
 		 	// Animation tab 88888888888888888888888888888888888888888888888888
 				$animcol = `columnLayout -adj true animcol`;
  				
 					rowLayout -nc 4
 		 			-cw 1 44 -cw 2 44 -cw 3 44 -cw 4 44 ;
 		 			intField -ed 0 -w 32 scrolll;	//place holder for other controls
 		 			intField -ed 0 -w 32 scrollt;
 		 			intField -ed 0 -w 32 scrollw;
 		 			intField -ed 0 -w 32 scrollh;
 					setParent..;
 						
 					//the button "palette" layout
 					string $animscroll;
 		 		$animscroll = `scrollLayout -cr true -h 800 animscroll`;
 		 		 frameLayout AnimPalette;
 		 		 	gridLayout -autoGrow true -columnsResizable true -cellWidthHeight 100 25 -nr 25 griddy;
 		 		 	setParent..;	
 						setParent..;
 					setParent..;
  				setParent..;
  
 		 	// Pose Tab 8888888888888888888888888888888888888888888888888888888
 		 	$posecol = `columnLayout -adj true posecol`;		
  
 		 		text -l ""; //place holder for other controls
  				setParent..;
  
 		 	tabLayout -edit -tabLabel $animcol "Animations" -tabLabel $posecol "Poses" $tabs;
 		 	scrollLayout -edit -rc "ScrollResizeCommand()" animscroll;
  			setParent..;	
  		setParent..;
  	setParent..;
  	
  	MakeButtons();
  	showWindow;
  	ScrollResizeCommand();
  }
  
  MakeAWindow();
         

Just to refresh some memories, I am trying to get a grid of buttons (inside of a tab, which itself is inside of a columnLayout) to display in a screen area that is resizeable, or at least consistent from one animator’s machine to the next.


#105

I want to give my gui a dynamic optionMenu, so the menuItems should change when the user clicks specific controls. I found no hints about flags for optionMenu or menuItems with which I can remove or change the menuItems.

Any Ideas?

Thanks,
phantastikfan


#106

If you want to add controls to a certain layout based on user interaction, see the -p flag (parent). About the updating, I’m not sure. Could just reopen the window in a command, but that wouldn’t be a good idea really.


#107

Here’s a quick and dirty sample of what you can do. It gets tricky if you want to replace on specific elements, but if you want to stay simple, try deleting and reconstructing menus in one shot. Otherwise, it’ll take a bit of design and forethought to keep it clear and bug-less. Look into the edit flags to see what they allow you to do - good luck.


   
   global proc MakeMenu1()
   {
   	global string $menuname;
   
   	//delete the previous menu
   	menu -e -dai $menuname;
   
   	//make a new one    
   	menuItem -p $menuname -l "one";
   	menuItem -p $menuname -l "two";
   	menuItem -p $menuname -l "three";
   
   
   }
   
   global proc MakeMenu2()
   {
   	global string $menuname;
   	menu -e -dai $menuname;
   
   	menuItem -p $menuname -l "uno";
   	menuItem -p $menuname -l "dos";
   	menuItem -p $menuname -l "tres";
   }
   
   
   global proc MakeAWindow()
   {
   	global string $menuname;
 
 	//if this window exists already, delete it before we create it again
   	if (`window -q -ex layoutwin`) deleteUI layoutwin;
   
   	window -t "menu testing" -mnb on -rtf true layoutwin;
   		menuBarLayout;
   			$menuname = `menu -l "file" lemenu`;
   		setParent..;
   		columnLayout;
   			button -l "menu 1" -c "MakeMenu1()" but1;
   			button -l "menu 2" -c "MakeMenu2()" but2;
   		setParent..;
   	setParent..;
   	
   	showWindow;
   }
   

#108

That piece of code looks pretty good, thanks, but I think it will only work for the command “option”, but I am using “optionMenu” (something like a selectbox) and that does not have the flag -dai (-deleteAllItems) :frowning:


#109

If you want to get rid of a menuItem from an optionMenu you could do this…


  string $items[] = `optionMenu -q -ill MyOptionMenu`;
  deleteUI -menuItem $items[0];
  

…so you could go through and delete the items and then replace them if you wanted to.


#110

I didn’t know that there is a command “deleteUI”, I think that will work pretty well, thanks for the tip!


#111

anyone know how to make this type of control :

Thanks.


#112

That’s a gradientControl, should have an example in the docs (I think, not at my own machine at the moment so can’t check!)


#113

Never mind this post:)


#114

Hi,

Just a quick and stupid question… I’d like to make a status line consisting of 2 lines of text. The textfield element seems to allow only one line (I’m using \r or
), any ideas ?

Thanks,

Jens


#115

I have written an exporter with the MAYA API. I am using a MEL Script for the export GUI that allows the user to configure the export. The script looks something like this.


global proc int exportOptions( string $parent,
string $action,
string $initialSettings,
string $resultCallback )

{

 ...
 ...
     
     if ($action == "post") {
            
         //build GUI with controls
             ...
             ...
                                       
     } 
     else if ($action == "query") 
     {
             //build resultstring with useroptions
             $result = 1;
             ...
     } 
     else 
     {
             $bResult = 0;
     }
     
     return $bResult;        
 
 return 1;

}


I have a radio button in the GUI. If the user chooses the second option of this button, I want to refresh the GUI and add a checkbox the user can select.

I know how to query the radio button, but what do I have to do to refresh the GUI when the user clicks the radio button ?


#116

put a query/refresh procedure on the -changeCommand flag of the appropriate control.


#117

thanks, that was exactly what i needed.


#118

Is there a way to use the gradientControl without attaching it to a ramp? I want to use this control in a UI for the user to set up several values between 0-1 and then I want to query these for use later in a proc. But I don’t want to create a node everytime the user wants to use the tool…

:hmm:


#119

Is there a way to use the gradientControl without attaching it to a ramp?

I think this is what you are looking for…you can “attach” an optionVar which will hold the values of the points in the control. I think that that each entry in the string array will have 3 comma separated numbers which represent the value, position and interpolation type.


  global proc checkMyGradValues()
  {
     print ("
Getting values from the gradient control...
");
  
     string $gradPoints[] = `optionVar -q "GradNoAttrCtrlOpVar"`;
     for ( $point in $gradPoints )
     {
  	  string $values[];
  	  int $n = `tokenize $point "," $values`;
  	  if ( $n != 3 ) continue;
  
  	  print ("point at position " + $values[1] + " with value " + $values[0] + "
");
     }
  }
  
  {
     optionVar -rm "GradNoAttrCtrlOpVar";
     optionVar -stringValueAppend "GradNoAttrCtrlOpVar" "1,0,1";
  
     window;
     columnLayout;
     button -command "checkMyGradValues";
     gradientControlNoAttr -ov "GradNoAttrCtrlOpVar" GradNoAttrCtrl;
     showWindow;
  }
  

#120

Thank you very much. That’s exactly what I’m looking for :bounce:
Why does the query return “value” , “position”, “value”? I thought the first one was the ID for the point…