PDA

View Full Version : scriptJob Button help


FunkyT
04-11-2006, 12:34 AM
Greetings all,

I'm trying to pretty much make selection of one object select another using a scriptJob. For instance, you have a cube and a sphere in a scene, if you click on the cube, it automatically runs a select -r to select the sphere. I'm sure this is easier than I can figure out. but what I have right now is:

scriptJob -event "SelectionChanged" "select -r sphere";

which works for if you change a selection, what'd I really like is something that does that but for a specific selection, and not a just a general selection change. Is there some way to create your own event that represents "select -r cube" or something? Any help from you MEL gurus would be much appreciated.

RyanT
04-11-2006, 12:53 AM
Changing the selection when someone selects something seems slightly odd to me but, here you go:

//Create your script job but have it call a proc (function) instead of executing a command
//You should also put the script job into a variable so you can kill it later
int $theJob = `scriptJob -event "SelectionChanged" "CGTselSphere"`;

//In this case I have the scriptJob calling CGTselSphere
global proc CGTselSphere()
{
//This gets your current selection
string $getSelection[] = `ls -sl`;

//This loops through all the nodes in the selection
for($node in $getSelection)
{
//If the nodes name is pCube1 then select pSphere1
if($node == "pCube1")
{
select -r pSphere1;
}
//You can also use a switch statement
switch ($node)
{
case "pSphere1":
select -r "pCube1"
case "pCube1":
select -r "pSphere1"
}
//Be carefull with scriptjobs they run ALL the time
//To get rid of them you have to kill them with `scriptJob -kill $theJob -force`;
}
}


-RyanT

CGTalk Moderation
04-11-2006, 12:53 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.