MEL UI query

I’m not sure if there’s a way to do this or not.

Is there a way to figure out either the name a button that was pressed on a user created UI window, or get the name of the window that the button belongs to, or basically any way at all to trace what was pressed.

What I’m trying to do is open multiple character UI windows which are all laid out the same except button and window names are different. Ex. I have character A and character B, then I have A_UI_Window and B_UI_Window. And in each window there’s a button, say select all character controls, that calls the same procedure. In this procedure that gets called, I want to differentiate from which window this button was pressed so I know which character to select all the controls on. The windows are all built off of nodes and then created by running the same script on all the nodes, so there’s no way to hardcode any value in there.

Does that make sense, and does anyone have any ideas :?:

If I understand correctly…

U have UIs that are created dynamically from a script?
So all the UI’s are named dynamically as well, like window1 window2 etc…?
When the buttons from those UIs are pressed they call a procedure?
And that procedure needs to know from which UI it was called?

in which case,
The script that creates the UIs could pass the UIs to the procedure as arguments;

string $window
string $button


// the procedure called by the UI
proc cly_nameButton( string $window, string $button) // UI "long" names passed by string arguments
{
	print ( $window+ " is the current window
" );
	print ( $button+ " is the current button
" );
}

// the UI creation
{
string $window = `window`; // the default is to not retain
	columnLayout;
		string $button = `button`;
		button -edit -command ( "cly_nameButton "+ $window+ " "+ $button ) $button;
showWindow $window;
}

Hey Joshua,

What I would do is when you create your button, create the button first then attach your -command in a new. By splitting up your command and your create you can make reference to itself.

This would print out the absolute path of your button or print out the text in your button:


string $buttonName = `button -l "This Button"`;
button -e -c("print \"This was the button:\"" + $buttonName + ";") $buttonName;

or

string $buttonName = `button -l "This Button"`;
button -e -c("print " + `button -q -l $buttonName` + ";") $buttonName;

I’m not sure how you have your code layed out but you could create your window and pass a Var that defines the character and have all your function take a $charCode:

global proc createCharWindow(string $charCode)
{
    window -l ($charCode + " Tools");
        columnLayout -adjustableColumn true;
            string $buttonName = `button -l ("Select:" + "$charCode)`;
            button -e -c("SelectBonesFunction " + $charCode + ";") $buttonName;
    showWindow;
}

I hope this is what you are after.

~B)

Ya it is possible via a debug process to backtrace a button that was pressed and trace it back through its execution, listing all the UI’s that have been created dynamically.

I did it once as a “fun” thing, fun being defined as… a bit like beating your head repeatedly against… anyway.

It is possible and very messy, but that was probably my approach at the time whilst dealing with some spagetti code.

You might find some guidance on the cached version on the way back machine of Brian Ewerts web site.

http://web.archive.org/web/*/http://ewertb.com

This one in particular maybe of interest to you.
http://web.archive.org/web/20050408083637/www.ewertb.com/maya/mel/mel.php?howto=101