Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Scripts - persistent data?

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 649 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            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_()
            
            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post