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

    Save UI data and load UI data from .txt file

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 462 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 29/03/2017 at 07:04, xxxxxxxx wrote:

      Hi guys,

      I am trying to save UI data to a .txt file and load UI settings back by the .txt file for the UI.
      so for example:

      If I have four GeDialog.AddEditText with different names in each one. and I have a save button and press it and save it right to the .txt file, which is good. now I have a Load button, but how you load the .txt file and read it, so it can fill in the four GeDialog.AddEditText with the data from .txt file.

      This is how I am saving the .txt file and it works, but how to go about loading it back when I open it?

          def Save_UI_Settings_Data(self) :
        
              ChrName = self.GetString(self.ChrName)
        
              Save_file = p.join(p.split(__file__)[0], ChrName+'_Data.txt')
        
              doc = c4d.documents.GetActiveDocument()
        
              SubN1 = self.GetString(self.UI_SN_1) 
              SubN2 = self.GetString(self.UI_SN_2) 
              SubN3 = self.GetString(self.UI_SN_3) 
              SubN4 = self.GetString(self.UI_SN_4)
        
              if ChrName:
                  with open(Save_file,'a') as type_file:
                      type_file.write(p.split('Slot1')[1]+';'+SubN1+'\n')
                      type_file.write(p.split('Slot2')[1]+';'+SubN2+'\n')
                      type_file.write(p.split('Slot3')[1]+';'+SubN3+'\n')
                      type_file.write(p.split('Slot4')[1]+';'+SubN4+'\n')
                  return
      

      Note! 
      This is new to me when saving data for a plugin, so plz help , a tip or example on this that I can find online to help me.
      Cheers,
      Ashton

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

        On 30/03/2017 at 08:01, xxxxxxxx wrote:

        Hi Ashton,

        to be honest I don't understand the question. I mean, you already write the contents of string widgets into a file, where's the problem with the opposite?

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

          On 30/03/2017 at 08:37, xxxxxxxx wrote:

          Hi Andreas
          I am saying i don't know how to do the opposite which is the loading.
          So it like if I have a button that is for opening your save settings and you open it with a open file dialog , you select the file which is the .txt and it load  the UI settings that  you have in the .txt
          So How you make it read .txt and load settings to ui.
          Hope you understand what I am saying.

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

            On 31/03/2017 at 07:58, xxxxxxxx wrote:

            Hi Ashton,

            in our C++ docs we do have a manual on GeDialog, which might shed some more light. In order to set the values of string gadgets, GeDialog.SetString() is the function to use. Depending on your needs InitValues() could be a good place to read the file and set these values, but it could of course also be done in reaction to a button press in GeGeDialog.Command().
            Reading and writing files with standard Python functions is a bit beyond the scope of MAXON's SDK Team, but I'm sure the official Python docs can help here, see for example Chapter 7.2 Reading and Writing Files.

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