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

    Dialog in a dialog

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 272 Views
    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 Offline
      Helper
      last edited by

      On 25/03/2013 at 07:35, xxxxxxxx wrote:

      I'm tring to open a 2nd (modal) dialog in another dialog.
      It works ok, until I close and re-open the plugin with the dialog.
      Then an incorrect dialog is displayed and later Cinema 4d crashes.
      It seems that i do not restore correctly?

        
        
      import c4d  
      import os  
      from c4d import gui, plugins, bitmaps, utils, documents  
        
      PLUGIN_ID = 1011310 # Test ID  
        
      MY_CITY             = 11001  
      MY_BUTTON           = 11004  
        
      class MyDialog2(gui.GeDialog) :  #2nd (modal) dialog  
        
        def CreateLayout(self) :  
            self.GroupBegin(id=1011, flags=c4d.BFH_FIT, cols=2)   
            self.element = self.AddStaticText(id=1003, flags=c4d.BFH_LEFT, initw=100, name="City")  
            self.AddEditText(MY_CITY, c4d.BFH_SCALEFIT, 100, 0)  
            self.GroupEnd()      
              
            self.GroupBegin(id=1013, flags=c4d.BFH_SCALEFIT, cols=1)  
            self.AddButton(MY_BUTTON, c4d.BFV_MASK, initw=100, name="Done")  
            self.GroupEnd()  
            return True    
              
              
        def Command(self, id, msg) :        
            if (id == MY_BUTTON) :  
                print "city: ", self.GetString (MY_CITY)  
                self.Close()  
                return True  
            return True          
              
      class MyDialog(gui.GeDialog) : #main dialog  
        
        def CreateLayout(self) :  
            self.GroupBegin(id=1013, flags=c4d.BFH_SCALEFIT, cols=1)  
            self.AddButton(MY_BUTTON, c4d.BFV_MASK, initw=100, name="Goto 2nd dialog")  
            self.GroupEnd()  
            return True      
        
        def Command(self, id, msg) :        
            if (id == MY_BUTTON) :  
                self.dialog2 = MyDialog2()  #init and open 2nd dialog  
                self.dialog2.Open(dlgtype=c4d.DLG_TYPE_MODAL, pluginid=PLUGIN_ID, defaultw=200, defaulth=150, xpos=-1, ypos=-1)  
                return True  
            return True  
        
      #################################################################################################  
        
      class MyMenuPlugin(plugins.CommandData) :  
        dialog = None  
        def Execute(self, doc) :  
        # create the dialog  
           if self.dialog is None:  
              self.dialog = MyDialog()  
           return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=200, defaulth=150, xpos=-1, ypos=-1)  
              
        def RestoreLayout(self, sec_ref) :  
        # manage the dialog  
           if self.dialog is None:  
              self.dialog = MyDialog()  
           print "Restore."  
           return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)  
             
      if __name__ == "__main__":  
        
       path, fn = os.path.split(__file__)  
       bmp = bitmaps.BaseBitmap()                                   
       bmp.InitWith(os.path.join(path, "res/icons/", "icon.tif"))   
        
       okyn = plugins.RegisterCommandPlugin(PLUGIN_ID, "OSM",0, bmp, "OSM", MyMenuPlugin())    
       if (okyn) :   
        print "Initialized."  
        
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 25/03/2013 at 07:40, xxxxxxxx wrote:

        Hi.

        Pass the pluginid to a dialog only for the dialog that belongs to the CommandData itself. It is
        also only necessary when you want to restore the dialog (in CommandData.Restore()) which in
        turn only works for asynchronous dialogs.

        Remove the pluginid=PLUGIN_ID from the Open() call of your second dialog.

        -Niklas

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

          On 26/03/2013 at 12:07, xxxxxxxx wrote:

          Yes, it works!
          Thank you.
          I'll put it in a tutorial including your remarks.

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