[Closed] Finding Unique object with ID?
Is there any way to get an object id?
The way I normally find objects in the scene is by the name. However this doesn’t work if you have objects which identical names.
Example scene:
$Box
$Box
$Box
Now, If I write $Box what box will I actually select?
Ideally I would like to be able to write something like
objectID=$Box.id
select ObjectID –selects the box in the line above
Is this possible? I remember that the ids exist in c++ sdk
/Andreas
There’s two methods… this one has existed for a long time:
myHandle = $.inode.handle -- returns a node handle, integer
myNode = maxOps.getNodeByHandle myHandle -- returns the node given the handle
But if you plan on doing any merging, x-ref’ing, etc. this method is unsafe, as the handle changes.
And this one is ‘new’ and applies to non-nodes as well (materials, controllers, etc.)
myHandle = getHandleByAnim $
myNode = getAnimByHandle myHandle
[strike]I’d imagine the same problem applies to this system, but I haven’t tested :)[/strike]
UNGHk… nevermind that last one; the handles there change even when you load the same scene – woop
So your best bets if you really want a plausibly-unique way to identify your objects would be…
A. a scripted plugin or custom atrribute block with a nodeTab or maxwrapperTab in which you can drop the objects
B. a persistent global variable that points to the appropriate object(s)
C. setting a ‘unique’ ID on the object somewhere… for example in user properties, or appData; and then iterating over the scene to find them again.
D. <Insert further options here>
Edit: – > =, ‘’ > =. eek.
Thanks man! Very good reply.
Setting user properties works, but is slow cpu wize and is quite tedious.
I think I will try the node.handle. Seems like it should work. I’m not dealing with any merges as far as I know
Trying it out now!
/Andreas
We beat modelers with bad naming conventions… ohhh… did I just write that?
There’s also the UniqueName if you can torerate numbers on the end of your names, then collect with a $‘Box*’
If you want to personally manage them, then Appdata is probably best… It’s lightning fast.
I’ve used bit.IntToHex and bit.HexToInt to reduce the data amount I’m storing on the object to just four characters per node. AppData only stores string data.
Hehe, well this is for characters and their bones dont have unique names so I can’t really blame the artists here
/Andreas
and make sure to use <node>.inode.handle ; as there are some objects (I’m looking at you, teapot) that have a .handle parameter of their own
but… bones do have unique names! L Tibia!
That said – given how much of max relies on unique names for a lot of things, it’s always baffled me that it doesn’t enforce this… even if it’s just a cosmetic enforcement that could be toggled off in the preferences.
Actually… one could script this…
runs
Really? All the bones I see have non-unique names.
Yea you are right. It’s strange, maybe there is a reason, maybe. Personally I like when they just index the names. We are building our own super big editor and I spent quite some time making sure that all the names are unique. Can be a bit of a pain though, you can model several people at one scene and then it can be tricky to make sure everything is unique…
/Andreas
Well, reall world bones, at least
http://en.wikipedia.org/wiki/List_of_bones_of_the_human_skeleton
( prepend with L or R where appropriate )
I find myself using custom attributes, like Richard was saying. Pump in a tag to identify your objects, like “myTag”. Then when you want to retrieve it:
for o in objects where (isProperty o.baseObject #myTag) == true do voodoo
Been working good so far
Just about every thing that I build gets put into a maxObjectTab in a container modifier so I can seach the maxObjectTab for what I’m looking for. All I need to do is collect all the modifiers with (getClassInstances myContainerMod) and then iterate through all the parts for each group of objects in the tab. The container will have a name property as well that I can check for as well as a unique ID to match it agaist. Yep, I’ve worked with those modelers as well;)
It’s a bit much to manage, but all of our rigged people have names. So we can just say I want to see Robert and Sally walking across the balcony. We don’t have any hero 3D people, green screen for anything over 3-5% of the screen. Their rig naming corresponds to the person… We haven’t gotten to last names yet, but some of them are pretty funny…if you’ve lotsa people you need to name, there are some pretty interesting random name generation website out there…