PDA

View Full Version : Q: instances in scene


Leionaaad
08-14-2008, 12:28 PM
Imagine: I have a selection. wich will get a modifier applied. If any of the object is instanced, the modifier gets applied as many instances they are. right?
So...how can I deselect objects wich are instances and having only one instanced object selected?
Thank you.

TzMtN
08-14-2008, 12:55 PM
Here is a quick test for you:


(
local selArr = for o in selection collect o

for i in selArr do (
local objRefNodes = for r in (refs.dependents i.baseObject) where isValidNode r and r != i collect r
if objRefNodes.count > 0 then (
for o in objRefNodes do (
local n = findItem selArr o
if n > 0 then deleteItem selArr n
)
)
)

select selArr
)


I used the 'refs.dependents' function to find instances of the base object
and removed them from the selection.

Leionaaad
08-14-2008, 05:49 PM
thanks man, works just fine, pitty I can understand only half of it..

thatoneguy
08-14-2008, 06:15 PM
Just a quick performance question.

You use if > 0 and I use != 0. Is one or the other faster or less memory intensive?

I imagine it's marginal one way or the other. Just curious.

JHaywood
08-14-2008, 06:24 PM
Just a quick performance question.

You use if > 0 and I use != 0. Is one or the other faster or less memory intensive?

I imagine it's marginal one way or the other. Just curious.


I was just wondering that myself yesterday.

ZeBoxx2
08-15-2008, 12:24 AM
it is marginal - memory-wise it didn't make any difference, speed-wise... for 10,000,000 iterations of random numbers between 0 and 100 (only positives), seeded the same for both runs:
> -- 23744ms
!= -- 23234ms

As for which to use... I seem to use them mixed based on the function.. findItem, (getFiles <filespec>).count and that sort of thing, looks like I use "!= 0"... whereas other things, like <array>.count, I use "> 0". In general it seems I use "> 0" when the value of N later matters in the code - which, for findItem and getFiles, tend not to be the case; getFiles I use mostly to check if a particular file exists or not (doesFileExist isn't supported in all max versions we support). Perhaps there's a more sane systematic approach, but as long as the code does what it's supposed to.. given the negligible speed difference..

thatoneguy
08-15-2008, 04:36 AM
Same here.

If I'm checking to see if it found something (finditem) I use !=. If I'm counting array items I use > 0.

Which doesn't really make any semantic difference... I guess it's just bizzaro subconscious motivations.

I guess I view a search with no results as a failure and a count of 0 as a possible and normal scenario?

CGTalk Moderation
08-15-2008, 04:36 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.