PDA

View Full Version : !?! run a mel when i select an object !?!


Firas
07-30-2003, 04:20 PM
hi all..
am not sure if i can do that with mel.. but i need to exicute my MEL automaticly whenever i select Locator for example ..

can we do that ? please if we can .. just write a simple example ...

if we cannt do that .. thats mean i have to learn API inorder to finish my SMART_IK tool..


SMART_IK is developed to make the "pining joint" possible.. :wise:

GDC
07-30-2003, 05:27 PM
Here is one way to do this...
Create a scriptJob that runs on every selection change, which calls a procudure that checks the current selection and if it's of the right type act's upon it.

Here is a simple example:

global proc createSimpleScripJob()
{
global int $gSimpleScriptJobNum;
if(!$gSimpleScriptJobNum){
$gSimplEScriptJobNum=`scriptJob -protected -e "SelectionChanged" "checkSimpleSelection"`;
}
}

// make sure the script job starts!
createSimpleScriptJob;

global proc checkSimpleSelection()
{
string $sel[]=`ls -sl`;
if(size($sel)!=0){
// do stuff.....
}
}


I actually have something like running to catch the creation of all materials. Speed wise you can't tell it's running!

Hope that helps
--g

Firas
07-30-2003, 05:54 PM
thankx .. i'll try now.

Marcel
12-12-2003, 02:42 PM
The scriptjob works nice, but it would be nice to kill it when I close my scriptwindow.

I create a scriptjob with:

$mvSimplEScriptJobNum=`scriptJob - protected -e "SelectionChanged" "mv_refresh";

But somehow when I try to kill it with:

scriptJob -f -kill $mvSimpleScriptJobNum;

It starts complaining that it's a permanent scriptjob which can't be killed. I've also tried adding the -protected and -force flags to the creation and kill commands, but that didn't help much.

And another small question, is there a way to execute a command on 'window close'. Right now I have a special close button, but that isn't very slick :)

Doogie
12-12-2003, 03:36 PM
I use this so it kills the scriptjob when the scene closes.scriptJob -killWithScene

I know there's a command to close w/ GUI
**scans though recent memory**scriptJob -p WindowName // i believe

here's a link to another thread about it (including the standard warning given everytime scriptjobs are brought up):
http://www.cgtalk.com/showthread.php?s=&threadid=106548

-Paul

mhovland
12-12-2003, 03:43 PM
Originally posted by Marcel
...

It starts complaining that it's a permanent scriptjob which can't be killed. I've also tried adding the -protected and -force flags to the creation and kill commands, but that didn't help much.

And another small question, is there a way to execute a command on 'window close'. Right now I have a special close button, but that isn't very slick :) [/B]

Is there a reason you are making the scriptJob protected? Just remove the protected flag, and then you should be able to kill it with the code you have.

For the second question, you can parent the scriptJob to the window, that way when the window is destroyed, the job is killed with it.

ACFred
12-12-2003, 04:49 PM
There is a VERY useful Search feature on this site. This question has been asked MANY times already and the answers are quite often the same.
Just a friendly reminder for the next time you have a question. The best first course of action is to Search throughout the MEL forum.

Alec

Marcel
12-12-2003, 07:07 PM
Originally posted by ACFred
Just a friendly reminder for the next time you have a question. The best first course of action is to Search throughout the MEL forum.

I'm aware of the very usefull search function, how else do you think I found this thread? I've also searched on 'scriptjob' and 'permanent' but that didn't return any threads with the solution to my problem (killing the scriptjob that is 'permanent' for no apperent reason).

Originally posted by mhovland
Is there a reason you are making the scriptJob protected? Just remove the protected flag, and then you should be able to kill it with the code you have.

For the second question, you can parent the scriptJob to the window, that way when the window is destroyed, the job is killed with it.[/B]

I made the scriptjob with the usual parameters, but that didn't work, so I though it would work with the -protected/-force combination. No luck there. However, it does seem to work on another computer, so I must be doing something wrong.

I will try the parenting, it sounds very logical, thanks Mike and Doogie!

mhovland
12-12-2003, 07:45 PM
If you're interested here are code snippets of how I create and kill a scriptJob:

at the end of my UI declaration (which is in it's own proc) I have this:

int $sjNum = `scriptJob -e "SelectionChanged" "mhHSVscriptJob" -p mhHSVwin`;


And here is the scriptJob code:

global proc mhHSVscriptJob()
{
mhFixSat;
}


It is that small because all it is doing is making a call into my plugin command "mhFixSat".

Notice that I didn't include any code to kill the job, this is because I parented the job to my UI. Close the UI window using either the button in the interface or the "X" in the corner of the window, and the job goes bye-bye.

CGTalk Moderation
01-15-2006, 04:00 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.