PDA

View Full Version : Telling the difference between same-named objects?


noouch
01-26-2009, 02:54 PM
I've made a script that saves the names of objects and their corresponding materials to a file to apply to the updated version of a scene. This works fine as long as every object has its own individual name and is never renamed. Problems arise when some objects are renamed, or when identically named objects appear in the scene.

So I'm wondering, is there some sort of ID or something that is attached to an object in addition to the name to make it individual in the scene that I can use to select objects instead of using the name?

Jon-Huhn
01-26-2009, 03:12 PM
You can try .handle, but keep in mind that this ID allocation is dynamic at the time of creation, so if you were to import an object with a given .handle ID into another scene, chances are it would be assigned a different ID at that point.

MatanH
01-26-2009, 03:12 PM
Here is a simple solution that should work.

select(for o in objects where o.name == "Teapot01" collect o)[1]

this code will run through all objects in the scene in the order of their creation and collect all objects named "Teapot01", then it will select the first one
In the same way you can access the 2nd one, the 3rd and so on..

noouch
01-26-2009, 04:05 PM
Thanks, handle seems to be exactly what I was looking for.

JHaywood
01-26-2009, 05:54 PM
You can also us the AnimHandle System introduced in Max 2008, if you're using that version or higher. It's supposed to be more reliable than using the .handle property of an object, although I haven't personally done any kind of comparison.

This is from the help docs...



AnimHandle System

The AnimHandle system defines a unique ID number for every entity in the scene, including nodes, modifiers, materials, controllers, etc. When an entity is deleted from memory, its number will never be reused by any entity created later, except in the case of the so-called "wrap-around" - an unhealthy condition possible only when four billion entities (the 32-bit limit) are created in a single 3ds Max session.

Therefore you can determine whether an object is deleted by requesting the object using its handle, and seeing if the result is undefined.

Available in 3ds Max 2008 and higher.

Methods:

<integer>GetHandleByAnim <object>

This method returns the unique AnimHandle ID for the given scene entity.



<object>GetAnimByHandle <integer>

This method returns the scene entity corresponding to the unique AnimHandle ID, or undefined if the entity has been deleted or has not been created yet.



FOR EXAMPLE:



x = teapot()--create a teapot

xHandle = GetHandleByAnim x --get the anim.handle

x_verify = GetAnimByHandle xhandle --get by anim.handle

x == x_verify --compare the two - returns true

delete x--delete the teapot

clearUndoBuffer() --object deleted completely from memory

x_verify = GetAnimByHandle xhandle --now returns undefined

CGTalk Moderation
01-26-2009, 05:54 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.