/* selectTrigger v01 http://zoomy.net/2010/12/23/selecttrigger-v01/ Select a control object followed by one or more target objects, then run this script. A scriptNode will be created which creates and tracks a scriptJob. The scriptJob checks selected objects, and if the control object is first in the selection list, the target objects will be selected as well. Since scriptJobs only last until the scene is closed, the scriptNode also re-creates the scriptJob when the scene is reopened. */ string $sel[] = `ls -sl`; if (size($sel) < 2) { print "selectTrigger: Select two or more objects."; } else { int $size = `size($sel)`; string $node = `scriptNode -n "scriptNode"`; addAttr -longName selection -dt "stringArray" $node; string $items = stringArrayToString($sel, "\" \""); $items = " \""+$items+"\" "; string $cmd = "setAttr "+$node+".selection -type stringArray "+$size+" " + $items ; eval $cmd; $items = stringArrayToString($sel, "\\\\\\\", \\\\\\\""); $items = "\\\\\\\""+$items+"\\\\\\\""; string $procInit = "global proc reactToSelection(string $args[]) { string $a = $args[0]; string $b[]; for ($i = 1; $i < size($args); $i++) { $b[size($b)] = $args[$i]; } string $why = `undoInfo -q -undoName`; if ( `gmatch $why \"select*\"` ) { string $sel[] = `ls -sl`; int $hasA = stringArrayCount( $a, $sel ); if ( $hasA ) { $sel = stringArrayCatenate( $b, $sel ); select -r $sel; } } }"; string $attrInit = "$cmd = \"scriptJob -kws -event \\\"SelectionChanged\\\" \\\"reactToSelection({"+ $items + "})\\\"\";int $jobNum = `eval $cmd`;setAttr(\"" + $node + ".jobID\", $jobNum);"; string $before = $procInit + "select " + $node + ".selection;" + $attrInit + "print(\"Created node: "+$node+"\");"; string $after = "print(\"deleted job # \" + `getAttr(\"" + $node + ".jobID\")`);scriptJob -kill `getAttr(\"" + $node + ".jobID\")`;"; addAttr -longName "jobID" -at long $node; scriptNode -e -st 2 -bs $before $node; scriptNode -e -st 2 -as $after -ea $node; scriptNode -executeBefore $node; }