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

    Issue with Separators in "ShowPopupDialog"[SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 504 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 24/11/2016 at 07:55, xxxxxxxx wrote:

      Hello fellow programmers,

      I want to add a number of separators for a popup menu that I'm implementing in order to group the menu into different sections.
      The first separator shows up fine, but the next one is omitted. Not sure if this is just a limit of the PopupDialog or if I'm doing something wrong.

      Example code as follows:

      import c4d
        
      def main() :
          bc = c4d.BaseContainer()
          bc.SetString(c4d.FIRST_POPUP_ID+5, "Popup Menu 1...")
          bc.SetString(c4d.FIRST_POPUP_ID+1, "Popup Menu 2...")
          bc.SetString(c4d.FIRST_POPUP_ID+2, "Popup Menu 3...")
          bc.SetString(0, "") 
          bc.SetString(c4d.FIRST_POPUP_ID+3, "Popup Menu 4...")
          bc.SetString(0, "") 
          bc.SetString(c4d.FIRST_POPUP_ID+4, "Popup Menu 5...")
          bc.SetString(c4d.FIRST_POPUP_ID, "Popup Menu 6...")
          
          result = c4d.gui.ShowPopupDialog(cd=None, bc=bc, x = c4d.MOUSEPOS, y = c4d.MOUSEPOS, flags = c4d.POPUP_CENTERHORIZ) - c4d.FIRST_POPUP_ID
          
        
      if __name__=='__main__':
          main()
      

      Like I said, the separator after "Popup Menu 3..." shows up but the next one doesn't.
      Hopefully someone can clarify the situation.

      Thanks
      Jo

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

        On 25/11/2016 at 00:15, xxxxxxxx wrote:

        Hello,

        you are calling SetString(0, "") twice. This will do the same thing twice: storing an empty string at ID 0. So the second time when you call SetString(0, "") you are just overwriting the existing entry, you are not adding anything.

        You can add an element to a BaseContainer using InsData () which will add an element independent of the given ID. It is probably recommended to use InsData () with such BaseContainers.

          
        bc = c4d.BaseContainer()  
        bc.InsData(c4d.FIRST_POPUP_ID+1, "Popup Menu 1...")  
        bc.InsData(0, "")   
        bc.InsData(c4d.FIRST_POPUP_ID+2, "Popup Menu 2...")  
        bc.InsData(0, "")   
        bc.InsData(c4d.FIRST_POPUP_ID+3, "Popup Menu 3...")  
        

        best wishes,
        Sebastian

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

          On 25/11/2016 at 01:32, xxxxxxxx wrote:

          Hi Sebastian, thank you for the help! This works perfectly, even though I have to admit that I still don't fully understand how BaseContainers function.
          If BaseContainer takes the data sequentially, shouldn't the second separator (overwriting the first one) be the one that shows up? What is InsData doing differently, so that the IDs don't get overwritten?

          Guess I have to look more into the technicalities of that class.

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

            On 28/11/2016 at 00:49, xxxxxxxx wrote:

            Hello,

            SetString() and InsData() are two different functions that do two different things. SetString() would overwrite an element with the given ID. InsData() adds another element with the given ID:

              
            bc = c4d.BaseContainer()  
              
            bc.SetString(0, "Some String A")  
            bc.SetString(0, "Some String A")  
              
            print("Print Elements:")  
              
            for element in bc:  
              print(element)  
              
            bc.FlushAll()  
              
            bc.InsData(0, "Some String B")  
            bc.InsData(0, "Some String B")  
              
            print("Print Elements:")  
              
            for element in bc:  
              print(element)  
            

            For questions no longer related to this thread's topic please open a new thread. Thanks.

            best wishes,
            Sebastian

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

              On 29/11/2016 at 05:16, xxxxxxxx wrote:

              Hi Sebastian,
              thank you for clearing that up. Initially i thought BaseContainers worked like a dictionary, with the indices being the keys. Apparently it is more like a list, with the get/set methods using it as a quasi dictionary.
              What I noticed though, is that the get/set methods only take the first occurrence of any index into account.

              import c4d
                
              bc = c4d.BaseContainer()
                
              bc.InsData(0, "Some String")
              bc.InsData(0, "Some String")
              bc.SetString(0, "Some New String")
                
              print("Print Elements:")
                
              for element in bc:
                  print(element)
                  
              print bc.GetString(0) 
              

              In any case, my initial question was fully answered and i feel a little smarter now. 🙂
              Thanks for your help.

              Best
              Jo

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