Notifications
Clear all

[Closed] Determining whether an object is an instance?

Hi,

When looping through geometry, is it possible to determine whether this object is an instance of another, so I don’t have to process it twice?

Thanks

6 Replies
 JHN

Yes there is, lookup “Interface: InstanceMgr” in the maxscript manual.

InstanceMgr.GetInstances obj &instances

Goodluck!
-Johan

Thank you, will look into it

here is a head start,

this will select all object instances of the selected objects.


 macroScript select_Instances
 	category:"JN Scripts"
 	toolTip:"Select Object Instances"
 	icon:#("MergeAnim",1)
 
 (
 -- Joshua Newman
 -- www.joshuanewman.net
 -- copyright 2005
 -- max 7, 8, 9
 	obj=selection as array
 	sel=#()
 	for s in obj do
 	(
 		InstanceMgr.getInstances s &a
 		join sel a
 	)
 	select sel
 )
 

also, read in the help about refs.dependants

Cheers,

J.

Ah, thank you very much for your further insight

Hmm… I wonder if it is possible to traverse objects in the scene such that every ‘instance’ is processed once. I.e. If I have 2 boxes, both which are instances of each other, I only want to process one of them in the loop.

For example if I try

for o in geometry do print o.name

I’ll get both Box01 and Box02. I only want one of them.

I know I can determine whether an object is ‘unique’ so to speak by checking whether the return value of InstanceMgr.GetInstances == 1.

I’ll think about this some more… Just wondering if I overlooked any simple way of doing this…

Thanks anyway.

  • Alex
 JHN

One way could be to make a multidimensional array based on instances, and only process the first element of each subarray… that way you will only proces an instance once.

Other way would be to check if an object is an instance and store it in an array, and check with each new processing object if it is an instance of the object in the array if not process else don’t.

Hope it helps you get started.
-Johan