badoumba 06 February 2009 10:26 PM
Hello
I have made several scripts with a UI. Some of the UI’s values are not directly linked to object’s properties in the scene but are just changed during running time of my app. by some functions.
Problem: If I close my popup UI and want to re-open it again to change some settings, I have then lost all these “floating” values. They can’t be recovered from any object ( size of a sphere for instance), so I have to use a kind of persistent data for them.
What’s the simplest and standard process to achieve that?
Thanks for any help of course !
There are so many ways with different pros and cons, I don’t even know where to start :)
*You can store persistent global variables with the scene and put your data there. It used to be a big No-no in the past, but persistent globals were fixed several releases ago and do not cause problems when merging anymore. Be sure to use a long descriptive name. You can use arrays to store an arbitrary number of MAXScript Values (incl. floats, integers, strings, colors, other arrays etc.) in a single variable.
*You can store data in AppData of ANY maxObject which includes scene nodes, base objects, modifiers, materials and maps, animation controllers and trackview nodes. VERY powerful but limited to strings so require data conversion when reading and writing. Storing data in the root node of the scene (via Trackview nodes) makes the data part of scene completely independent of any scene nodes, so even if you delete all scene objects, that data would stick around. AppData survives merging of the holder object.
*You can store the data in actual TrackViewNodes. You can create your tracks, assign controllers to them and even connect spinners to these controllers if desired. This method is the best when you have to store animation data since controllers are best suited for the task.
*You can create a (hidden?) holder object and store your data in it using any of the available methods including UserProps, AppData, Custom Attributes etc. The beauty of this approach is that merging the object into another scene would bring the data over. UserProps are string only and too exposed (which is both good and bad - you can see and edit them easily in the Object Properties dialog). Custom Attributes are too easy to remove but can include animation controllers, too.
*You can store the data externally, for example in an INI file, a MAXScript file or a pure ASCII file. Obviously, the data would not be persistent in the scene, but if you want your tool to use the same settings each time you open it regardless of which scene is loaded, it is a good option. I use it all the time.
Borislav “Bobo” Petrov
|