MEL - Maya UI Building


#1

This thread is dedicated to Maya UI Building.

Please post any tips, tricks and advanced or general useful Maya UI Building knowledge in this thread.

Please only post Maya UI Building related examples, as there is already a sticky thread for general MEL posting.


#2

And since I’m the magic nose goblin who asked for it, it’s only right that I contribute something.

Here are links to two terribly useful UI tutorials at Bryan Ewert’s site.

The Scripted Panel Tutorial
The Form Layout Tutorial

-jl


#3

Okey dokey, since I just finished a MEL class last semester.
the direct UI page:

http://cade.scope.edu/courseware/notes/mel/uidesign.html

The entire MEL based set (FRAMES HTML)

http://cade.scope.edu/courseware/notes/mel/index.html


#4

This thread didn’t exactly take off like a rocket. Perhaps it needs some feeding. Here is a simple tutorial script that shows how to build and manage a textScrollList from the contents of a string array.


global proc scrollExample (){

    if (`window -ex "scrollWin"`)                    //does the window already exist?
        deleteUI "scrollWin";                        //if it does, kill it
    
    //define the window
    window                                         //create a window
        -title "Text Scroll Example"                 //give it a title
        -w 250 -h 220                             //set width and height
        "scrollWin";                                //give the window a unique name
        columnLayout -w 250;                        //create a column
        
            text -l "" -h 10;                    //text spacer
            textScrollList                        //set up the scroll list
                -h 200
                -w 240
                -ams false                        //disallow multiple selections
                -sc "scrollWinUpdateSel"            //the command used when an item is selected
                "swScrollList";                    //the control is given a unique, explicit name
            textField -w 240 "scTextField";        //text field also gets a unique name
            text -l "" -h 10;                    //text spacer
            
    swUpdateWin;                                    //call a general purpose window update
            
    showWindow "scrollWin";                        //tell Maya to draw the window
}



//general purpose window updater. This makes it
//easy to refresh the window contents from anywhere
//in the script with a single call
global proc swUpdateWin (){
    string    $cams[] = `ls -cameras`;                //create an array of all the cameras in the scene
    string    $x;                                    //it's a good idea to declare all variables
    
    textScrollList -e -ra "swScrollList";            //clear the scroll list before adding new stuff
                                                    
    //the list is now empty
    for ($x in $cams)                            //loop over the array with $x
        textScrollList                            //fill in the contents of the scroll list
            -edit                                //put the command in edit mode
            -append    $x                            //add every $x in $cams to the scrollList
            "swScrollList";                        //gotta tell it which scroll list to append to
}



//the selector proc. This is called by the command
//attached to the scrollList itself. The -sc flag
global proc scrollWinUpdateSel (){
    string    $sel[] = `textScrollList                 //define an array for the selection
            -query                                 //put the command in query mode
            -selectItem                             //get the string of the item the user selected
            "swScrollList"`;                        //naming controls makes this a snap
    
    textField                                    //put the name of the selection in the field 
        -edit                                     //put the command in edit mode
        -text $sel[0]                            //text is what we're editing. $sel is that text
        "scTextField";                            //name of the text field
}

-jl


#5

Hi Melon-

I also have procedures to add and remove items from a given textScrollList.

//Procedure adds selected objects to a given textScrollList.
global proc dwAddSelectedObjectsToList (string $textScrollListName)
{
//find out what exists in textScrollList.
string $textInScrollList[] = textScrollList -q -ai $textScrollListName;

//find out what´s selected in scene.
string $currentMayaSelection[] = ls -sl;

if (size($currentMayaSelection) == 0)
error “Nothing selected.”;

//remove all items from textList (need to “refresh” list).
textScrollList -e -removeAll $textScrollListName;

string $allSelectedArray[] = stringArrayCatenate $textInScrollList $currentMayaSelection;

string $cleanedSelection[] = stringArrayRemoveDuplicates $allSelectedArray;

for ($current in $cleanedSelection)
{
textScrollList -e -append $current $textScrollListName;
}
}

…and to remove selected items from list:

//Procedure to remove selected elements from a textScrollList.
global proc dwRemoveObjectsFromList (string $textScrollListName)
{
string $currentTextSelection[] = textScrollList -q -si $textScrollListName;
if (size($currentTextSelection) == 0)
error “Nothing selected in text list.”;
for ($currentText in $currentTextSelection)
{
textScrollList -e -ri $currentText $textScrollListName;
}
}

:beer:
David


#6

not that i want to say this thread is not worthy to be alive (it definitely is, since UI building took me the longest time to learn)… but dont you think that it would be well placed in the other mel scripts sticky thread?
the more sticky threads there are the faster questions plunge to page 2 that most ppl dont read.

how bout it?

cheers

alexx


#7

Yeah, good point. I also noticed the plethora of sticky threads was kind of overcrowding the normal threads. And yes, I admit it, I never read the second page… :stuck_out_tongue:
I don’t know…maybe there should be a “sticky section” or something where all the sticky threads go…

UI building took me the longest time to learn

longer than particle scripting??? I can’t believe that!

:beer:
David


#8

they are sticky threads for a reason. so you can easily find what you are looking for. myself as well as a few others dont feel it its getting over crowded. as far as posts in this thread and the sticky… any posts with just thanks! great! or other banter that does not contribute actual MEL or MEL links and info will be culled… to effectively organize them into a streamlined resource…

there are some stickies that can be “unstuck” and we will do a better job ensuring that page 1 does not get overcrowded…

if you feel a thread is worthy of page 1 glory, do us all a favour and bump it up… :slight_smile:

I appreciate your guys’ comments on the validity of this thread and stickies in general… thanks.

:beer:


#9

I hope its ok to ask UI related questions here, if not, feel free to move this over to the mel forum.
I have used the -w/-h flags on controls before without a problem, and also the position controls for formlayout, but here is the question. Whenever I have tried to use -w/-h for a window, they dont seem to work beyond the first time the window is opened. Is there a secret trick to this or something?

ie: I create a window with no retain flag and -w/-h set. test it, it works but I add a new control to the script, so I close that window, source the script again and it should be a bigger window, but its the same as the previous one, even though the width/height has been changed.

Thanks
-Todd


#10

Yeah, this stuff with the dimensions of windows/controls has always been a mystery to me as well. Even when you specify explicit w/h it just kinda´does what it wants. The only real way to fix the size of a window in my experience is to use -sizeable 0, but that of course fixes it at the specified size. There´s probably a logic somewhere to this but I stopped searching for it, and it´s not such a big deal for me…

:beer:
David


#11

there is a logic indeed :slight_smile:

usually in your preferences you have a checkbox set (default), that is called:

interface-> Windows: remember size and position

with that one switched on, you can only one specify the width and height of your window. after that maya reads the size out of the following file:

“C:\Dokumente und Einstellungen\yourname\Eigene Dateien\maya\4.0\prefs\windowPrefs.mel”

you can edit that file and throw out the line which has the size for your window… then you can create it again with your own settings.

cheers

alexx


#12

Alexx you is the man!

:beer:
David


#13

you´d better not ask me how long it took me to find THAT out :wink:

cheers david :beer:

alexx


#14

yeah, thanks a lot alexx.


#15

Originally posted by dwalden74
[B]Yeah, this stuff with the dimensions of windows/controls has always been a mystery to me as well. Even when you specify explicit w/h it just kinda´does what it wants. The only real way to fix the size of a window in my experience is to use -sizeable 0, but that of course fixes it at the specified size. There´s probably a logic somewhere to this but I stopped searching for it, and it´s not such a big deal for me…

:beer:
David [/B]

can’t you just use the command

     windowPref -remove myWindowName;   

to get rid of your size and position prefs for that window???


#16

Originally posted by dmcgrath
[B]Okey dokey, since I just finished a MEL class last semester.
the direct UI page:

http://cade.scope.edu/courseware/notes/mel/uidesign.html

The entire MEL based set (FRAMES HTML)

http://cade.scope.edu/courseware/notes/mel/index.html [/B]

do you know of any mirror sites for these? they seem to be offline.


#17

You can override the window size set by the user prefs by using the edit flah.

window -w 100-h 100 myWindow;
columnLayout;
button;
showWindow myWindow;

resize the window manually, then run

window -e -w 100-h 100 myWindow;

Just add that line after the showWindow command, and the window will open the same size


#18

Originally posted by bentllama
do you know of any mirror sites for these? they seem to be offline.

Check them every once in a while. They come and go.


#19

Hey guys I need to build this UI. And I’m a little stuck. :annoyed:
I need some help please.

The UI should look look this:

It needs 2 tabs:
The first tab needs to have 2 buttons with a sliders next to them on the same line.
And the second tab 4 buttons with silders next to them.


#20

hey guys, I have another question…yeah, i am full of them.

I am working on a UI for several scripts, and I was using a scrollLayout as a child of a tabLayout.

Everything is not OK immediately.

string $testTab =scrollLayout -horizontalScrollBarThickness 0 -verticalScrollBarThickness 16;
columnLayout -h 300 -columnAttach “both” 5
-rowSpacing 10 -adj true;

                          button;

setParent …; setParent …;

ok, here is the BAD part.
When I use this, the columnLayout is only a few pixels tall because the scrollLayout shrinks up on it. any suggestions?

Thanks in advance

-Todd