[Closed] Object ID?
I’m sure this is a stupid question, but how do you differentiate in Maxscript between two or more objects that have the same name and identical properties (like two cubes named $Box01 with the same dimensions, color, TM, etc)? Is there some type of unique “object ID” for each object in the scene, or even some way to determine when an object was created?
Thanks a lot for the help; I’ve been combing through the user reference and must be overlooking it.
$.INode.handle
--or
$.handle
--related method
maxOps.getNodeByHandle id
It returns a unique handle to the object, based on (I think) creation order. You should not rely to heavily on them because I think there where some cases where a handle could be changed, but maybe someone can comment on that. It’s fine using them for a search function or to find unique objects when everything else is the same, like in your case.
-Johan
In MAX 2008 and up there’s also the AnimHandle System.
GetHandleByAnim <object> –To get the handle from the object
GetAnimByHandle <integer> –To get the object from the handle
If you merge an object into a scene the ID is updated so you can’t rely on the ID being the same from scene to scene for any given object.
If you want to be more certain about the objects being unique (even when merging, etc.), set up an ID on the thing manually:
callbacks.addscript #nodeCreated "o = callbacks.notificationParam(); setAppData o 999 ((genClassID returnValue:true) as string)" id:#nodeUID
OK
newObj = sphere()
$Sphere:Sphere01 @ [0.000000,0.000000,0.000000]
getAppData newObj 999
"#(2014781007, -924657808)"
anotherNewObj = sphere()
$Sphere:Sphere02 @ [0.000000,0.000000,0.000000]
getAppData anotherNewObj 999
"#(1324664872, -1825936639)"
I’m using the general event callback here, but the node event system would work just as well (except that you have to specify an external function which adds a dependency). Similarly, you could use whatever routine you’d prefer to generate the actual ID… genClassID() essentially just returns two random signed integers which ‘should be enough’.