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_()