View Full Version : How do I reselect my objects with lscript

02-15-2003, 09:07 PM
In the code below, I used a for loop to set a bunch of properties...However I now want to reselect the same objects when I exit the script....any help would be appriciated

scene = Scene();
Objs = scene.getSelect();

for (i=1;i<10;i++)
ran = random(1,10);

//................Now how do I reselect the Objs again ? ...............

Tom Winnicki
02-16-2003, 01:01 AM
Take a look at "Test_184_my_select_02.ls" located here: http://www3.sympatico.ca/tom.winnicki/Programming/LScript/Examples_Layout/

This script contains selecting utility functions (and supporting functions) which I wrote mainly for my undo-redo scrit because of a few quirks in Layout, namely the SelectByName() bug. If that code 'scares' you, then you may just do this:

for(a = Objs.size(); a > 0; a--)
if(a == Objs.size())

Note that the loop traverses the Objs[] array backwards, that's because Layout (not LScript) returns the selected items in reverse, i.e. the last selected (or the current) item is in Objs[1]. In other words if you selected item A, then added to selection item B and then C then Objs[1] = C's OA, Objs[2] = B's OA and Objs[3] = A's OA. In layout C would be the currently selected item. When the loop reselects items it starts with Objs[3] - selects A, then adds to selection Objs[2] - B and lastly Objs[1] - C so that C being added to selection last is again the currently selected item. If that loop above was running forward then the selection would be restored backward, that is, after it finished, A would be the current item not C. Of course, if you don't care about the order of the reselected items but only that the same items are reselected then you may traverse the Objs[] array forward.