Linkbox Setlink with data? [SOLVED]



  • 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



  • 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.



  • 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


Log in to reply