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 get ComboBox value based on item selection?

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 452 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 12/11/2017 at 05:28, xxxxxxxx wrote:

      Hi everyone,

      Firstly, thank you for taking the time to create this amazing community, where I learn a lot even tho this is my first post. I'm sure you are able to help me. 🙂

      I've built a dialog where you select the folder in the first comboBox and based on that choice it adds the files to a second comboBox.

      I've manage to have get the directory for the folders, but I can't get the children of the selected folder on the second comboBox. I understand that you can't just get the string of a comboBox (unfortunately).
      So how can I get the values for the selected folder?
      Here's the code I'm currently working on:

      ## eXpressoMaker is created by Andre Anjos v1.0 ##
        
      # Add template modules into Xpresso
        
      # Import modules #
        
      import c4d, os
      from c4d import gui, plugins, documents, storage
        
      ##################
        
      # Global Variables
        
      PLUGIN_ID = 1040128  # Release ID 1040128
      GRP_COMBOX = 1002
      CHILD_VALUES = 1011
      PATH = storage.GeGetStartupWritePath() + '/library/xgroup/'
        
      ##################
        
      def listFolders() :
        
          folders = []
        
          if os.path.exists(PATH) :
        
              for folder in os.listdir(PATH) :
                  folders.append(folder)
          
          return folders
          
      def listFiles(folder) :
        
          files = []
        
          for file in os.listdir(PATH + folder) :
              files.append(file)
          
          return files
        
      class eXpressoMakerDialog(gui.GeDialog) :
        
          def CreateLayout(self) :
        
              self.GroupBegin(id=10000, flags=c4d.BFH_SCALEFIT, cols=1, rows=3, title="eXpresso Maker v1.0")
              
              self.GroupBegin(id=10001, flags=c4d.BFH_SCALEFIT, cols=1, rows=1, title="Folder")
              self.AddStaticText(id=1001, flags=c4d.BFH_CENTER, initw=0, inith=20, name="Folder")
              self.AddComboBox(id=GRP_COMBOX, flags=c4d.BFH_SCALEFIT, initw=200, inith=20)
              
              for folder in listFolders() :
                  self.AddChild(id=GRP_COMBOX, subid=CHILD_VALUES, child=folder) 
        
              self.GroupEnd()
              
              self.GroupBegin(id=10002, flags=c4d.BFH_SCALEFIT, cols=1, rows=1, title="File")
              self.AddStaticText(id=1003, flags=c4d.BFH_CENTER, initw=0, inith=20, name="File")       
              self.AddComboBox(id=1004, flags=c4d.BFH_SCALEFIT, initw=200, inith=20)
              
              self.GroupEnd()
              
              self.GroupBegin(id=10003, flags=c4d.BFH_SCALEFIT, cols=1, rows=1)
              self.AddSeparatorV(initv=200, flags=c4d.BFH_SCALEFIT)               
              self.AddButton(id=1005, flags=c4d.BFH_SCALEFIT,  initw=200, inith=20, name="Add")
              self.GroupEnd()
              
              self.GroupEnd()
              
              return True
        
          def Command(self, id, msg) :
        
              if (id == GRP_COMBOX) :
              
                  if (self.GetInt32(GRP_COMBOX) == CHILD_VALUES) :
                      
                      childSelected = self.GetInt32(GRP_COMBOX) #<---- Get the comboBox value here
        
                      # Here to get value for folderSelected??
                                                   |
                                                   V
                      for file in listFiles(folderSelected) :
                          self.AddChild(id=1004, subid=1012, child=file)
                          
                      return True
                  
              
      class eXpressoMakerPlugin(plugins.CommandData) :
        
          dialog = None
          
          # Creates the dialog
          def Execute(self, doc) :
          
              if self.dialog is None:
                  self.dialog = eXpressoMakerDialog()
                
              return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=200, defaulth=150, xpos=-1, ypos=-1)
          
          # Manages the dialog
          def RestoreLayout(self, sec_ref) :
        
              if self.dialog is None:
                  self.dialog = eXpressoMakerDialog()
                
              return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)
              
      if __name__ == "__main__":
       
          okyn = plugins.RegisterCommandPlugin(PLUGIN_ID, "eXpresso Maker v1.0", 0, None, "eXpresso Maker v1.0", eXpressoMakerPlugin())
          
          if (okyn) :
              print "eXpresso Maker v1.0 Loaded!"
      

      Thank you very much in advance with your help!

      Andre

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

        On 13/11/2017 at 01:44, xxxxxxxx wrote:

        Hello and welcome,

        when you are creating the combo box you are assigning each child the same subid (see AddChild()). This is wrong; each child needs it's own subid. This subid is returned when you access the current value of the combo box with GetInt32(). You find an example in the C++ gedialog_gadgets.cpp dialog.

        To get the selected folder or file you can simply store the list returned by your appropriate sub-function as a member of your dialog class. Then you can store the corresponding index as the subid of the child. When you get the currently selected child with GetInt32() this would return the index you need to use to get the correct string from the stored list.

        Also, please do not cross post your questions on multiple forums or at least include a link to your cross posts. This helps everyone to avoid unnecessary work.

        best wishes,
        Sebastian

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

          On 13/11/2017 at 01:50, xxxxxxxx wrote:

          Hi Sebastian,

          Thank you very much for the welcoming and quick reply! 🙂

          I see what you mean and makes total sense.

          Apologies for cross posting.

          Have a great day!

          Cheers!

          Andre

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