jonlauf
02-14-2007, 04:57 PM
selectArray = for i in selection where superclassof i != light collect i
select selectArray
namoi
02-14-2007, 05:24 PM
Thanks, that do the trick
But i still wondder why the others code didn't work...mostly because of the deselect() i used, but i don't know why.
jonlauf
02-14-2007, 07:35 PM
It's not deselect, it's because the seletion array changes thru each iteration of the loop, it works if you collect the elements in a seperate array then run the code:
newArray = for i in selection collect i
for i in newArray where superclassof i == light do deselect i
shibumenon
02-14-2007, 08:28 PM
hmmm .. quite an interesting one this is !
And I guess, this is the right situation to evaluate the difference between
selection and selection as array
'selection' is kind of dynamic, so if I say
var1 = selection
then, var1 becomes a dynamic array, and it'll always contain nodes that are currently
selected
but if you say var1 = selection as array
then var1 will always contain the same nodes which were selected when you executed
the line.
To understand why this happens, you could try this :
An fresh, empty scene, make 3 nodes : a sphere, and 2 omni lights
Now type the same code that you started with ... ie
for i in selection where superclassof i == light do deselect i
CASE 1 : you select omni1, sphere, omni2 .... (in this order) and evaluate your script
for loop 1st iteration : omni1, sphere, omni2
checks the 1st element, (omni1) ..... expression true, so deselects it
for loop 2nd iteration : sphere, omni2
checks the 2nd element, (omni2) ..... expression true, so deselects it
for loop 3rd iteration : sphere
ideally, the for loop doesn't have a 3rd element this time to check,
so doesn't evaluate the where expression.
But since the object remaining in the selection is a sphere, your purpose is solved.
--------------------------------------------------------------------------------
CASE 2 : you select sphere, omni1, omni2 ... (in this order) and evaluate your script
for loop 1st iteration : sphere, omni1, omni2
checks the 1st element, (sphere) ..... expression false, so doesn't deselect anything
for loop 2nd iteration : sphere, omni1, omni2
checks the 2nd element (omni1) ..... expression true, so deselects it
for loop 3rd iteration : sphere, omni2
no 3rd element to check, so you are left with a sphere and omni selected in scene,
though omni2 is a light !
--------------------------------------------------------------------------------hmmm
... I have to run it multiple times to achive the result. I've tried it directly in the listener with 3 spheres and some lights and the first time i run it it deselects some lights, the 2nd time its deselects some other lights ans so on...
So the different results that you obtained should be because of the order of selection,
where the selection keeps dynamically changing.
But instead of 'selection' , if you use selection as array, you will surely get the result that you were looking for.
for i in (selection as array) where superclassof i == light do deselect i
namoi
02-14-2007, 08:36 PM
The demonstration is obvious...
Thanks we learn every day here !
CGTalk Moderation
02-14-2007, 08:37 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-2013, Jelsoft Enterprises Ltd.