View Full Version : selection event!!
11-02-2005, 05:57 PM
i'd like to know the command that can check if an object is selected or not to use it in the expression editor, as an event trigger, or.......how can i link a mel script to any attribute...for exemple, i added an attribute with boolean content, so if it is set to true, it execute one script(ex: select -r cube1), else, it executes another script.
thank you very much.
11-02-2005, 09:54 PM
I'm not sure if this is exactly what you are looking for, but to grab a list of everything selected, use 'ls -selection'. For instance,
string $selectionSet = `ls -selection`;
//for everything in the selection set, print it out
for($i = 0; $i < size($selectionSet); $i++)
print($selectionSet[$i] + "\n");
Notice that this returns everything selected - an array of all the names selected; You may just want to grab the first item selected - $selectionSet - or only operate if one and only one object is selected:
if(size($selectionSet) == 1)
/*Do stuff with $selectionSet*/
11-02-2005, 10:07 PM
thanks EigenPuff! it works perfectly, but how can i always evaluate it? put it in the expression editor? or there is another mel command!!!
11-02-2005, 10:35 PM
i think the scriptjob-command is what you're looking for.
here a little example from the documentation:
// create a job that deletes things when they are seleted
int $jobNum = `scriptJob -ct "SomethingSelected" "delete" -protected`;
with the Flag -attributeChange (-ac) you can run a script everytime a attribute is changed.
but remember that these scriptjobs will slow down your maya and won't work while you play back your scene.
i hope this was helpful!
11-05-2005, 07:57 PM
thank you Starrider! it was really what i was looking for :thumbsup:....
i used it to parent constraint some cubes to any null when it's selected depending on the position of the cubes!, simple ex: we have two nulls -5 0 0 and 5 0 0 and depending on the null selected, we check the X position of all the cubes to see which one should be parent constrained to the current selection, after then, we animate the rotation of the null, so the cubes parented will rotate as well, then we select another null to have its cubes parented to it and we animate it too, its cubes will follow of course, but!....the animation of the cubes that was parented to the first null and then parented to the second had lost thier animation! because they weren't keyframed just thier old parent!........so my question is: how to add a keyframe to an attribute!!! so i will add keyframe in the parent constraint node when the null is selected.......i hope i was clear! :rolleyes:...it was a little chinese :blush:
11-05-2005, 07:57 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.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.