NickB Posted January 8, 2007 Share Posted January 8, 2007 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 Quote Link to comment
Petri Posted January 9, 2007 Share Posted January 9, 2007 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. Quote Link to comment
NickB Posted January 9, 2007 Author Share Posted January 9, 2007 Thanks Petri, that sounds like it should let me do what I'm trying to do. I'll give it a crack this weekend. Cheers, Nick. Quote Link to comment
Petri Posted January 9, 2007 Share Posted January 9, 2007 (edited) 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 January 9, 2007 by Petri Quote Link to comment
Petri Posted January 9, 2007 Share Posted January 9, 2007 (edited) 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 January 9, 2007 by Petri Quote Link to comment
islandmon Posted January 9, 2007 Share Posted January 9, 2007 Petri, Excellent tutorial ! thx Quote Link to comment
Petri Posted January 10, 2007 Share Posted January 10, 2007 What is in a name... For some reason, I've needed to use names in my scripts a lot. AddAssociation by the way works fine without names, ResetObject (which is used as the pipeline between associated objects) definitely does need the names. Quote Link to comment
Recommended Posts
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.