PDA

View Full Version : How to execute a MEL Script when selecting a node?


Go!Raiders
02-17-2003, 06:04 AM
Hi,

I am trying to bring up a custom UI when I select an object. How do I set up a MEL script that executes when I select that object?

Thanx for any help.

stunndman
02-17-2003, 06:41 AM
take a look at the mel command scriptJob - with this command you can attach your procedures to various events

mark_wilkins
02-17-2003, 07:25 AM
Though you can do what you describe with a scriptJob, I'd ask whether bringing up a UI *EVERY* time you select an object is really what you want to do.

A clever thing that my colleague (and contributor to our book) Stephan Osterburg came up with was a way to build a custom marking menu for the object under the cursor. Since lots of things in Maya make you select objects and you may not want to ALWAYS bring up the UI, something like this might be a better design choice.

(I can't quite remember how he did this, but it involved adding some kind of hook into a custom version of one of the Maya-shipped MEL files that set up the interface. He'd proposed making it an example in our book but it seemed just a little too rough-and-ready an approach to fit what we were trying to do...)

Just a thought...

-- Mark

Go!Raiders
02-17-2003, 08:21 AM
ARGH! To bad you did not include that in your book. I was looking in your book before I posted my question here. Thanx for pointing me in the right direction.

So, I set up a scriptJob that waits for a selection condition to became True and than it checks what has been selected and preforms an action based on what is selected?

mark_wilkins
02-17-2003, 08:24 AM
Yes, that's how you do it.

So what are you doing exactly? Building control objects for a character rig or something like that?

-- Mark

Go!Raiders
02-17-2003, 04:32 PM
That is exactly what I am doing. Once my rig is done and ready for animation, I want to be able to select the controller for the head and have a UI pop up with predefined mouth shapes, or when I select the controller for the wrist a UI pops up with sliders to control the fingers and the shoulder.

How do you check the status of an object, to see if it is selected?

Thanx for all your help.

alexx
02-17-2003, 06:09 PM
check the documentation for the script job..

the "select" is just a state that you can trigger your script to..
it gets triggered whenever you select ANYthing..

what you need to do then is have a condition which checks, which object got selected.
if it is none that you want, you just break execution and if it is one of your controller objects you build up the UI..

right here comes a question to my mind:

- how can you query the mouse position in mel to pop up the window there?
i have been looking for that one for quite a long time..

cheers

alexx

wrend
02-17-2003, 06:42 PM
- how can you query the mouse position in mel to pop up the window there?
i have been looking for that one for quite a long time..


draggerCtx, or perhaps autoPlace :)

alexx
02-17-2003, 07:06 PM
cant they simply call it "mouseX and mouseY" or something..
bummers :)

thanx

alexx

Go!Raiders
02-17-2003, 07:51 PM
Well, that was my second question. How do I check that "headLocator" is in a selected state once the scriptJob gets triggered by any selection.


Originally posted by alexx


what you need to do then is have a condition which checks, which object got selected.
if it is none that you want, you just break execution and if it is one of your controller objects you build up the UI..


alexx

mark_wilkins
02-17-2003, 09:07 PM
Well, that was my second question. How do I check that "headLocator" is in a selected state once the scriptJob gets triggered by any selection.

string $locSelected = `ls -sl "headLocator"`;

If anything comes back in the $locSelected variable, you have a winner.

-- Mark

CGTalk Moderation
01-14-2006, 10:00 AM
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.