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

    How to send a variable to a sub dialog

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 332 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 26/12/2016 at 19:49, xxxxxxxx wrote:

      Hello there,

      How can I send the variable "Value" from the main dialog to the sub dialog, check script and screenshot below :

      import c4d  
      from c4d import gui, bitmaps  
        
      NO = 21549  
      YES = 21547  
      CHECK_ICON = 21548  
        
      class subDialog(gui.GeDialog) :  
        def CreateLayout(self) :      
            self.SetTitle("Sub Dialog")     
            self.GroupBegin(id=0, flags=c4d.BFH_SCALEFIT, cols=2)  
            self.GroupBorderSpace(0, 0, 10, 0)  
        
            bc = c4d.BaseContainer()     
            fn = bitmaps.InitResourceBitmap(c4d.Tprotection)  
            self.myBitButton=self.AddCustomGui(CHECK_ICON, c4d.CUSTOMGUI_BITMAPBUTTON, "Bitmap Button", c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 50, 50, bc)  
            self.myBitButton.SetImage(fn, False)  
          
            self.GroupBegin(id=0, flags=c4d.BFH_CENTER, cols=1)  
            self.AddStaticText(7, c4d.BFH_LEFT, 0, 0, "The value " + **str(Value)** \+ " is higher than the recommended value", c4d.BORDER_NONE) **# Send the variable "Value" here**  
            self.AddStaticText(7, c4d.BFH_LEFT, 0, 0, "Press YES to continue or NO to cancel", c4d.BORDER_NONE)  
            self.GroupEnd()  
              
            self.GroupEnd()  
              
            self.AddSeparatorH(0, c4d.BFH_SCALEFIT)  
              
            self.GroupBegin(id=0, flags=c4d.BFH_CENTER, cols=2)  
            self.AddButton(YES, c4d.BFH_CENTER, 30, 15, name="YES")  
            self.AddButton(NO, c4d.BFH_CENTER, 30, 15, name="NO")  
            self.GroupEnd()  
              
            return True    
        
        def Command(self, id, msg) :        
            if (id == YES) :  
                self.Response = True  
                self.Close()  
        
            if (id == NO) :  
                self.Response = False  
                self.Close()  
            return True   
          
      class mainDialog(c4d.gui.GeDialog) :  
        
        def CreateLayout(self) :        
            self.SetTitle("Main Dialog")      
            self.AddButton(11001, c4d.BFH_SCALEFIT, 0, 20, "Open Sub Dialog")          
            return True      
        def Command(self, id, msg) :  
            if id == 11001:  
                **Value = 1800 # How to send this variable to the sub dialog**  
                if Value > 1500 :    
                    self.subDialog = subDialog()  
                    self.subDialog.Open(dlgtype=c4d.DLG_TYPE_MODAL, defaultw=300, defaulth=0)  
                  
                    if self.subDialog.Response == True :  
                        print self.subDialog.Response  
                    else :  
                        print self.subDialog.Response    
              
            return True  
      def main() :  
        global mainDialog  
        mainDialog = mainDialog()  
        mainDialog.Open(c4d.DLG_TYPE_MODAL, xpos=700, ypos= 200, defaultw=516, defaulth=10)  
          
        return True  
      if __name__=='__main__':  
        main()
      

      Thanks.

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

        On 27/12/2016 at 02:39, xxxxxxxx wrote:

        Hi,

        You can simply pass the value via the constructor ( __init__() ) of your SubDialog class and store it as a member. You should initialize the  Response member there too.
        And you can also have methods in the  _SubDialog  _class to get and set the value.

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

          On 29/12/2016 at 07:41, xxxxxxxx wrote:

          Hi, Thanks for your helpful comment.

          The modified script :

          import c4d  
          from c4d import gui, bitmaps  
            
          NO = 21549  
          YES = 21547  
          CHECK_ICON = 21548  
            
          class subDialog(gui.GeDialog) :  
              
            **def __init__(self, Value) :  
                self.Value = Value**  
                  
            def CreateLayout(self) :     
                self.SetTitle("Sub Dialog")    
                self.GroupBegin(id=0, flags=c4d.BFH_SCALEFIT, cols=2)  
                self.GroupBorderSpace(0, 0, 10, 0)  
            
                bc = c4d.BaseContainer()    
                fn = bitmaps.InitResourceBitmap(c4d.Tprotection)  
                self.myBitButton=self.AddCustomGui(CHECK_ICON, c4d.CUSTOMGUI_BITMAPBUTTON, "Bitmap Button", c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 50, 50, bc)  
                self.myBitButton.SetImage(fn, False)  
            
                self.GroupBegin(id=0, flags=c4d.BFH_CENTER, cols=1)  
                self.AddStaticText(7, c4d.BFH_LEFT, 0, 0, "The value " + **str(self.Value)** \+ " is higher than the recommended value", c4d.BORDER_NONE) # Send the variable "Value" here  
                self.AddStaticText(7, c4d.BFH_LEFT, 0, 0, "Press YES to continue or NO to cancel", c4d.BORDER_NONE)  
                self.GroupEnd()  
                 
                self.GroupEnd()  
                 
                self.AddSeparatorH(0, c4d.BFH_SCALEFIT)  
                 
                self.GroupBegin(id=0, flags=c4d.BFH_CENTER, cols=2)  
                self.AddButton(YES, c4d.BFH_CENTER, 30, 15, name="YES")  
                self.AddButton(NO, c4d.BFH_CENTER, 30, 15, name="NO")  
                self.GroupEnd()  
                 
                return True   
              
            def Command(self, id, msg) :       
                if (id == YES) :  
                    self.Response = True  
                    self.Close()  
            
                if (id == NO) :  
                    self.Response = False  
                    self.Close()  
                return True  
            
          class mainDialog(c4d.gui.GeDialog) :  
            
            def CreateLayout(self) :       
                self.SetTitle("Main Dialog")     
                self.AddButton(11001, c4d.BFH_SCALEFIT, 0, 20, "Open Sub Dialog")         
                return True     
            def Command(self, id, msg) :  
                if id == 11001:  
                    Value = 1800 # How to send this variable to the sub dialog  
                    if Value > 1500 :   
                        **self.subDialog = subDialog(Value)**  
                        self.subDialog.Open(dlgtype=c4d.DLG_TYPE_MODAL, defaultw=300, defaulth=0)  
                     
                        if self.subDialog.Response == True :  
                            print self.subDialog.Response  
                        else :  
                            print self.subDialog.Response   
                 
                return True  
          def main() :  
            global mainDialog  
            mainDialog = mainDialog()  
            mainDialog.Open(c4d.DLG_TYPE_MODAL, xpos=700, ypos= 200, defaultw=516, defaulth=10)  
            
            return True  
          if __name__=='__main__':  
            main()
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post