Multiple SubDialogs



  • On 08/04/2014 at 14:14, xxxxxxxx wrote:

    Figured it out! After typing it out above I realized RestoreLayout() was misspelled. Thank you guys for all the help!

    *Edit there is a new problem the setup:

        def Restore(self, pluginid, secref) :
            if secref['subid'] == 1:
                print "Color"
                return self.RB_ColorDLG.Restore(pluginid,secref)
            if secref['subid'] == 2:
                print "Temp"
                return self.RB_TempDLG.Restore(pluginid,secref)
            else:
                print "Main"
                return super(BuddyDialog, self).Restore(pluginid,secref)
    

    This causes cinema to crash. I will restore the layout but if you launch the sub dialog again everything locks up. This happens with the Example as well. 



  • On 08/04/2014 at 16:01, xxxxxxxx wrote:

    Hi Shawn, I can reproduce the problems you have described. The Example I posted worked though,
    but funnily broke after a few more times testing it. I'll have to talk to a developer on this, I am pretty
    sure this is a bug. Especially this message is

    Traceback (most recent call last) :
      File "'restore-sub-dialog.pyp'", line 57, in CreateLayout
    SystemError: error return without exception set

    Best,
    -Niklas



  • On 08/04/2014 at 16:19, xxxxxxxx wrote:

    Thank you Niklas.

    -Shawn



  • On 08/04/2014 at 19:28, xxxxxxxx wrote:

    It seems to work just fine for me. No errors or problems at all.
    Maybe you're trying to do something different than I'm doing?

    Here is a complete example that works fine for me in R13.
    Save it as a .pyp file and put it in your plugins folder.
    The main dialog has buttons to open two other dialogs. And a button that will change the checkbox gizmo in dilaog1.
    All three dialogs can be docked into the UI and saved in a custom layout.

    #This is an example of a GeDialog plugin that opens three dialogs  
    #It also allows all three dialogs to be docked and saved in a custom layout  
      
    import c4d, os  
    from c4d import gui, plugins, bitmaps  
      
    PLUGIN_ID  = 1000004 #Testing ID  
    SUBDLG_ID1  = 1000005 #Testing ID  
    SUBDLG_ID2 = 1000006 #Testing ID  
      
    MAINDLG_BUTTON1_ID = 1000  
    MAINDLG_BUTTON2_ID = 1001  
    MAINDLG_BUTTON3_ID = 1002  
    SUBDLG_TEXT_ID     = 1003  
    SUBDLG_CHKBOX_ID   = 1004  
    SUBDLG_RESET_ID    = 1005  
      
    ############################  
    #The first sub dialog              
    class SubDialog1(c4d.gui.GeDialog) :  
      
      def CreateLayout(self) :  
          self.SetTitle('Sub-Dialog1')      
            
          self.GroupBeginInMenuLine()    
          self.AddCheckbox(SUBDLG_RESET_ID, c4d.BFH_RIGHT, 100, 20, name="Reset")  
          self.GroupEnd()          
            
          self.GroupBegin(0, c4d.BFH_SCALEFIT, 2, 0, "MyGroup")  
          self.GroupBorderSpace(5, 5, 5, 5)  
          self.GroupBorder(c4d.BORDER_BLACK)  
          self.AddStaticText(SUBDLG_TEXT_ID, c4d.BFH_LEFT, 200, 20, "This is the sub-dialog1")  
          self.AddCheckbox(SUBDLG_CHKBOX_ID, c4d.BFH_LEFT, 20, 20, "myChkbox")  
          self.GroupEnd()   
            
          return True          
            
      def Command(self, id, msg) :  
          if id == SUBDLG_RESET_ID:  
              self.SetBool(SUBDLG_CHKBOX_ID, False)   
              self.SetBool(SUBDLG_RESET_ID, False)     
                
          return True         
            
            
    ############################  
    #The second sub dialog              
    class SubDialog2(c4d.gui.GeDialog) :  
      
      def CreateLayout(self) :  
          self.SetTitle('Sub-Dialog2')      
            
          self.GroupBeginInMenuLine()    
          self.AddCheckbox(SUBDLG_RESET_ID, c4d.BFH_RIGHT, 100, 20, name="Reset")  
          self.GroupEnd()          
            
          self.GroupBegin(0, c4d.BFH_SCALEFIT, 2, 0, "MyGroup")  
          self.GroupBorderSpace(5, 5, 5, 5)  
          self.GroupBorder(c4d.BORDER_BLACK)  
          self.AddStaticText(SUBDLG_TEXT_ID, c4d.BFH_LEFT, 200, 20, "This is the sub-dialog2")  
          self.AddCheckbox(SUBDLG_CHKBOX_ID, c4d.BFH_LEFT, 20, 20, "myChkbox")  
          self.GroupEnd()   
            
          return True          
            
      def Command(self, id, msg) :  
          if id == SUBDLG_RESET_ID:  
              self.SetBool(SUBDLG_CHKBOX_ID, False)   
              self.SetBool(SUBDLG_RESET_ID, False)     
                
          return True          
            
      
      
    ############################  
    #The main dialog  
    class MainDialog(c4d.gui.GeDialog) :   
      
      sub_dialog1 = SubDialog1()  
      sub_dialog2 = SubDialog2()          
      
      def CreateLayout(self) :  
          self.SetTitle('Main Dialog')  
          self.AddButton(MAINDLG_BUTTON1_ID, 0, name="Open Sub-Dialog1")  
          self.AddButton(MAINDLG_BUTTON2_ID, 0, name="Open Sub-Dialog2")  
          self.AddButton(MAINDLG_BUTTON3_ID, 0, name="Change Sub-Dialog1")  
          return True  
      
      def Command(self, id, msg) :  
          if id == MAINDLG_BUTTON1_ID:  
              self.sub_dialog1.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, subid=SUBDLG_ID1)  
                
          if id == MAINDLG_BUTTON2_ID:  
              self.sub_dialog2.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, subid=SUBDLG_ID2)              
                
          if id == MAINDLG_BUTTON3_ID:  
              self.sub_dialog1.SetBool(SUBDLG_CHKBOX_ID, True)              
                
          return True  
            
      #Restore the subdialog and the main dialog in the layout  
      def Restore(self, pluginid, secref) :  
          if secref['subid'] == SUBDLG_ID1:  
              return self.sub_dialog1.Restore(pluginid, secref)  
                
          if secref['subid'] == SUBDLG_ID2:  
              return self.sub_dialog2.Restore(pluginid, secref)              
                
          else:  
              return super(MainDialog, self).Restore(pluginid, secref)  
            
    ############################  
    #The Command Data section   
    class MainDialog_CD(c4d.plugins.CommandData) :  
      
      @property  
      def dialog(self) :  
          if not hasattr(self, '_dialog') :  
              self._dialog = MainDialog()  
          return self._dialog  
      
      def Execute(self, doc) :  
          return self.dialog.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID)  
      
      def RestoreLayout(self, secref) :  
          return self.dialog.Restore(PLUGIN_ID, secref)  
      
    if __name__ == "__main__":  
      
      bmp = bitmaps.BaseBitmap()  
      dir, file = os.path.split(__file__)  
      fn = os.path.join(dir, "res", "icon.png")  
      bmp.InitWith(fn)  
      plugins.RegisterCommandPlugin(PLUGIN_ID, "Sub-Dialog Docking",0, bmp, "re-open", MainDialog_CD())
    

    -ScottA


Log in to reply