PDA

View Full Version : Determining whether an object is an instance?


scorpion007
06-15-2007, 08:10 AM
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

JHN
06-15-2007, 08:40 AM
Yes there is, lookup "Interface: InstanceMgr" in the maxscript manual.

InstanceMgr.GetInstances obj &instances

Goodluck!
-Johan

scorpion007
06-15-2007, 12:40 PM
Thank you, will look into it :)

j-man
06-15-2007, 05:42 PM
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.

scorpion007
06-16-2007, 01:43 AM
Ah, thank you very much for your further insight :)

scorpion007
06-18-2007, 03:54 AM
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
06-18-2007, 08:40 AM
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

CGTalk Moderation
06-18-2007, 08:40 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.