Jump to content
Developer Wiki and Function Reference Links ×

How to give objects an identifier?


NickB

Recommended Posts

Hi all, I'm pretty new to this Scripting lark, but I'm trying to give it my best shot. I've just about got my head round the idea of 'handles' and 'arrays', but essentially what I want to do is create a series of objects - each with it's own serial number - so that later I can query the objects for their properties (e.g. position).

How can I do this?

Sorry if this is an obvious question, but I haven't found the answer yet.

I'm reading a book with some Maya scripting in it, and in that an object can be assigned a name when it is created.Essentially this is what I am trying to do.

Thanks for any thoughts,

Nick

Link to comment

SETNAME(obHd, serial_as_string); { object that already exists }

or

NAMEOBJECT(serial_as_string); { object to be created }

To have a unique serial, you might first find out the number of names with

NAMENUM;

then use that+1 as the name (or part of it).

For arbitrary names you have to check that the naming has been successful: IF GETNAME(obHd)='none' THEN it_has_failed

Namespace is shared between object, symbols, classes, hatches and so on; in fact everything but layers.

Link to comment

Nick, you'll find some interesting pitfalls and possible user errors in no time at all...

1. Automatic creation of names works one way for new objects (ISNEWCUSTOMOBJECT returns TRUE) and differently with copies of existing objects.

2. Names are not persistent, ie. users can change them at will.

3. Names tend to disappear when objects are copied from file to file: something in the receiving end already has the name.

4. PIOs used in symbols are another problem (includes "red" symbols).

And so on. If you come up with a bullet- and idiot-proof naming scheme, I'd like to hear about it; it could be something b-dy obvious that I've just missed.

EDIT Underlined words had gone AWOL

Edited by Petri
Link to comment

The new

FUNCTION AddAssociation(ioOwnerObj :HANDLE; inKind :INTEGER; ioTargetObj :HANDLE) :BOOLEAN;

needs object names to handle handles (!), too, so a water-, bullet- and idiot-proof system would be needed!

Just to theorize:

- using filename, a random number and NAMENUM+1 would certainly reduce the likelihood of duplicate names to almost nil

- a text file for each object (PIO) could store the last serial# used for the particular PIO - but this would fail in copy/paste & WGR when the files are created by different users, so we'd need the file name too, I think

- storing the name also in a hidden parameter field might be enough persistence?

Edited by Petri
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...