ScriptSpot home

Forum topic · General Scripting

handles

By gramx · 2010-12-22

Description

Hi I am trying to select an object by it unique handle. I can find out what the handle is (see below) what I dont know is how to select the object via its handle. Can anyone help?

$.handle (Returns the unique id associated with the node)

Thanks

Gram

Comments (14)
gramx

Thanks, the hasProperty() function will fix it!

Graph

the hasproperty function should help to filter the ones out that dont have it. or isProperty dunno wich one it was for CAs

Garp

About identifying through handle IDs, using the appropriate method:

select (maxOps.getNodeByHandle 3) --for selection
obj = maxOps.getNodeByHandle 3 --for assignment
Reply to Garp
gramx

Thanks, trying to use custom handles rather than the handle function built into max. Allthough all objects get a unique handle if you merge objects into another scenes then the handle IDs can change. :(

gramx

selecting object via custom ID

Hi

I have used the following code to add an ID to an object:-

local DataCA = attributes data ; (parameters main;(myNewID type:#integer default:2 animatable:false;))
custAttributes.add $ DataCA

I then select the object with the following code:-

for obj in $* where obj.myNewID == 2 do select obj

If I have any objects in the scene that dont have this extra attribute I get the following error:-

-- Error occurred in obj loop
-- Frame:
-- obj: $Box01
-- Unknown property: "myNewID" in blabla

How would I get around this?

Thanks

Gram

Graph

Scripted Custom attributes are what you might want to look into


local DataCA = attributes data ; (parameters main;(myNewID type:#integer default:2 animatable:false;))
custAttributes.add $ DataCA
Panayot Karabakalov

same result without collecting

for obj in $* where obj.handle == 2 do select obj

Thanks Anubis, that makes sense. Is it possible to add your own hidden handels to objects? such as an ID tag. The .handle works ok but if you merge it into another scene then the handle number changes.

Ta

G

Reply to gramx
gramx

User Defined properties

Better idea? - instead of using tags I can give objects a tag_code in the User Defined Properties. This way if the object gets renamed I can still select it via the tag_code.

g

Reply to gramx
Panayot Karabakalov

check also setAppData

Yes, User Defined Properties are nice for that purpose.
Also can use setAppData function (check in the help).
While the UDP are only for scene objects, with setAppData can "stamp" any MAXWrapper_object - i.e. modifiers, materials, controllers ...

gramx

Great

I couldn't figure out the syntax, I am new to max script, many thanks!

g

Graph

select (for o in objects where o.handle == 2 collect o)[1]

just replace the 2 with the var holding the handle