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
    • Recent
    • Tags
    • Users
    • Login

    Save User Settings

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 453 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

      On 18/06/2014 at 14:27, xxxxxxxx wrote:

      If I want to save some of my python pluggin user-settings what is the best way?

      Is there some built in way to do it in C4D?
      Or should I just use 'pickle.dump' to a file stored next to the pluggin?

      Thanks,

      Chris

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

        On 19/06/2014 at 00:20, xxxxxxxx wrote:

        Take a look at the SDK function SetWorldPluginData(), assuming it's available in Python.

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

          On 19/06/2014 at 07:47, xxxxxxxx wrote:

          Unfortunately, It's not supported in Python Steve.
          Which is the main reason why I write all of my preferences plugins in C++.

          To store data. The usual tools for that in Python are BaseContainers and UserData.
          You can hide the UserData gizmos if you don't want the user to see them.

          -ScottA

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

            On 19/06/2014 at 08:02, xxxxxxxx wrote:

            Scott, why do you think it is not supported in Python?

            import c4d
            import datetime
            from c4d.plugins import SetWorldPluginData, GetWorldPluginData
              
            PLUGIN_ID = 100004 # TEST ID ONLY!
            TIME_START = datetime.datetime(1970, 1, 1)
            TIME_FORMAT = "%Y %B %d, %H:%M:%s"
              
            def total_seconds(td) :
                # datetime.timedelta.total_seconds() was added
                # in Python 2.7
                
                temp = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6)
                return temp / 10**6
              
            def main() :
                bc = GetWorldPluginData(PLUGIN_ID) or c4d.BaseContainer()
                if bc.GetType(1000) != c4d.DTYPE_NONE:
                    dt = TIME_START + datetime.timedelta(seconds=bc.GetLong(1000))
                    print "Last saved time:", dt.strftime(TIME_FORMAT)
              
                bc.SetLong(1000, total_seconds((datetime.datetime.now() - TIME_START)))
                SetWorldPluginData(PLUGIN_ID, bc, add=False)
              
            if __name__ == "__main__":
                main()
            

            -Niklas

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

              On 19/06/2014 at 08:31, xxxxxxxx wrote:

              What I meant was that we can't create our own preferences so that the user can see them and change them (toggle them on/off).
              AFAIK. The PrefsDialogObject class is not supported by Python.

              It's kind of irritating that this is not available in Python.

              -ScottA

              *Edit:
              Isn't storing data in the WorldContainer like this this kind of dangerous?
              Since these containers will be there permanently. Even if the plugin is removed. And there's no visual reference to them in the preferences GUI.
              What's to prevent plugin developers from filling people's WC with data that never gets flushed?

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