Indeed there is:  Python comes with the cPickle module, that lets you 
serialize any builtin Python data to disk.  It has a dump method that does 
that writing to your filesystem, but it also had a dumps (dump string) that 
writes it as a string.

In Maya, you can make string attrs on your nodes...

pseudo code, not directly tested but you get the idea

import cPickle

data = {"a":1, "b":2}
stringData = cPickle.dumps(data)

# Add a custom string attr to your node and:
mc.setAttr("myObj.stringAttr", stringData, type='string')

# Then later to query it:
stringAttrData = str(mc.getAttr("myObj.stringAttr"))
loadedData = cPickle.loads(stringAttrData)

print loadedData
{"a":1, "b":2}

I do this *all* the time to just get away from having to deal with Maya's 
own attr types.  So much more flexibility in data storage on Maya nodes.

You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
To view this discussion on the web visit
For more options, visit

Reply via email to