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

    Linkbox Setlink with data? [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 366 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 10/04/2017 at 14:33, xxxxxxxx wrote:

      Hi guys, 
      I am trying to Load the data from the text file, read it and load it in to the link box. but it don't link what I tell it to find in the object manger, which is Cube.1 inside the .txt file. Plz tell what I am doing wrong in my code.

      This is what inside the .txt file.

      Cube.1
      

      The Code:

      Load = {"id": 1009, "name": "Open Settings"}
      SaveSettingsPath_in_field = 1011
      UI_TEMP_S1 = 1010
        
      class LinkBoxDialog(gui.GeDialog) :
          def CreateLayout(self) :
              self.MenuFlushAll()
              self.MenuSubBegin("Settings")        
              self.MenuAddString(Load["id"], Load["name"])
              self.MenuSubEnd()    
              self.MenuFinished()
        
              self.GroupBegin(34, c4d.BFH_MASK, rows=1)
              self.AddStaticText(203, c4d.BFH_CENTER, 0, 0, "Settings")
              self.Enable(203, False)
              self.AddEditText(SaveSettingsPath_in_field, c4d.BFH_MASK, 250, 10)
              self.GroupEnd()
        
              self.GroupBegin(34, c4d.BFH_MASK, rows=1)
              self.AddStaticText(0, c4d.BFH_CENTER, 0, 0, "TEMP 1.")
              self.rootLinkBaseContainer = c4d.BaseContainer()
              self.LinkBox1 = self.AddCustomGui(UI_TEMP_S1, c4d.CUSTOMGUI_LINKBOX, "", c4d.BFH_CENTER, 250, 10, self.rootLinkBaseContainer)
              self.GroupEnd()
        
        
              return True
        
        
          def LoadSettings(self) :
              doc = c4d.documents.GetActiveDocument()
        
              Load_Path = st.LoadDialog(type=c4d.FILESELECTTYPE_ANYTHING, title="Open Your Settings Folder Directory.", flags=c4d.FILESELECT_DIRECTORY, force_suffix=".txt")
        
              self.SetString(SaveSettingsPath_in_field, Load_Path)
        
              Get_Path = self.GetString(SaveSettingsPath_in_field)
        
              doc = c4d.documents.GetActiveDocument()
        
              linkBox = self.FindCustomGui(UI_TEMP_S1, c4d.CUSTOMGUI_LINKBOX)
        
              data1 = open(os.path.join(Get_Path, 'Temp_Data_1.txt'), "r")
        
              read_txt = data1.readline()
        
              get_obj = doc.SearchObject(read_txt)
        
              linkBox.SetLink(get_obj)
        
              c4d.EventAdd()
              
              return True
        
          def Command(self, id, msg=None) :
        
              if (id == 1009) :
                  self.LoadSettings()
              return True
      

      plz help or tips would be really helpful to me.
      Cheers,
      Ashton

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

        On 11/04/2017 at 09:39, xxxxxxxx wrote:

        Hi Ashton,

        the problem is, that the result of readline() contains the newline/linebreak at the end. Strip this from the string and your code works. Still I suggest to add error checks, where needed. Also makes debugging easier.

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

          On 11/04/2017 at 16:50, xxxxxxxx wrote:

          Thanks Andreas 🙂

          lol i had a next line which is line 2 lol

              #####################################
              # Save UI Settings to File
              ##################################### 
              def Save_UI_Settings(self) :
                  doc = c4d.documents.GetActiveDocument()        
            
                  newpath = st.LoadDialog(type=c4d.FILESELECTTYPE_ANYTHING, title="Save Settings in a Directory.", flags=c4d.FILESELECT_DIRECTORY, force_suffix="")
            
                  self.SetString(SaveSettingsPath_in_field, newpath)
            
                  linkBox = self.FindCustomGui(1010, c4d.CUSTOMGUI_LINKBOX)
                  #####################################
                  # Save Temp 
                  #####################################
                  with open(p.join(os.path.join(newpath, 'Temp_Data_1.txt')), 'w') as type_file:
                      LinkData = linkBox.GetLink().GetName()               
                      type_file.write(LinkData+"\n") # <----------- I needed to Remove +"\n" it was making line 2 in the .txt
          

          So in my Load Settings, I now have it like this now.

                  doc = c4d.documents.GetActiveDocument()
                  linkBox = self.FindCustomGui(1010, c4d.CUSTOMGUI_LINKBOX)
                  data1 = open(os.path.join(Get_Path, 'Temp_Data_1.txt'), "r")
                  linkBox.SetLink(doc.SearchObject(data1.readline()))
                  c4d.EventAdd()
          

          So I Works Great on Loading! 🙂
          Thanks and Cheers,
          Ashton

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