PDA

View Full Version : How to get name of UI component?


Sebek128
11-23-2010, 10:49 AM
I'm trying to make character pose copy/paste tool. I strore poses by saving attributes into file and creating snapshot of viewport and placing an image in UI window.

I would like to paste the pose by clicking on the image.
What I need is geting the name of image which is being clicked, to paste attributes from coresponding file.

Any tips?

NaughtyNathan
11-23-2010, 01:45 PM
I assume you are talking about pure Maya (elf) UI and not QT? also Mel or Python?

image controls don't have any "click" facility, so you will need to use a different control that accepts user-clicks (i.e. symbolButton, iconTextButton, swatchDisplayPort, etc...). (you could use the pop-up or drag/drop trick to add click functionality to any control, but I'm guessing this may be too complicated for you right now...?)

The easiest way to handle the UI name is to give it one yourself and then just specify that in the command string. e.g.

symbolButton -image "posePic.bmp" -c "runFunction myPoseButton" myPoseButton;this creates a symbolButton called "myPoseButton", which the command string refers to directly, passing this name to the function "runFunction". If for some reason you don't want to hardcode your control names where necessary you can grab the name into a variable and encode that into the command:

string $myButton = `symbolButton -image "posePic.bmp"`;
symbolButton -edit -c ("runFunction "+$myButton);
:nathaN

Sebek128
11-23-2010, 02:51 PM
Thanks for replying.

I assume you are talking about pure Maya (elf) UI and not QT? also Mel or Python?

I use just pure MEL UI.


symbolButton -image "posePic.bmp" -c "runFunction myPoseButton" myPoseButton;

I dont know if I understand it correctly. Does this
1) cerate button that executes "runFunction myPoseButton" command , or
2) cerate button that executes "runFunction" command with myPoseButton as an argument ?


(you could use the pop-up or drag/drop trick to add click functionality to any control, but I'm guessing this may be too complicated for you right now...?) [/code]:nathaN

I was thinking about popup menu the same for each image, runnig the same command with the name of image being an argumet for the command. But still I wasn't able to get the name of image I have oppened popupmenu on.


Reagrds,
Sebastian

ewerybody
11-24-2010, 11:26 AM
I'm trying to make character pose copy/paste tool. I strore poses by saving attributes into file and creating snapshot of viewport and placing an image in UI window.sounds like you are writing poseLib (http://www.creativecrash.com/maya/downloads/scripts-plugins/animation/c/poselib) :D

To the symbolButton example:
symbolButton -image "posePic.bmp" -command "runFunction myPoseButton" myPoseButton;clicking the button executes the string given along with the -command flag. In that case yes 2)! One could say "myPoseButton" is an argument of "runFunction". But you can actually put anything in such a string as long its formated correctly any syntactically right not just one word, even a whole script. Of course for overview: shorter is always better on commands like that.

but.. Why not paste a little bit of code you have trouble with?! Might be better than us throwing vague suggestions at you.


btw: refering to the topic "How to get name of UI component?" I recently set up this : muix01 (http://goodsoul.de/mel/muix01.mel). drop onto maya, run "muix01", inspect UI components. (but beware! there is a but crashing some versions of maya when querying ui types)

Sebek128
11-25-2010, 10:11 AM
Thanks NaughtyNathan and ewerybody, Your tips seemed to be extremely useful.
I have made small test script and it works fine.



sounds like you are writing poseLib (http://www.creativecrash.com/maya/downloads/scripts-plugins/animation/c/poselib) :D


Well it looks exactly what I am trying to do, but it just will be built in a character control panel of my rig

NaughtyNathan
11-25-2010, 10:27 AM
anything you place inside quotes "" is a literal string. this means that when you press your button, it is executing the MEL code:

runFunction $name;which is obviously not what you ever want. you need to encode the variable into the resulting command string, not place it directly "inside the string":

button -l $name -command ("runFunction "+$name) $name;this catenates the literal string: "runFunction " with the contents of the variable: $name to produce a final command string of: "runFunction button1" (or whatever the button name is at that exact point).

one further point, any functrion called by a UI control must be global.

:nathaN

Sebek128
11-25-2010, 10:31 AM
I have just spotted my mistake, and edited previous post.

Thanks a lot.

Sebek128
11-25-2010, 02:13 PM
Now I remember why I didn't use symbolButton.

This is part of code I was using

playblast -v false -frame 1 - percent 100 -w 120 -h 120 -orn 0 -cf ($filepath) -fmt "image";
$images[$count] = `image -image $filepath -w 120 -h 120 -parent bodyForm`;

It works.
After changing Image to symbolButton I got an error File not found.
Of course file exists where I expect it to be. $filepath variable is full path to the file.

I tried to use filetest command, just before editing buttons image, to find out what is happening.

filetest -r $filepath;

I didn't work. It didn't even returned 0. Just nothing.

Looked strange for me so I typed filetest -r $filepath; in script editor while my script was still working (got my UI still open)
Now it returned 1.

Is it possible that it wasn't able to set image for button because it haven't been saved yet?

I tried to wait for it

while ( (`filetest -r $filepath`) !=1 )
{
filetest -r $filepath;
};


It just gets out of loop and print the same error message.

Am I doing it completely wrong or is it something wrong with symbolButton?

-------------------------------------------------------------------------------------------------
----------------------------EDIT---SOLUTION------------------------------------------------
---------------------------------------------------------------------------------------------------

My brain is fried after whole day of struggle but the solution is easy.
symbolButtton accepts *.bmp files (defenetly no jpg allowed)

Just small

setAttr "defaultRenderGlobals.imageFormat" 20;

to set in render settings bmp format and thats it.

I hope this tip will be usefull for somebody. Good night.

CGTalk Moderation
11-25-2010, 02:13 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.