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

    Update GeDialog When Button is Pressed?

    Cinema 4D SDK
    r21 python
    3
    6
    663
    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.
    • B
      bentraje
      last edited by bentraje

      Hi,

      I have a dialog that reads images from a folder directory. Every now and then, images are either added or removed in the directory.

      Currently, I have to reload the plug-in and reopen the plug-in for the changes to reflect. Is there a way to have GeDialog reflect the changes when a button is pressed.

      So far I have this code, but the problem is when the layout is flushed, it doesn't return back.
      You can see the problem here:
      https://www.dropbox.com/s/9ckr4dad6vf9f3x/c4d198_update_gui_dialog_when_button_is_pressed.mp4?dl=0

      def Command(self, id, msg):
      
              if id==10001: # When button is pressed
                  save_image()
                  self.LayoutFlushGroup(9002)
                  self.LayoutChanged(9002)
      
              return True
      
      

      Is there a way around this?

      1 Reply Last reply Reply Quote 0
      • M
        mp5gosu
        last edited by mp5gosu

        Yes, when Layout is flushed, it is flushed. 🙂
        You have to add your controls again, between LayoutFlushGroup() and LayoutChanged(). This is the most common way to build dynamic layouts.

        Create a helper function to create your layout. Then, you can call it when needed (CreateLayout(), MyUpdateRoutine() and so on.)

        1 Reply Last reply Reply Quote 1
        • M
          m_adam
          last edited by m_adam

          Hi @bentraje as @mp5gosu you need to recreate the UI by yourself.

          LayoutFlushGroup As the documentation says:
          Removes all controls from a group and places the control insertion point within the group.

          So it removes everything.

          And the note of LayoutFlushGroup also says:
          After all, components are added call LayoutChanged() with the group ID.

          So you need to call LayoutChanged once you have re-inserted your Gadget.
          You can find an example in C++ in gedialog_gadgets.cpp.

          Cheers,
          Maxime.

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

          1 Reply Last reply Reply Quote 1
          • B
            bentraje
            last edited by

            @mp5gosu @m_adam

            Thanks for the response.

            I'm not sure how to do this "add your controls again".
            By controls, do you mean the statictext, addedittext etc, which I guess it is based on the C++ code referenced before with the AddDynamicElement C++ function?

            If so,

            I revised the code to but it still gives me the same result in the initial video. Or are you referring to a different control?

            def Command(self, id, msg):
            
                    if id==10001: # When button is pressed
                        save_image()
                        self.LayoutFlushGroup(9002)
            
                        #THE GROUP THAT SHOWS THE GRID OF THE PICTURES
                        self.GroupBegin(id=9002, flags=c4d.BFH_SCALEFIT, groupflags = c4d.BFV_GRIDGROUP_EQUALCOLS, cols=4, rows=4,initw=0, inith=0)
                        self.GroupSpace(0, 0)
                        for image in images:
                            image_bmp = c4d.bitmaps.BaseBitmap()
                            image_copy = os.path.join(image_path, image)
                            image_bmp.InitWith(image_copy)
                            bitmapButton = self.AddCustomGui(buttonId, c4d.CUSTOMGUI_BITMAPBUTTON, "", c4d.BFV_CENTER , w, h, bcBitmapButton)
                            bitmapButton.SetImage(image_bmp, True)
            
                        self.GroupEnd()
            
                        self.LayoutChanged(9002)
            
                    return True
            
            1 Reply Last reply Reply Quote 0
            • M
              m_adam
              last edited by m_adam

              @bentraje said in Update GeDialog When Button is Pressed?:

              AddDynamicElement

              Is specific to this example that will draw an element according to the value of the combo box. you can actually replace this line by GeDialog::AddStaticText or whatever gadget addition you want to.

              You don't need to recreate the group by itself only it's content.

              So if it recreates the same things it is probably because images are not local to your class but only to your function, so if you redraw in the same order it will change of course nothing.

              Cheers,
              Maxime.

              MAXON SDK Specialist

              Development Blog, MAXON Registered Developer

              1 Reply Last reply Reply Quote 1
              • B
                bentraje
                last edited by

                RE: So if it recreates the same things it is probably because images are not local to your class but only to your function,
                Ah, gotcha. Thanks for the heads up. Works now as expected 🙂

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