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

    TreeView DropDown Menu

    Cinema 4D SDK
    3
    3
    828
    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.
    • S
      simonator420
      last edited by simonator420

      Hi, it may be a foolish task but I would like to have different value in each row after I make the selection in the dropdown menu. This way it displays same value for every row. Could you help me with that?

      class ListView(c4d.gui.TreeViewFunctions):
       
          def __init__(self):
              self.selectedEntry = 1000
      
          def GetDropDownMenu(self, root, userdata, obj, lColumn, menuInfo):
              doc = c4d.documents.GetActiveDocument()
              menuInfo["entry"] = self.selectedEntry
              menuInfo["menu"][1000] = "Material 1"
              menuInfo["menu"][1001] = "Material 2"
              menuInfo["menu"][1002] = "Material 3"
              menuInfo["menu"][1003] = "Material 4"
              menuInfo["state"] = int(menuInfo["state"])
      
          def SetDropDownMenu(self, root, userdata, obj, lColumn, entry):
              self.selectedEntry = entry
              print(f"User selected the entry with the ID: {entry}")
      
      
      1 Reply Last reply Reply Quote 0
      • M
        mogh
        last edited by

        Hi @simonator420,

        you use the same ID for each row I guess, in your code above you would need to ofset every row by a certain amount for the IDs

        I can not give you a working code from your snippet.

        self.selectedEntry = 1000 + offset
        

        kind regards,
        mogh

        ferdinandF 1 Reply Last reply Reply Quote 0
        • ferdinandF
          ferdinand @mogh
          last edited by ferdinand

          Hello @simonator420,

          Thank you for reaching out to us. As announced here, Maxon is currently conducting a company meeting. Please understand that our capability to answer questions is therefore limited at the moment.

          I am slightly confused about the nature of your questions, especially in the context of the reply from @mogh. TreeViewFunctions.GetDropDownMenu lets you define the content of drop down menus in a TreeView, and the slightly ill named SetDropDownMenu lets you react to an item being selected in such menu.

          The 'problem' with your code snippet is that you do not differentiate the drop down gadgets which are set in GetDropDownMenu. Like many methods of TreeViewFunctions it is called for each cell in the tree view table, where lColumn denotes the column as defined in your TreeViewCustomGui.SetLayout call, and obj denotes an item in your root, so sort of the row in the tree.

          lColumn becomes meaningless when your tree view has only one column of type LV_DROPDOWN. How to make sense of obj, depends on the shape of the data you passed as root. When root root is just a list[object], you could for example alternate between even and odd rows like this.

          def GetDropDownMenu(
              self, root: list[object], userdata: any, obj: object, lColumn: int, menuInfo: dict):
              """Simple example for defining the menu content based on the position of #obj in #root.
              """
              index: int = root.index(obj)
              if index % 2 == 0:
                  menuInfo["menu"][1000] = "Even row first option"
                  menuInfo["menu"][1001] = "Even row second option"
              else:
                  menuInfo["menu"][1000] = "Odd row first option"
                  menuInfo["menu"][1001] = "Odd row second option"
          
              menuInfo["state"] = int(menuInfo["state"])
          

          In practice, the content of a drop down is more likely to be determined based on the fields of obj (e.g., if obj.a == "foo" then Menu1 else Menu2)rather than its relative position in root (be it a list-like or tree-like data structure).

          Cheers,
          Ferdinand

          MAXON SDK Specialist
          developers.maxon.net

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