MEL - Maya UI Building


#347

QTTabWidget.setPosition(‘South’) would make the tabs appear on the bottom. North, West and East are also valid options.

/Christian


#348

Hi all,
I trying to add new button to the Status line:

global proc toggleMyToolsButton() {
     
     	global string $gStatusLine;
     	global string $gStatusLineForm;
     
     	$statusLine = `formLayout -parent $gStatusLineForm`;
     	$gStatusLine = `flowLayout`;
     
     	setParent $statusLine;
     	$buttonForm = `formLayout`;
     
     	// Just a button 
     	global string $gMyToolsButton;
     
     	$gMyToolsButton = `iconTextCheckBox -image1 "bullet_selectSolverNode.png"	// test
     		-annotation ("My tools")
     		-changeCommand ("ToggleChannelBox") channelBoxButton`;	// test
     
     		///
     		// Set up the attachments.
     		//
     		formLayout -edit
     			-attachForm	$gMyToolsButton  top	1
     			//-attachControl $gMyToolsButton  left   0 $gLayerEditorButton	// Why this don't working?
     			-attachNone	$gMyToolsButton  bottom
     			-attachNone	$gMyToolsButton  right
     			$buttonForm;
     
     }
     
     toggleMyToolsButton();
But I don't alighn new button to other button like a "Show/hide Attribute editor/Layer editor/Channel box, etc.":


#349

Hi. I’m back to studying Python.
Now reading up on classes and how to utilize it with UI:s.

I’m having some problems figuring out how to get exactly what I want though and so I turn to you.
I’m using the book “Maya Python for Games and Film”. They are distributing a base window class found here:
http://maya-python.com/files/optwin.py

I then created another class which inherits from the base class, here:

import optwin
reload(optwin)

from optwin import AR_OptionsWindow


class newWin(AR_OptionsWindow):
    def __init__(self):
        AR_OptionsWindow.__init__(self)
        self.title = 'Dag\'s window'
        self.window = 'dag\'s window'
        self.actionName = 'Huey'
     

    def displayOptions(self):
        mc.setParent(self.optionsForm)
        self.btnA = mc.button(
                        label = "button A")


        mc.formLayout(self.optionsForm, edit=True,
                      attachForm=(
                      [self.btnA, 'left', 0],
                      [self.btnA, 'right', 0],
                      [self.btnA, 'top', 0],
                      [self.btnA, 'bottom', 0],

                      ),
                      
                      attachPosition=(
                      [self.btnA, 'right', 0, 50],
                      )               
        )

        
newWin.showUI()

It’s really simple. However I really can’t figure out how to align the button in the formlayout which is parented to the tab layout so it will scale with the window =/
Tried parenting the button to the mainForm instead and sure, that works, but I want it to be attached under the tab layout.

Thank you for reading!


#350

Ok, I figured this one out. However I still don’t get it… :banghead:

By editing the base class, the elements resize according to the formLayout settings.
on line 42 I changed:
scrollable=True to scrollable=False

However I really wouldn’t want to go in and edit the class, but it seems nothing else work. :rolleyes:

I tried to edit this in my inherited class:

    def displayOptions(self):

        mc.tabLayout(
                    self.optionsBorder,
                    e=True,
                    scrollable=False,
                    tabsVisible=True,
                    tli = (1, 'tab 1')
            	    )

This works for the tabVisible and tab label, but does nothing for the scrollable function. :argh:

Anyone could shed some light on this?

I’m posting both the edited class and my full inherited one for you to try.

https://dl.dropboxusercontent.com/u/16029672/3D/Script/optwin.py
https://dl.dropboxusercontent.com/u/16029672/3D/Script/optwin_derived_class.py


#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.