Scripts - persistent data?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/01/2012 at 01:12, xxxxxxxx wrote:
OK I appreciate that scripts are not the thing to use if you want to store a lot of data
but, if you want to store something like a bunch of settings until the script is run again
is their a 'correct' way to do this?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/01/2012 at 01:45, xxxxxxxx wrote:
Do it like any other program does it, save the settings in a configuration file, or somewhat alike.
Maybe you should store the file in %APPDATA%/Maxon/CInema 4D R13/prefs, but then you should provide a deinstallation of your script. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/01/2012 at 03:51, xxxxxxxx wrote:
thanks niklas
that was my thought to - but I didn't want preempt any suggestion by putting it in the question
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/01/2012 at 03:54, xxxxxxxx wrote:
Maybe something like this. ^^
_# -- Imports -------------------------------------------------------------------_ **import** **c4d** **import** **os.path** **as** **path** **import** **xml.etree.ElementTree** **as** **etree** _# -- Configuration -------------------------------------------------------------_ **class** **InvalidXMLConfiguration** ( **Exception** ) : _""" Raised when a the configuration contains errors. """_ **class** **Config_** (object) : _""" An object storing the configuration for the plugin. """_ __did_load = False __config_path = path.join(c4d.GeGetC4dPath(c4d.C4D_PATH_PREFS), \ 'my_plugin.cfg') my_plugin_does_stuff = 'The default value here.' my_plugin_is_awesome = True **def** __init__(self) : **if** **not** self.__did_load: self.__load_config(self) **def** __setattr__(self, name, value) : setattr(Config_, name, value) **def** __getattr__(self, name) : **return** getattr(Config_, name) **def** __load_config(self) : _""" Load the configuration here. """_ get = **lambda** x: x. text **if** x **else** None fl = open(self.__config_path) xml = etree.ElementTree(file = fl) self.my_plugin_does_stuff = get(xml.find('my_plugin_does_stuff')) **or** \ self.my_plugin_does_stuff self.my_plugin_is_awesome = get(xml.find('my_plugin_is_awesome')) **or** \ self.my_plugin_is_awesome _# .._ Config = Config_()
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/01/2012 at 07:56, xxxxxxxx wrote:
oh wow - that's one for reference folder
will do my best to get my head around it
thanks Niklas
Paul