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

    Re-Initialize dialog if already opened

    Cinema 4D SDK
    python sdk
    2
    3
    380
    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.
    • mfersaouiM
      mfersaoui
      last edited by mfersaoui

      Hello,
      When the dialog of my CommandData is already opened and I re-execute my CommandData the InitValues() function for example it executed only the first time dialog open.
      To re-execute the InitValues() each time I execute my CommandData I added self.dialog.Close() before the self.dialog.Open() function.

      How can I do that without closing the dialog each time I execute my CommandData plugin?

      class MyDlg(c4d.gui.GeDialog):
          def CreateLayout(self):
              ...
      
          def InitValues(self):
              Print("Hello World!")
      
      class MyCommandData(c4d.plugins.CommandData):
          dialog = None
      
          def Execute(self, doc):
              # Creates the dialog if its not already exists
              if self.dialog is None: self.dialog = MyDlg()
      
              # Close the dialog if its open
              self.dialog.Close()
      
              # Opens the dialog
              return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=500, defaulth=120,   
                                              xpos=512, ypos=128)
      
      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by Manuel

        hello,

        for your next threads, please help us keeping things organised and clean. I know it's not your priority but it really simplify our work here.

        • Q&A New Functionality.

        and please, set the thread as solved once it is 🙂

        you can simply check if your dialogbox is opened and call InitValues()

        class MyDlg(c4d.gui.GeDialog):
        
            def CreateLayout(self):
                self.AddEditNumberArrows(1000,c4d.BFH_LEFT,70,10) 
                
                return True
        
            def InitValues(self):
        
                self.SetFloat(1000, 1.0, min=0.0, step=0.1)
                print("Hello World!")
                return True
        
        class MyCommandData(c4d.plugins.CommandData):
            dialog = None
        
            def Execute(self, doc):
                # Creates the dialog if its not already exists
                if self.dialog is None: 
                    self.dialog = MyDlg()
                if self.dialog.IsOpen():
                    self.dialog.InitValues()
                    return True
                    
        
                # Opens the dialog
                return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=500, defaulth=120,   
                                                xpos=512, ypos=128)
        

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        mfersaouiM 1 Reply Last reply Reply Quote 1
        • mfersaouiM
          mfersaoui @Manuel
          last edited by mfersaoui

          @m_magalhaes
          Hello,
          Right. Duly noted. Thanks for your time.

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