Notifications
Clear all

[Closed] Q: instances in scene

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.

6 Replies

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.

thanks man, works just fine, pitty I can understand only half of it…

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.

1 Reply
(@jhaywood)
Joined: 11 months ago

Posts: 0

I was just wondering that myself yesterday.

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…

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?