PDA

View Full Version : how do you obtain the last selection in an array?


Geuse
03-11-2009, 01:44 AM
I want to create a script for moving an object or a bunch of objects to another object's positon.
But instead of using an array where [0] is the target object I want the last number selected in the array to be the target. It makes it more intuitive imo. Like creating a locator and then having it selected you can just shift select another object and hit a shelf button instead of having to go into the outliner and select them, or pan around in the world to find them.

I read someone who wanted to reverse an array so the last object selected gets [0] instead. This ought to work for my purpose also, but if you have a better way, please share.

EDIT: Found the post here http://forums.cgsociety.org/showthread.php?f=89&t=693140&highlight=array

greatPumpkin
03-11-2009, 06:30 AM
you can also grab the last item without manipulating the array by
string $myarray[] = {"first","second","third","last"};

string $lastOne = $myarray[`size $myarray`-1]

you ask for the size of the array on the fly and minus one since it starts from zero.

Geuse
03-11-2009, 09:45 AM
Ah, I've seen the size command before and how people use it. Feel so stupid I couldn't think of that.

Thank you very much! very, very grateful.

CGTalk Moderation
03-11-2009, 09:45 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.