I've just finished writing our own Tag class.  I don't think I can post the
code.  But I can outline the idea and our approach.
I'd like to hear anyone else's thought's on tagging data too.  Especially
people who have witten expanded this tagging idea to perhaps describe their
own scene graph of Maya data.  How you tackled synchronisation and call
backs.

Basically it writes an attribute, the contents of that attribute is a dict
written using json.  (Chad; couldn't get pickle to read pickled data back.
You can only pickle the __repr__ to a Maya attr.  I couldn't get that to
load back.)  The base `Tag` class has method's:

ToDict()
FromDict()
Read()
Write()
Save()
Load()

so on so forth:

Also every `Tag` has a UID property using pythons uuid.  From this UID I can
then construct the parent/child logic.

So now I have
SetParent()
GetParent()
IsParent()
IsChild()
etc

All relationships like this are handled with message connections as you
outlined.  Where the direction or the connection is searched for parent and
child `Tags`.  A child `Tag` has the parent/child UID stamped into it.

Using this `Tag` as base I've been able to save 100's of Pose's directly
onto a character in one HUGE json multi dimension dict stamped into an
attribute.  Maya seems to have no upper character limit that I've
encountered yet.  And no speed problems creating the attr with this huge
string.  Although we did try using multiple attrs and this did slow down the
UI.

It's also interesting to note.  Using json it is quite easy to do a basic
dump and load of you class.  In this pseudo code pnAttr is a
pymel.Attribute() instance

class A(object):
    def __inti__(self):
        self.a = None
    def Write(self):
         pnAttr.set(json.dumps(self.ToDict()))
    def Read(self):
         self.__dict__ = json.loads(pnAttr.get())

-Dave


On Wed, Jan 13, 2010 at 6:12 AM, John Patrick <[email protected]> wrote:

> Thanks Chad.  I guess I'm doing a little wishful thinking here.  If that
> unique id was easily accessible, this might work but without it I suppose
> messages are still the way to go.  Onward and upward...
>
> On Tue, Jan 12, 2010 at 9:30 PM, Chad Dombrova <[email protected]> wrote:
>
>> you could pickle to a string and then add that to a string attribute on
>> the node.  the advantage of .messages is that if a node is moved in the DAG
>> or renamed the connection remains, but pickled string data containing object
>> names will become invalid.  ( on a side note: houdini creates a unique id
>> for every node in every file for all time.  that's pretty handy.  i wish
>> that maya would do that natively, though there are ways of hacking it into
>> place.)
>>
>> -chad
>>
>>
>>
>> On Jan 12, 2010, at 9:10 PM, JP wrote:
>>
>> > Hi all,
>> >
>> > I'm currently working on a script that allows for space-switching
>> > between objects, and came across some general questions regarding data
>> > persistence.
>> >
>> > In short, I have a couple classes I've created that represent parents,
>> > children, etc, and was thinking about how to keep track of some of
>> > this data.  In the past, I've used the tried-and-true method of
>> > connecting .message attributes between objects and then checking for
>> > them later.  While this works, it's not terribly elegant, and when I
>> > start having a lot
>> > of data I want to keep track of, it becomes cumbersome to inspect all
>> > of those connections.
>> >
>> > I was wondering if anyone had experimented with creating file-like
>> > objects from script nodes (or other nodes) that would allow something
>> > like this:
>> >
>> > f = ScriptNodeFile("spaceSwitching", "r")
>> > f.write("Some line of text \n.")
>> > f.close()
>> >
>> > It would also be very very cool if you could pickle data to this
>> > ScriptNodeFile object!
>> >
>> > Obviously, pickling/saving an external file with this data would work,
>> > but I'm almost certain these would be quickly lost in our file
>> > system.  I think it would be very handy indeed to be able to store and
>> > recall data to a node within the scene file.  Just wondered if anyone
>> > out there had come across anything like this, or had any bright ideas
>> > that might help me with this sort of thing.
>> >
>> > Thanks!
>> > --
>> > http://groups.google.com/group/python_inside_maya
>>
>>
>> --
>>
>> http://groups.google.com/group/python_inside_maya
>>
>
>
>
> --
> John Patrick
> 404-242-2675
> [email protected]
> http://www.canyourigit.com
>
> --
> http://groups.google.com/group/python_inside_maya
>
-- 
http://groups.google.com/group/python_inside_maya

Reply via email to