[Maya / Python] Best place to save scene-specific tool data?

Making a custom weight painting tool. Not sure where to save data related to the scene it is used in and it’s also per skincluster specific.

These are the methods I’ve used or know of:

[ul]
[li]Make an empty transform and add some attributes to that to store variables, but then it sits in plain sight and some newer user might delete it not knowing what it is, I could use lockNode but that doesn’t inform them much. I could make a script job that warns them when they delete it to give them the chance to undo but that’s not desirable either.
[/li][li]I could use a non-DAG node to help hide it, perhaps even put the attributes on a multiplyDivide or so forth so it isn’t in plain sight. Is there something more optimal here?
[/li][li]I could pickle the data to a file and store it somewhere that makes sense (in a subfolder of the scenes folder, maybe). Though I don’t believe this method is good for scene-specific data.
[/li][li]I’ve read into scriptNode a bit but it doesn’t really seem what I’m looking for, just bringing it up in case I’m missing something here.
[/li][li]A custom node would be ideal IF it didn’t have to be loaded as a plugin, so lets forget that.
[/li][/ul]

Those are the ideas I’ve had and I’m not sure any of them are ideal, advice appreciated.

You could store the data on the base node of whatever hierarchy the tool is working on. That places all of the data in one place, and if the artist deletes it, you don’t have garbage data floating around. Or use whichever node has the skin cluster on it?

You can also look at the fileInfo cmd, it lets you setup a simple key / value storage in the file header itself, kind of like optionVars but file specific.

For scene-wide data, fileInfo is the way to go. You can also use it to store binary data (like pickled Python objects,in cases where that makes sense) by encoding the binary data into a an ascii block and then decoding as needed: see http://stackoverflow.com/questions/34910494/maya-python-embed-zip-file-into-maya-file for an example (that one links back to a thread here :wink:

For data specific to a particular node custom attributes are better. If possible you want the nodes to be visible scene objects so it’s clear when you have data and the data you have matches the visible scenes. A lot of places uses scriptNodes as data stores for this sort of thing because you can trigger them to do setup or teardown tasks – which is fine on a one-off basis. However the problem with all node-data solutions is that artists constantly munge files together; expect to see many, many untracked copies of your invisible nodes accumulating over time unles you invest in cleaning them out.

1 Like

sounds like it’s node-specific data if it’s related to each skinCluster in the scene. if that is true, then I would create custom attributes on the skinClusters themselves to store the data.

Thanks guys, that helps so much!

I’ve been tossing up between attributes on the skinclusters and file info, but I often delete the skincluster and reapply it for whatever reason, particularly transferring changes which is why fileInfo was a good contender, but on second thought I’ll just pop a button in that copies the attributes between skin clusters.

I’m sure going to put fileInfo to good use in the scripts I make after as well. Cheers all.

1 Like