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

    Python Scripting-Help with GeDialog.AddComboBox add child option

    Cinema 4D SDK
    python
    4
    12
    2.6k
    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.
    • R
      referent
      last edited by

      Hi Sebastian! Thanks a lot for your reply!!!

      and for clarifying me about posting and categories

      I couldn't figure out at the end to add command and that all complete script works by example that you send me here.

      Maybe I wasn't clear enough of what I trying to do and to get as the final result.

      My goal is that I make preset with names e.g child 0-or final name "Bath" and when I run script and chose from dropping menu of combo box e.g name "Bath" or some other next selection child 2 or final name "Patio" by selection from item with ready name "Patio" script and code automatically rename new spline based on selection from combobox eg I draw new Spline> and when I select from combo box child's selection Patio command will automatically rename spline to Patio,if is that possible? Plugin cafe is simply awesome,and I am happy so happy to discover it.
      Thanks a lot for your reply!

      Best Wishes

      Nenad

      1 Reply Last reply Reply Quote 0
      • S
        s_bach
        last edited by

        Hello,

        a GeDialog of a Python script must be a modal dialog. This means that while this dialog is opened, you can only interact with that dialog.

        Therefore you can use your script to change the name of any previously created (active) object.

        best wishes,
        Sebastian

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        R 1 Reply Last reply Reply Quote 2
        • R
          referent @s_bach
          last edited by referent

          @s_bach Hello Sebastian!

          The main issue is when I implement command and custom member function into the whole script how you suggest in to previously reply, nothing happening and the script wouldn't work.Or when I just copy your code example in to script manager nothing happening,I am using R17 if that can maybe be one of the reasons why script not work?

          class TestDialog(gui.GeDialog):

          def CreateLayout(self):
          
              self.AddComboBox(5000, c4d.BFH_LEFT, 100, 10, False)
              self.AddChild(5000, 0, "Child 0")
              self.AddChild(5000, 1, "Child 1")
              self.AddChild(5000, 2, "Child 2")
          
              return True
          
          def Command(self, id, msg):
          
              # print currently selected "child""
              if id == 5000:
                  value = self.GetInt32(5000)
                  print("got value: " + str(value))
          
          
              return c4d.gui.GeDialog.Command(self, id, msg) 
          
          # custom function
          def GetSelectedChild(self):
              return self.GetInt32(5000)
          

          def main():
          dialog = TestDialog()

          dialog.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE, 132456, -1 ,-1 ,400 ,400)
          
          value = dialog.GetSelectedChild()
          
          op.SetName(str(value))
          c4d.EventAdd()
          

          Thank you for reply!

          Regards

          1 Reply Last reply Reply Quote 0
          • S
            s_bach
            last edited by

            Hello,

            you have to add

            if __name__=='__main__':
                main()
            

            as usual to execute the script.

            best wishes,
            Sebastian

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            1 Reply Last reply Reply Quote 1
            • R
              referent
              last edited by

              7fa52105-f8bc-492d-bd56-e75e84a81179-image.png

              1 Reply Last reply Reply Quote 0
              • R
                referent
                last edited by

                import c4d
                from c4d import gui
                #Welcome to the world of Python

                class TestDialog(gui.GeDialog):

                def CreateLayout(self):
                
                    self.AddComboBox(5000, c4d.BFH_LEFT, 100, 10, False)
                    self.AddChild(5000, 0, "Child 0")
                    self.AddChild(5000, 1, "Child 1")
                    self.AddChild(5000, 2, "Child 2")
                
                    return True
                
                def Command(self, id, msg):
                
                    # print currently selected "child""
                    if id == 5000:
                        value = self.GetInt32(5000)
                        print("got value: " + str(value))
                
                
                    return c4d.gui.GeDialog.Command(self, id, msg) 
                
                # custom function
                def GetSelectedChild(self):
                    return self.GetInt32(5000)
                

                def main():
                dialog = TestDialog()

                dialog.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE, 132456, -1 ,-1 ,400 ,400)
                
                value = dialog.GetSelectedChild()
                
                op.SetName(str(value))
                c4d.EventAdd()
                

                if name=='main':
                main()

                1 Reply Last reply Reply Quote 0
                • R
                  referent
                  last edited by

                  Hello,

                  It is not working, and script isn't executable as I said in previously message,

                  thank you for your reply,

                  Regards

                  1 Reply Last reply Reply Quote 0
                  • CairynC
                    Cairyn
                    last edited by

                    Working fine for me, once I correct all the indentations. I am not sure whether your script's indents are okay, since the code is broken up into several code-quotes, but in case it's not: the methods of the class need to be indented under the class definition.

                    I don't see anything that would work under R19 (my current test) but not under R17 (your version) so this is a bit of guesswork. What is the console saying when you try to execute the code?

                    You will need to add a line to close the dialog, too, and to transform the returned value into the proper string instead of the index number as string... maybe use a dictionary for value/string pairs.

                    import c4d
                    from c4d import gui
                    
                    dropdown_values = {
                                       0:"Child 0",
                                       1:"Child 1",
                                       2:"Child 2"
                                      }
                    
                    class TestDialog(gui.GeDialog):
                    
                        pass_value = 0
                    
                        def CreateLayout(self):
                    
                            self.AddComboBox(5000, c4d.BFH_LEFT, 100, 10, False)
                            self.AddChild(5000, 0, dropdown_values.get(0))
                            self.AddChild(5000, 1, dropdown_values.get(1))
                            self.AddChild(5000, 2, dropdown_values.get(2))
                            return True
                    
                        def Command(self, id, msg):
                            # print currently selected "child""
                            if id == 5000:
                                value = self.GetInt32(5000)
                                print("got index: " + str(value) + ", value: " + dropdown_values.get(value))
                                self.pass_value = value
                                self.Close()
                            return c4d.gui.GeDialog.Command(self, id, msg) 
                    
                        # custom function
                        def GetSelectedChild(self):
                            return self.pass_value
                    
                    def main():
                        dialog = TestDialog()
                    
                        dialog.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE, 132456, -1 ,-1 ,400 ,400)
                    
                        value = dialog.GetSelectedChild()
                        print "Value after call: ", value
                        op.SetName(dropdown_values.get(value))
                        c4d.EventAdd()
                    
                    if __name__=='__main__':
                        main()
                    
                    1 Reply Last reply Reply Quote 2
                    • R
                      referent
                      last edited by

                      Wow! Thank you soooooooooooo much!

                      Those parts were missing. Works like a charm now! 🙂

                      can't thank you enough!

                      We can close now this topic

                      1 Reply Last reply Reply Quote 0
                      • M
                        m_adam
                        last edited by m_adam

                        Please do not delete topics once they are resolved, this topic may help other people that have the same issue.
                        Instead, use the Q&A functionality to mark a topic as solved.

                        Cheers,
                        Maxime.

                        MAXON SDK Specialist

                        Development Blog, MAXON Registered Developer

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