简体   繁体   中英

Save Python class instance as Maya scene object

In my scene I have an instance of my Python class Base() which is essentially a container for rig modules to be added to my character rig. When an instance of Base is created my script stores it under a variable called rigBase. The Base() class has groups for storing different rig components ex. rigBase.jointGrp rigBase.ctrlGrp. This lets me organize rig modules into the Base by passing the rigBase variable to the build function of each module. The problem is that this variable is stored in memory and not in the actual scene so when I save and load the scene the variable is lost and new modules don't have access to the instance of Base().

My question is, how can I store the variable rigBase in my scene so that when I save/load the file my script is able to recognize the previously created group nodes as an instance of Base()?

I may be possible to convert an instance of a class to a binary or ascii writable format, but I suppose that's not a good way to save data. I suggest to check which data you really need to know and try to serialize only that data it with json or pickle. Then you can attach this data to any maya node or save it as seperate file. Then if the scene is loaded, these infos can be loaded and converted back and attached to a new Base instance.

You can save as a json even in a maya attribute. You can manage to save data with script node so each time you open/close your maya, it will perform something

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM