ScriptSpot

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 · 2011-01-03

Thanks, the hasProperty() function will fix it!

Graph · 2011-01-03

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

Garp · 2011-01-02

About identifying through handle IDs, using the appropriate method:

select (maxOps.getNodeByHandle 3) --for selection
obj = maxOps.getNodeByHandle 3 --for assignment

gramx · 2011-01-03

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. :(

selecting object via custom ID

gramx · 2011-01-02

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 · 2010-12-23

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

gramx · 2010-12-23

Thanks Graph,

Thats going to help alot:)

g

same result without collecting

Anubis · 2010-12-22

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

gramx · 2010-12-23

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

User Defined properties

gramx · 2010-12-23

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

check also setAppData

Anubis · 2010-12-23

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 ...

AppData

gramx · 2010-12-24

Checked the Help it looks like I could use the AppData function to store IDs, Thanks.

Great

gramx · 2010-12-22

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

g

Graph · 2010-12-22

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

just replace the 2 with the var holding the handle