Re: AddtoSelection scripting question

Date : Fri, 11 Jan 2008 14:59:59 -0500
To : XSI(at)Softimage.COM
From : "Ajit Menon" <xsiajit(at)gmail.com>
Subject : Re: AddtoSelection scripting question
Hi Joey
It's a weird script coz something it works without exception, sometimes it doesn't...
 
I logged the array contents initially and each container has the correct object in it. But occassionaly, the script breaks and says object 'undefined'. Sometimes it selects the right name, but still breaks...
 
I guess there is s'ting wrong because sometimes it works, sometimes it doesn't.
 
Bernard's suggestion to drop it into a collection might be the smart way to go (if my brain caught up to such 'technology'... lol).
 
But thanks for the feedback. Any new feedback would be welcome though... :)
Cheers!

 
On 1/11/08, Ponthieux, Joey <j.ponthieux(at)nasa.gov> wrote:
I need to add a correction to this.

If you have items 0-19, and remove item 4, your sample continues after
that point from 4-18 because everything shifts by 1 due to the deletion.


Joey Ponthieux
NCI Information Systems Inc.
NASA Langley Research Center
____________________________________________________________
Opinions stated here-in are strictly those of the author and
do not represent the opinions of NASA or any other party.



Ponthieux, Joey wrote:
> I'd agree with Bernard here, you'll probably find an XSICollection to
> be very useful as a placeholder for the original selection or for the
> items you want to keep.
>
> The problem is that you wanting to modify the Selection object.
> Everytime you select something via script or the interface the items
> become part of the Selection Object. Both SelectObj and AddToSelection
> modify the Selection Object and you ar eusing both.
>
> In your case your attempting to modify the Selection Object. For
> example you start by selecting  a large number of scene items, which
> are now present in Selection then you only want 20% of them to remain
> in Selection.
>
> You can't append the 20% remaining items to Selection because they are
> already there. If you don't want to use another collection to manage
> the original selection your best bet is to isolate the 20% you want to
> keep and remove the other 80% from the Selection Object.
>
> You can physically remove them one by one from the selection using
>
> Selection.Remove(Selection(index))
>
> Mind you this is complicated because each time you remove an item you
> reduce the length of Selection by 1
> so you must also compensate your iteration by 1.In other words if you
> have 20 items selected to start (0-19),and you know that you don't
> want item 4, you remove it by executing
>
> Selection.Remove(Selection(4))
>
> but now Selection only has items 0-18 because you removed one. This
> leaves items 5-18 left to sample and every time you delete another the
> length of Selection decreases by one. This means you have to modify
> you increment for your loop in order to stay ahead of the change in
> the Selection Objects length.  The process holds some dangers, though
> it is possible to do.
>
>
> The easiest way would be what Bernard suggested, to acquire the items
> you want to save into a collection.
>
> var oColl = XSIFactory.CreateActiveXObject("XSI.Collection");
> //define an XSI Collection
> populate the collection with the items you want to keep one at a time...
>
> oColl.Add("itemname");
> or
> oColl.Add(reference);
>
> then modify the selection all at once at the end
>
> SelectObj(oColl);
>
>
> If you have a list of everything you want to keep as a string you can
> reinit the Selection and replace
> everything all at once using:
>
> Selection.SetAsText("item,item,item,etc")
>
> but you must have the list first.
>
> Joey Ponthieux
> NCI Information Systems Inc.
> NASA Langley Research Center
> ____________________________________________________________
> Opinions stated here-in are strictly those of the author and
> do not represent the opinions of NASA or any other party.
>
>
>
> Bernard Lebel wrote:
>> I haven't read your script, but what you could do is copy the selected
>> objects into a collection, use that collection to get those random
>> objects, and then repopulate the Selection object with these objects.
>>
>>
>> Cheers
>> Bernard
>>
>>
>>
>> On Jan 11, 2008 11:37 AM, Ajit Menon < xsiajit(at)gmail.com> wrote:
>>
>>> I've attached the entire script.
>>> Basically u select any number of objects in your scene (any kind)
>>> and when
>>> you run it, enter a percentage value, say 20%.
>>> The script is supposed to generate unique random objects and select
>>> only 20%
>>> of the selected items.
>>>
>>> I made a small error when I sent in the original script... my loop
>>> actually
>>> runs from 1 to arrayLength coz I assumed that u have to do at least one
>>> SelectObject before I can use AddToSelection...
>>> correct me if I am wrong though.
>>>
>>> thanks again though!
>>>
>>>
>>>
>>>
>>>
>>> On 1/11/08, Ponthieux, Joey < j.ponthieux(at)nasa.gov> wrote:
>>>
>>>> Someone correct me if I'm wrong here but aren't you adding the same
>>>> object back to the Selection Object?
>>>>
>>>> When you use SelectObj it places whatever into Selection, in this case
>>>> it looks as though objArray[0] gets placed in Selection(0), but
>>>> without
>>>> knowing what the content of objArray is this could be questionable.
>>>>
>>>> Then you set up a loop, which starts at 0 and you attempt to iterate
>>>> through objArray ultimately adding
>>>> objArray[0] back into Selection where it already exists.
>>>>
>>>> Joey Ponthieux
>>>> NCI Information Systems Inc.
>>>> NASA Langley Research Center
>>>> ____________________________________________________________
>>>> Opinions stated here-in are strictly those of the author and
>>>> do not represent the opinions of NASA or any other party.
>>>>
>>>>
>>>>
>>>> Ajit Menon wrote:
>>>>
>>>>> Hi all
>>>>> I have a simple selection script which however every now and then
>>>>> gives me an error:
>>>>>
>>>>> // WARNING : 3030-SELE-AddToSelection - Command was cancelled.
>>>>>
>>>>> I have no idea why it's doing it coz it seems random. Here's that
>>>>> part
>>>>> of the script:
>>>>>
>>>>>
>>>>> SelectObj(objArray[0], null, true);
>>>>>
>>>>> for (s=0;s<arrayLength;s++)
>>>>> {
>>>>>
>>>>> // logmessage("Selected Array index is :"+sel);
>>>>> // logmessage("Selected Object is :"+objArray[sel]);
>>>>> AddToSelection (objArray[s], null, true);
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> Thanks in advance
>>>>> Ajit
>>>>>
>>>> ---
>>>> Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text
>>>> in body:
>>>> unsubscribe xsi
>>>>
>>>>
>>>
>> ---
>> Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in
>> body:
>> unsubscribe xsi
>>
> ---
> Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in
> body:
> unsubscribe xsi
---
Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
unsubscribe xsi


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.