Using Custom Objects for persistency
When writing plugins, one is often faced with the need of storing parameters. Of course, this can be done in some memory area inside the plugin, but what about if we also want to have persistency (i.e having the parameters saved in between sessions) ?
A good example would be a plugin storing information needed to view or render a scene. It has to be saved in the scene and reloaded in the next session. One approach would be to write the information on a file, but this solution messes up the user disk space and can be clumsy to manage (what if the user somehow delete that file in between sessions)
The cleanest approach is to make use of the Truespace API via the custom object objects support, thus having the information saved in the scene filealong with the other objects.
This article will show you how to build a custom object and use it in your plugin to carry around information. The example I have chosen is taken outof a bigger plugin (Camera Tools) still in production. We will make a little plugin (called SnapIt!) which can save the parameters of a view when the user press a button. It will create a custom object to store the view parameters. When saving the scene, the custom objects representing the view parameters will be saved,. Upon reloading the scene, hey will be retrieved and available for selection.