Solved Insert String Info Into AddStaticText dialog command

AddStaticText Insert String defined by variable as text name in Python

Hey guys,

I'm having a hard time trying to figure out the right order in which I'm trying to use a string obtained by a variable andu use the string infomation as a StaticText. Here's my current working code minus the AddStaticText part which works under the CreateLayout Definition, but it would run that before obtaining the information I would want it to, so I moved it under my Command Definition. Any small insight would be very grateful!

import c4d
from c4d import gui, plugins, bitmaps, documents

class GUI(gui.GeDialog):
    """ Creates the main graphical user interface of the plug-in  """
    BUTTON_ID = 1001
    Checkbox_ID = 1002
    ComboBox_ID = 1003
    AddChild_1 = 1004
    TextEdit = 1005
    def CreateLayout(self):
        self.SetTitle("CAV MVR IMPORTER")  # Set dialog title
        self.AddButton(self.BUTTON_ID, c4d.BFH_LEFT | c4d.BFV_TOP, 100, 25, "Close Dialog")
        
        self.AddCheckbox(self.Checkbox_ID, c4d.BFH_LEFT | c4d.BFV_TOP, 25, 25, "Checkbox")
        self.AddComboBox(self.ComboBox_ID, 0 | 0, 100, 25, True, True)
        self.AddChild(self.ComboBox_ID, self.AddChild_1, "Drop Down 1")
        #self.AddStaticText(self.TextEdit, 0 | 0, 100, 25, "Test Text", 1)
    def Command(self, id, msg):
        if id == 1001:
            fn = c4d.storage.LoadDialog()
            print fn
            if fn == str:
                self.AddStaticText(self.TextEdit, 0 | 0, 100, 25, fn, 1)
           


    
        
def main():
    # Test dialog
    diag = GUI()
    diag.Open(dlgtype=c4d.DLG_TYPE_MODAL, defaultw=1000, defaulth=400)

    


# Execute main()
if __name__ == '__main__':
    main()

Cheers!

MattG

Hi @geese780,

please make use of the Q&A New Functionality and read How to Post Questions, especially about category and tagging system.

I've setup correctly your post but please do it correctly for the next one.

Regarding your question, AddStaticText adds a new gadget into the UI, the usual way is to define all the Layout in the CreateLayout method of your GeDialog then defining value after user interaction.
So in your case, you could use GeDialog.SetString.

import c4d

class GUI(c4d.gui.GeDialog):
    """ Creates the main graphical user interface of the plug-in  """
    BUTTON_ID = 1001
    Checkbox_ID = 1002
    ComboBox_ID = 1003
    AddChild_1 = 1004
    TextEditGroup = 1005
    TextEdit = 1006
    
    def CreateLayout(self):
        self.SetTitle("CAV MVR IMPORTER")  # Set dialog title
        self.AddButton(self.BUTTON_ID, c4d.BFH_LEFT | c4d.BFV_TOP, 100, 25, "Close Dialog")
        
        self.AddCheckbox(self.Checkbox_ID, c4d.BFH_LEFT | c4d.BFV_TOP, 25, 25, "Checkbox")
        self.AddComboBox(self.ComboBox_ID, c4d.BFH_LEFT | c4d.BFV_TOP, 100, 25, True, True)
        self.AddChild(self.ComboBox_ID, self.AddChild_1, "Drop Down 1")
        
        # Create a Group, its usefull because here we adds the StaticText Gadget and to make it appears again
        # LayoutChanged needs to be called, which work only a group.
        if self.GroupBegin(self.TextEditGroup, c4d.BFH_SCALEFIT | c4d.BFV_TOP):
            self.AddStaticText(self.TextEdit, c4d.BFH_SCALEFIT | c4d.BFV_TOP, 100, 25, "", 1)
            self.HideElement(self.TextEdit, True)
        self.GroupEnd()
        
        return True
        
        
    def Command(self, id, msg):
        if id == 1001:
            fn = c4d.storage.LoadDialog()
            
            # Unhides the Text element
            self.HideElement(self.TextEdit, False)
            
            # Checks if its a str, then display the file path
            if isinstance(fn, str):
                self.SetString(self.TextEdit, fn)
                
            # If its not a string, the user cancelled
            else:
                self.SetString(self.TextEdit, "User cancelled")
                
            # Notify the layout of the group changed, this will invalidate the group and it will be then redraw
            # This is needed because the UI was hidden, if the Ui is not hidden then there is no need for it
            self.LayoutChanged(self.TextEditGroup)

        return True
        
def main():
    # Test dialog
    diag = GUI()
    diag.Open(dlgtype=c4d.DLG_TYPE_MODAL, defaultw=1000, defaulth=400)

# Execute main()
if __name__ == '__main__':
    main()

If there is something you don't understand feel free to ask.

Cheers,
Maxime

Thanks Maxime, understood on the rules and regulations, sorry about that.

I understand the group concept now, read up more on it and I have a better idea on how to approach the goal I'm trying to get to.

I have another error I'm getting but I'll try to do another post and see if I tag it right!

Thanks for your time!

Cheers!

MattG