Wednesday, February 1, 2012

Notes in building UI in Maya


I thought these couple notes on making ui's would be helpful.

Separating tab code into different functions so just removing a single line will remove the tab from ui.

Testing ui buttons with a simple print, this way can test ui even if backend tool needs changing.

The key things for tabs is, a tabLayout line, and a setParent line after tabs. Most of the code below is just formating the window. Using form gave me lots of control over where I wanted to put things in the ui.

Here's how the ui looked.

Here was the make gui function:

global proc makeGui()
//setup up title for gui
string $titleWindow = "Skinning Tool (c) Anozie 2012";

string $mainWindowName = "ToolMainWindow";

//delete window pref for this window if it exists
if(`windowPref -exists $mainWindowName`){ windowPref -remove $mainWindowName;}

if( `window -exists $mainWindowName` )
deleteUI $mainWindowName;
window -t $titleWindow -width 400 -height 260 -sizeable false $mainWindowName;

//optional add tabs here
string $tabs = `tabLayout`; //needed before can add tabs

showWindow $mainWindowName;

and here is an example of a tab, all the others have similar look.

The names for things in tab need to be different for different tabs.
This was a little confusing for me, so here is what i mean by above.

This here works:
if one tab had

textFieldGrp -l $name objectName;

and another tab had

textFieldGrp -l $name hithere;

but this wouldn't work
if one tab had

textFieldGrp -l $name objectName;

and another tab had

textFieldGrp -l $name objectName;

/////given a window add this tab
needs arguments
string name of window
global proc tabGetWeight_ui(string $winName)

if( `window -exists $winName` )

//what are the labels
string $titleTab = "get weight";
string $titleButton = "find weights";
string $t_getWeightVtx_TextField = "vertices";
string $t_getWeightJnt_TextField = "joints";

//set up format for gui
string $form = `formLayout -numberOfDivisions 320 $titleTab`;

textFieldGrp -l $t_getWeightVtx_TextField getWeightVtx_TextField;
textFieldGrp -l $t_getWeightJnt_TextField getWeightJnt_TextField;
button -label $titleButton -command "getWeights()" getButton;

//how should things be positioned
formLayout -edit
-attachForm getWeightVtx_TextField "top" 30
-attachForm getWeightJnt_TextField "top" 70
-attachForm getButton "top" 190
-attachForm getButton "left" 10

setParent $winName;//add tab to arg window


finally, here's the button command for the only button in the tab above

/////ui button command
needs no arguments
global proc getWeights()
print("getting weights");

I would also recommend taking a look at Walter Behrne's (polyextrude dot com) his online tutorials were fantastic, and I learned about tabs from reading them.