MEL - Maya UI Building


#351

I am completely stumped with this. I’m trying to build a character control GUI with a background image and buttons or some other clickable object laid over the top but I can’t get it working. The buttons are not clickable and behind the image and I have no idea why. I’ve basically pieced this code together from other character gui’s so I’m at a loss. Any help would be appreciated.

string $title = "Control Window";
 	int $width = 640;
 	int $height = 700;
 	
 	//create window
 	if(`window -q -exists UIWin`){
 		deleteUI UIWin;
 		}
  
 	 string $win = `window -title $title -widthHeight $width $height`;
 
 	// create tablayout
 	string $tabs = `tabLayout -innerMarginWidth 5 -innerMarginHeight 5`;
 
 //Body Tab
 		string $tab_cl1 = `columnLayout -w $width -h $height -adj 0 Body`;	
 		
 		// create a formLayout
 		string $form= `formLayout -numberOfDivisions 640`;
 		
 		
 		
 		//createButton
 		string $bodyButton =`button -w 70 -h 20 -label "Body" -ann "Select body control" -c print "body select"` ;
 		string $chestButton =`button -w 70 -h 20 -label "chest" -ann "Select chest control" -c print "chest select"` ;
 
 		
 		//creat image
 		string $BodyPage = `image -image "guiTail.png"`;
 
 		// FormLayout edit
 		formLayout -edit	  
 			  
 		-attachForm $bodyButton "top" 300
 		-attachForm $bodyButton "left" 200
 		
 		-attachForm $chestButton "top" 40
 		-attachForm $chestButton "left" 400
 
 		   
 		-attachForm $BodyPage "top" 0
 		-attachForm $BodyPage "left" 0
 $form;
 
 setParent..;
 setParent..;  
   
   
 //Show Window
 showWindow $win;

#352

Try creating the buttons after the image.

David


#353

Thanks, but I still can’t figure it out. I did as you suggested but the buttons are still behind the image. It seems that no matter what order I put the buttons and the image, the image is always in front. Is there anything else I could be missing?

Edit: Curiously if I instead use a symbolButton for the background image but have “-enable 0” so it cannot be clicked the control buttons are placed in front and work fine. The problem with this is “-enable 0” makes the image black and white.


#354

This might be a useful reference for people trying to understand how to hook up callbacks in Maya python:

http://techartsurvival.blogspot.com/2014/04/maya-callbacks-cheat-sheet.html


#355

hello. im Gabriela and i would like your help to have a job that could help me. work is autodesk maya mel proxy.
my work consists of the following

Create a script that allows me to create the proxy of a helicopter (model of a helicopter in
very low poly)
 must include a general controller type Nurbs Circle function as father of all
hierarchy.
 must create an expression that allows me to assess:
 If the helicopter is on the ground not moving propellers.
 If the helicopter rises must turn the propellers.

appreciate a reply thanks. :sad:


#356

We are not going to do your homework for you. Post code so we can see what you are struggling with.


#357

Maya gui trivia: somebody knows how to hide the x button in a widget so users cannot close them? Or make hitting that button crash save?
Thanks


#358

I’m learning to use Python in Maya and I’ve got a simple question. I’m creating a UI window code where I’m setting the pivot = of a .nurbsCube(). I created this Float Field Group that has 3 value fields.

pivotSet = cmds.floatFieldGrp(numberOfFields= 3, label= 'Pivot', value1= 3 ,value2= 1,value3= 1)

I’m trying to set the values of this field in another function that will use that pivotSet for the pivot =:

pivotSet = cmds.floatFieldGrp(pivotSet, query= True, value1= True ,value2= True, value3= True)

However, when I do this the function only returns a single float (value1) instead of all three values, so how can I fix this?


#359

Venator11387,
To ‘set’ the value you need to ‘edit’ the floatFieldGrp, ‘Query’ returns the existing values.

 cmds.floatFieldGrp(pivotSet, edit= True, value1= 1,value2= 2, value3= 3)

or

 cmds.floatFieldGrp(pivotSet, edit= True, value= (1, 2, 3)

Hope that helps :slight_smile:
Craig


#360

Awesome, that did it! Thanks!


#361

You’re welcome
:slight_smile:


#362

So I’m trying to set the vector direction of a uniform field by a value queried from a FieldGrp. However, when I try using the method below I get the following error:

# Set FieldGrp  
frontUniDir = cmds.floatFieldGrp(numberOfFields = 3, label = 'Front Wind Dir', value = ( -1.0, 0, 0, 0 ) )

# Query FieldGrp vector values
frtUniDirVal = cmds.floatFieldGrp( frontUniDir , query = True, value = True )

# Set Uniform Field Direction
cmds.setAttr( 'snowUniformField_Front.direction', frtUniDirVal )

Error: setAttr: Error reading data element number 1: [-1.0, 0.0, 0.0]

Traceback (most recent call last):

File “<maya console>”, line 38, in editCreate

File “<maya console>”, line 116, in editSnow

RuntimeError: setAttr: Error reading data element number 1: [-1.0, 0.0, 0.0]


#363

Try adding this to the setAttr -row:
type=float3


#364

Try adding this to the setAttr -row:
type=float3

Tried it and I got the same error. I also tried the code below, but once again the same error.

    cmds.setAttr( 'snowUniformField_Front.direction', frontUniDir[0], frontUniDir[1], frontUniDir[2], type = 'float3' )


#365

guys, pardon for this absurd question, Im very newbie to MEL. I wanted to create a simple UI window with only 1 floating number input to modify stepsnap value.

I have followed some simple tutorial to create window with floating input =

// the name of the float field
global string $floatFieldName="";

        global proc floatValueChanged() {
            global string $floatFieldName;
            
            // query the value from the float field
            $value = `floatField -query -value $floatFieldName`;
            
            // print value
            print("newValue="+ $value +"

");
}

        // window creation scoped to prevent unesseccary
        // globals being defined
        {
            string $window = `window`;
            columnLayout;
                floatField;
                
            showWindow $window;
        }

now I dont know how to connect that with the Mel command =

manipMoveContext -e -snapValue 10 Move;

Im very newbie so pardon for this simple question. Id appreciate any help.
Thank you


#366

Hi, you could borrow some of my code for this if you want;


 global proc stepSize_move(){
 	
 	int $mayaver = `about -v`;
 	string $window = "stepSizeWindow";
 	int $moveStepQ = `manipMoveContext -q -sv Move`;
 	
 	if (`window -ex $window `)
 		{ deleteUI $window;}
 		
 	window -title "Adjust Step Size" -width 200 -height 100 -rtf 1 $window;
 	
 	manipMoveContext -e -snap true Move;
 	manipMoveContext -e -snapRelative true Move;
 	columnLayout -adjustableColumn true;
 	
 	if ($mayaver <= 2015)
 	{
 		floatFieldGrp -nf 1 -pre 2
 			-label ("Move (mm) "+(uiRes("m_manipMoveProperties.kStepSize")))  
 			-v1 ($moveStepQ * 1)
 			-cc ("manipMoveContext -e -snapValue (#1/10) Move;")
 			manipMoveSnapValue;	
 	}
 	if ($mayaver >= 2016)
 	{
 		floatFieldGrp -nf 1 -pre 2
 			-label "Move (mm)"
 			-v1 ($moveStepQ * 1)
 			-cc ("manipMoveContext -e -snapValue (#1/10) Move;")
 			manipMoveSnapValue;	
 	}
 	
 	button -label "Close" -command ("deleteUI -window " + $window +"; manipMoveContext -e -snapValue 1 Move;");
 	
 	setParent ..;
 	showWindow $window;
 }

I never bothered making it more efficient as it is a hack job, but it works really well.


#367

Hi, Hamburger, thanks for the quick reply.
I tried to use ur code but nothing happened?

I am using Maya 2016 btw


#368

Well what I posted is a script.

However it is a procedure which is slightly different to what you were doing. With a script what you were typing, Maya can run it every time but that’s not the most effecient way to run code so instead we can tell Maya what the script is through what’s called a procedure. Basically a little shortcut so Maya knows which script to use instead of typing it all out.

We can just run it everytime with this command;

stepSize_move

and Maya will recall the entire script itself. If you want to do it the other way you can just remove this line; global proc stepSize_move(){

and the very last line; }

So save that “procedure” as a mel file (stepSize_move.mel) and put in in your My Documents\maya\2016\scripts. Start Maya and just type in (or save) stepSize_move and Maya will know which mel file to use. That’s the basics, hope it helps.


#369

Thank you sirrr, you helped me alottttttt :bounce: :bounce: :bounce: :bounce: :bounce: :bounce: :bounce: :bounce: :bounce:

it works perfectly now :slight_smile:


#370

HI,
I was searching for a visual way to build the Mel gui. As i’m not a coding guy it’s really hard to build the ideal Gui i want.

I googled a lot about it but unfortunately found nothing. Although whatever i’ve found is way too old and not that much useful.

So if there’s anyone know any tool like this please help me.please urgently. :slight_smile: