Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Multiple SubDialogs

    PYTHON Development
    0
    24
    14.7k
    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.
    • H
      Helper
      last edited by

      On 02/04/2014 at 10:33, xxxxxxxx wrote:

      Is there a way to have multiple subdialogs open at the same time. When I open a second one the first dialog becomes locked.

      I have tried using a subid with gui.GeDialog and gui.SubDialog, neither one works. Is there a specific way to set this up?

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 02/04/2014 at 13:28, xxxxxxxx wrote:

        Do you mean a SubDialog being embedded into another dialog (which is actually what a SubDialog
        is for, and is not possible with Python) or a Dialog that opens when the users clicks a button in the
        main dialog?

        For the latter, open the dialog asynchronous.

        -Niklas

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 02/04/2014 at 14:30, xxxxxxxx wrote:

          The Dialogs are basically just simple tools of the main plugin that I want to display in a separate window. I am using DLG_TYPE_ASYNC for the SubDialogs. I have also found that with having multiple Dialogs in the plugin you can not save them into your layout and the window displays "Plugin is missing."

          Is there a way to do this without having to make a separate plugin for each separate window?

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            On 03/04/2014 at 13:07, xxxxxxxx wrote:

            Use subids to open the dialogs. You can get the subid in CommandData::RestoreLayout() from the "secret" parameter.

            -Niklas

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              On 04/04/2014 at 08:47, xxxxxxxx wrote:

              Thanks for the help Niklas,

              I realized I was calling my subdialogs by the same name, so opening one killed the other.

              This is how I am calling the main dialog/window:

              return self.dialog.Restore(pluginid = PLUGIN_ID, secret = sec_ref)
              

              How do I use the "secret" to restore the submenus? I can't seen to find any information about that parameter.

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 04/04/2014 at 09:35, xxxxxxxx wrote:

                This is the best information I have found so far but I cant seam to convert it to python correctly.

                https://developers.maxon.net/forum/topic/1393/732_subid-for-dialogs&OB=ASC

                When I save my layout they plugin windows go blank.

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  On 04/04/2014 at 12:24, xxxxxxxx wrote:

                  Try print the "secret". It's no longer cryptic when you see its actually a dictionary.

                  -Niklas

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    On 04/04/2014 at 13:01, xxxxxxxx wrote:

                    I think I am confusing myself. The fact that this attribute is called "secret" makes it impossible to search for with Google.

                    I tried to print the attribute but of course the secret is not defined. (I am pretty sure I am going about this the wrong way.) Do you know where I can find an example of a python plugin consisting of 2 or more windows?

                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      On 04/04/2014 at 14:48, xxxxxxxx wrote:

                      Sorry, the C++ docs refer to it as "secret", but the Python docs say "sec_ref". I was talking about this parameter, it is the only one passed to RestoreLayout() besides "self".

                      print sec_ref

                      {'subid': 0, 'ptr': <PYCObject ...>}

                      See? Theres the subid.

                      -Niklas

                      1 Reply Last reply Reply Quote 0
                      • H
                        Helper
                        last edited by

                        On 05/04/2014 at 10:12, xxxxxxxx wrote:

                        I'm interested in knowing the answer to this one too.
                        Since it's much easier to communicate using a working example. Here's a very basic working example showing the problem of not being able to dock a sub dialog:

                        import c4d,os,sys  
                        from c4d import gui, plugins, bitmaps, documents, utils  
                          
                        PLUGIN_ID = 1000003    #The plugin's ID#  
                        MAINDLG   = 1000040    #An ID to be assigned to the main dialog  
                        SUBDLG    = 1000041    #An ID to be assigned to the sub dialog  
                          
                          
                        ###### The sub dialog ######  
                        class MySubDialog(gui.GeDialog) :  
                          
                          def CreateLayout(self) :  
                              self.SetTitle("Sub Dialog")          
                          
                              self.GroupBegin(0, c4d.BFH_SCALEFIT, 2, 0, "MyGroup")  
                              self.GroupBorderSpace(5, 5, 5, 5)  
                              self.GroupBorder(c4d.BORDER_BLACK)  
                              self.AddStaticText(1111, c4d.BFH_LEFT, 0, 0, "Hello World", 0)  
                              self.AddEditSlider(2222, c4d.BFH_SCALEFIT, 500, 0)  
                              self.GroupEnd()         
                              return True   
                          
                          def InitValues(self) :  
                              self.SetReal(id = 2222, value = 5.0, min = 0.0, max = 100.0, step = 1.0, format = c4d.FORMAT_METER)  
                              return True  
                          
                          def Command(self, id, msg) :  
                              if (id == 2222) :  
                                  print self.GetReal(2222)   #Print the value of the slider         
                              return True  
                          
                          
                        ###### The main dialog ######  
                        class MyMainDialog(gui.GeDialog) :  
                          
                          subdlg = MySubDialog()  
                          
                          def CreateLayout(self) :  
                              self.SetTitle("Main Dialog")   
                              self.AddButton(10001, c4d.BFH_CENTER, 150, 0, "Open SubDlg")     
                              return True     
                          
                          def InitValues(self) :     
                              return True  
                          
                          def Command(self, id, msg) :  
                               
                              if (id == 10001) :  
                                  self.subdlg.Open(dlgtype = c4d.DLG_TYPE_ASYNC, pluginid = SUBDLG, defaultw = 200, defaulth = 100)  
                                   
                              c4d.EventAdd()  
                              return True  
                          
                        class Dialog_CD(c4d.plugins.CommandData) :  
                          
                          mainDialog = None  
                          subDialog = None  
                          
                          def Init(self, op) :  
                              return True  
                          
                          def Execute(self, doc) :  
                              if self.mainDialog is None and self.subDialog is None:  
                                  self.mainDialog = MyMainDialog()  
                                  self.subDialog = MySubDialog()  
                                    
                              self.mainDialog.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, -1, -1, 0, 0, MAINDLG)  
                              #self.subDialog.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, -1, -1, 0, 0, SUBDLG)  #For reference only...We don't want to open both dialogs here  
                              return True   
                                
                                
                        ##### This does not work!!!! ########  
                        #The function stops after it finds the mainDialog. And only restores that dialog!!!  
                        #The sub dialog results in "plugin not found" in the layout!!!  
                          def RestoreLayout(self, sec_ref) :  
                           
                              subid = sec_ref["subid"]  
                              object = sec_ref["ptr"]  
                            
                              if self.mainDialog is None:  
                                  self.mainDialog = MyMainDialog()   
                                  print subid   
                                  if subid == MAINDLG:  
                                      print "subid == MAINDLG"  
                                      self.mainDialog.Restore(MAINDLG, sec_ref)  
                          
                              if self.subDialog is None:  
                                  self.subDialog = MySubDialog()   
                                  print subid   
                                  if subid == SUBDLG:  
                                      print "subid == SUBDLG"  
                                      self.subDialog.Restore(SUBDLG, sec_ref)  
                                        
                              return True   
                              
                        if __name__ == "__main__":  
                          bmp = c4d.bitmaps.BaseBitmap()  
                          dir, file = os.path.split(__file__)  
                          fn = os.path.join(dir, "res", "icon.tif")  
                          bmp.InitWith(fn)  
                          result = plugins.RegisterCommandPlugin(PLUGIN_ID, "Dockable SubDialogs", 0, bmp, "Dockable SubDialogs", Dialog_CD()) 
                        

                        -ScottA

                        1 Reply Last reply Reply Quote 0
                        • H
                          Helper
                          last edited by

                          On 06/04/2014 at 09:29, xxxxxxxx wrote:

                          Hello,

                          here is an example similar to yours that demonstrates how you can easily restore even sub-dialogs.
                          It also demonstrates a few techniques that are good practice and useful.

                          One big problem of your code, for instance, was that, if restoring the sub dialog would have 
                          worked, pressing the button on the main dialog would've opened another dialog than the one
                          that was restored into the layout.

                          Also,

                          a) the subid does not need to be a plugin ID
                          b) for GeDialog.Restore(), the first argument must be the command plugins PLUGIN_ID,
                          same when opening the main and sub dialog.

                          The reason it didn't restore is that the first time RestoreLayout() was called, you create the
                          sub-dialog, but the second time, the block that forwards the restoring to the sub-dialog isn't
                          even executed because of

                          if self.subDialog is None:  # False in the second call
                              # ...
                          

                          Best,
                          -Niklas

                          import c4d
                            
                          PLUGIN_ID = 1000004 # Test ID
                            
                          class MainDialog(c4d.gui.GeDialog) :
                            
                              # Do not create the object on class-level, although it might
                              # be unimportant since you do not open multiple objects of your
                              # MainDialog, it is contradicting to have one instance of sub
                              # dialog for all instances of the main dialog.
                              # A property that creates the dialog on-demand is perfect for
                              # this purpose.
                            
                              @property
                              def sub_dialog(self) :
                                  if not hasattr(self, '_sub_dialog') :
                                      self._sub_dialog = SubDialog()
                                  return self._sub_dialog
                            
                              # c4d.gui.GeDialog
                            
                              def CreateLayout(self) :
                                  self.SetTitle('Main Dialog')
                                  self.AddButton(1000, 0, name="Open Sub-Dialog")
                                  return True
                            
                              def Command(self, param, bc) :
                                  if param == 1000:
                                      self.sub_dialog.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, subid=1)
                                  return True
                            
                              def Restore(self, pluginid, secref) :
                                  # We override this method so we don't have to handle the sub-
                                  # dialog from the CommandData plugin. THIS dialog is responsible
                                  # for the sub-dialog, do not split such management throughout
                                  # your program or it gets confusing.
                                  if secref['subid'] == 1:
                                      return self.sub_dialog.Restore(pluginid, secref)
                                  else:
                                      return super(MainDialog, self).Restore(pluginid, secref)
                            
                          class SubDialog(c4d.gui.GeDialog) :
                            
                              # c4d.gui.GeDialog
                            
                              def CreateLayout(self) :
                                  self.SetTitle('Sub-Dialog')
                                  self.AddStaticText(1000, 0, name="This is the sub-dialog.")
                                  return True
                            
                          class Command(c4d.plugins.CommandData) :
                            
                              def Register(self) :
                                  return c4d.plugins.RegisterCommandPlugin(
                                          PLUGIN_ID, "Sub-Dialog Docking Test", 0, None, "", self)
                            
                              @property
                              def dialog(self) :
                                  if not hasattr(self, '_dialog') :
                                      self._dialog = MainDialog()
                                  return self._dialog
                            
                              # c4d.plugins.CommandData
                            
                              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__':
                              Command().Register()
                          
                          1 Reply Last reply Reply Quote 0
                          • H
                            Helper
                            last edited by

                            On 06/04/2014 at 11:24, xxxxxxxx wrote:

                            Thanks Niklas.
                            I never thought about using Restore() in the main GeDialog class like that.

                            -ScottA

                            1 Reply Last reply Reply Quote 0
                            • H
                              Helper
                              last edited by

                              On 07/04/2014 at 09:29, xxxxxxxx wrote:

                              You're welcome, Scott.

                              You can also find the code at the GitHub py-cinema4sdk repository under gui/restore-sub-dialog.pyp!
                              Do also take a look at the respective readme file at gui/restore-sub-dialog.md.

                              Best,
                              -Niklas

                              1 Reply Last reply Reply Quote 0
                              • H
                                Helper
                                last edited by

                                On 07/04/2014 at 11:19, xxxxxxxx wrote:

                                Thanks for the help guys, however I still have a few problems. Using Kiklas' method I got the SubDialogs to behave correctly when I re-open them while they are open and the window becomes active. I still get a Plugin not found while restoring a layout, I think this reason is due to having more than one sub dialog.

                                here is the code:

                                def Restore(self, PLUGIN_ID, secref) :
                                     if secref['subid'] == 1:
                                          return self.sub_dialog1.Restore(PLUGIN_ID,secref)
                                     elif secref['subid'] == 2:
                                          return self.sub_dialog2.Restore(PLUGIN_ID,secref)
                                     else:
                                          return super(MainDialog, self).Restore(PLUGIN_ID,secref)
                                

                                How do I correctly look for both subdialogs.

                                1 Reply Last reply Reply Quote 0
                                • H
                                  Helper
                                  last edited by

                                  On 07/04/2014 at 11:23, xxxxxxxx wrote:

                                  How do you open the subdialogs?

                                  1 Reply Last reply Reply Quote 0
                                  • H
                                    Helper
                                    last edited by

                                    On 07/04/2014 at 11:26, xxxxxxxx wrote:

                                    if id == 10017: # Get Render Time
                                         self.sub_dialog2.Open(c4d.DLG_TYPE_ASYNC, defaulth=200, defaultw=300, subid = 2)
                                    

                                    Oh wait, I think I just figured it out, This has to have the plugin ID as well correct?

                                    1 Reply Last reply Reply Quote 0
                                    • H
                                      Helper
                                      last edited by

                                      On 07/04/2014 at 11:41, xxxxxxxx wrote:

                                      No that did not work. Here is what my @properties look like

                                      @property
                                      def sub_dialog1(self) :
                                           if not hasattr(self, '_sub_dialog1') :
                                                self._sub_dialog1 = ColorDialog()
                                           return self._sub_dialog1
                                      @property
                                      def sub_dialog2(self) :
                                           if not hasattr(self, '_sub_dialog2') :
                                                self._sub_dialog2 = RenderTimeDialog()
                                           return self._sub_dialog2
                                      
                                      1 Reply Last reply Reply Quote 0
                                      • H
                                        Helper
                                        last edited by

                                        On 07/04/2014 at 11:58, xxxxxxxx wrote:

                                        Here is the code from your exaple made to have 2 sub dialogs: Same problem.

                                        import c4d
                                          
                                        PLUGIN_ID = 1000004 # Test ID
                                          
                                        class MainDialog(c4d.gui.GeDialog) :
                                          
                                            # Do not create the object on class-level, although it might
                                            # be unimportant since you do not open multiple objects of your
                                            # MainDialog, it is contradicting to have one instance of sub
                                            # dialog for all instances of the main dialog.
                                            # A property that creates the dialog on-demand is perfect for
                                            # this purpose.
                                          
                                            @property
                                            def sub_dialog(self) :
                                                if not hasattr(self, '_sub_dialog') :
                                                    self._sub_dialog = SubDialog()
                                                return self._sub_dialog
                                            @property
                                            def sub_dialog2(self) :
                                                if not hasattr(self, '_sub_dialog2') :
                                                    self._sub_dialog2 = SubDialog2()
                                                return self._sub_dialog2
                                            # c4d.gui.GeDialog
                                          
                                            def CreateLayout(self) :
                                                self.SetTitle('Main Dialog')
                                                self.AddButton(1000, 0, name="Open Sub-Dialog")
                                                return True
                                          
                                            def Command(self, param, bc) :
                                                if param == 1000:
                                                    self.sub_dialog.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, subid=1)
                                                    self.sub_dialog2.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, subid=2)
                                                return True
                                          
                                            def Restore(self, pluginid, secref) :
                                                # We override this method so we don't have to handle the sub-
                                                # dialog from the CommandData plugin. THIS dialog is responsible
                                                # for the sub-dialog, do not split such management throughout
                                                # your program or it gets confusing.
                                                if secref['subid'] == 1:
                                                    return self.sub_dialog.Restore(pluginid, secref)
                                                elif secref['subid'] == 2:
                                                    return self.sub_dialog2.Restore(pluginid, secref)
                                                else:
                                                    return super(MainDialog, self).Restore(pluginid, secref)
                                          
                                        class SubDialog(c4d.gui.GeDialog) :
                                          
                                            def CreateLayout(self) :
                                                self.SetTitle('Sub-Dialog')
                                                self.AddStaticText(1000, 0, name="This is the sub-dialog.")
                                                return True
                                        class SubDialog2(c4d.gui.GeDialog) :
                                          
                                            def CreateLayout(self) :
                                                self.SetTitle('Sub-Dialog2')
                                                self.AddStaticText(1000, 0, name="This is the sub-dialog2.")
                                                return True
                                          
                                        class Command(c4d.plugins.CommandData) :
                                          
                                            def Register(self) :
                                                return c4d.plugins.RegisterCommandPlugin(
                                                        PLUGIN_ID, "Sub-Dialog Docking Test", 0, None, "", self)
                                          
                                            @property
                                            def dialog(self) :
                                                if not hasattr(self, '_dialog') :
                                                    self._dialog = MainDialog()
                                                return self._dialog
                                          
                                            # c4d.plugins.CommandData
                                          
                                            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__':
                                            Command().Register()
                                        
                                        1 Reply Last reply Reply Quote 0
                                        • H
                                          Helper
                                          last edited by

                                          On 07/04/2014 at 13:45, xxxxxxxx wrote:

                                          OK I got the example to work. 
                                          however I cannot get my plugin to work. could it be that my main window uses a .res file?

                                          import c4d
                                            
                                          PLUGIN_ID = 1000004 # Test ID
                                            
                                          class MainDialog(c4d.gui.GeDialog) :
                                            
                                              # Do not create the object on class-level, although it might
                                              # be unimportant since you do not open multiple objects of your
                                              # MainDialog, it is contradicting to have one instance of sub
                                              # dialog for all instances of the main dialog.
                                              # A property that creates the dialog on-demand is perfect for
                                              # this purpose.
                                            
                                              @property
                                              def sub_dialog(self) :
                                                  if not hasattr(self, '_sub_dialog') :
                                                      self._sub_dialog = SubDialog()
                                                  return self._sub_dialog
                                              @property
                                              def sub_dialog2(self) :
                                                  if not hasattr(self, '_sub_dialog2') :
                                                      self._sub_dialog2 = SubDialog2()
                                                  return self._sub_dialog2
                                              # c4d.gui.GeDialog
                                            
                                              def CreateLayout(self) :
                                                  self.SetTitle('Main Dialog')
                                                  self.AddButton(1000, 0, name="Open Sub-Dialog")
                                                  return True
                                            
                                              def Command(self, param, bc) :
                                                  if param == 1000:
                                                      self.sub_dialog.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, subid=1)
                                                      self.sub_dialog2.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, subid=2)
                                                  return True
                                            
                                              def Restore(self, pluginid, secref) :
                                                  # We override this method so we don't have to handle the sub-
                                                  # dialog from the CommandData plugin. THIS dialog is responsible
                                                  # for the sub-dialog, do not split such management throughout
                                                  # your program or it gets confusing.
                                                  if secref['subid'] == 1:
                                                      print "yes"
                                                      return self.sub_dialog.Restore(pluginid, secref)
                                                  if secref['subid'] == 2:
                                                      return self.sub_dialog2.Restore(pluginid, secref)
                                                  else:
                                                      return super(MainDialog, self).Restore(pluginid, secref)
                                            
                                          class SubDialog(c4d.gui.GeDialog) :
                                            
                                              def CreateLayout(self) :
                                                  self.SetTitle('Sub-Dialog')
                                                  self.AddStaticText(1000, 0, name="This is the sub-dialog.")
                                                  return True
                                                  
                                          class SubDialog2(c4d.gui.GeDialog) :
                                            
                                              def CreateLayout(self) :
                                                  self.SetTitle('Sub-Dialog2')
                                                  self.AddStaticText(1000, 0, name="This is the sub-dialog2.")
                                                  return True
                                            
                                          class Command(c4d.plugins.CommandData) :
                                            
                                              def Register(self) :
                                                  return c4d.plugins.RegisterCommandPlugin(
                                                          PLUGIN_ID, "Sub-Dialog Docking Test", 0, None, "", self)
                                            
                                              @property
                                              def dialog(self) :
                                                  if not hasattr(self, '_dialog') :
                                                      self._dialog = MainDialog()
                                                  return self._dialog
                                            
                                              # c4d.plugins.CommandData
                                            
                                              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__':
                                              Command().Register()
                                          
                                          1 Reply Last reply Reply Quote 0
                                          • H
                                            Helper
                                            last edited by

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

                                            I think the problem with my plugin has something to do with the main command class, the "RestoreLayout" does not get called at all. I added some print functions to see and nothing. However the example prints just fine. Here is my main command code:

                                            class RenderBuddy(c4d.plugins.CommandData) :
                                              
                                                @property
                                                def RBdialog(self) :
                                                    if not hasattr(self, '_RBdialog') :
                                                        self._RBdialog = BuddyDialog()
                                                    return self._RBdialog
                                                    
                                                def Register(self) :
                                                    return c4d.plugins.RegisterCommandPlugin(PLUGIN_ID, "Render Buddy (Beta)",0, bmp, "", self)
                                                            
                                                def Execute(self, doc) :
                                                    return self.RBdialog.Open(c4d.DLG_TYPE_ASYNC,PLUGIN_ID)
                                                    
                                                def RestorLayout(self, secref) :
                                                    print "RB_Main"
                                                    return self.RBdialog.Restore(PLUGIN_ID, secref)
                                                
                                            if __name__ == "__main__":
                                                
                                                path, fn = os.path.split(__file__)
                                                bmp = bitmaps.BaseBitmap()  
                                                bmp.InitWith(os.path.join(path, "res/icons/", "icon.tif"))
                                                 
                                                RenderBuddy().Register()
                                            

                                            Everything seems to be right, but the RestoreLayout does not get called.

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