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 adding a new item as an child

    Cinema 4D SDK
    python r20
    3
    4
    970
    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.
    • P
      pim
      last edited by

      I have seen the excellent post of Maxime about creating a Treeview.
      See https://developers.maxon.net/forum/topic/10654/14102_using-customgui-listview/2

      There is an Add button, but now I want to add it as a child.

      I added a Insert Under button with following code in Command().

              if id == 1002:
                  # Insert Under
                  tex = TextureObject("Inserted under first item.")
                  first = self._listView.GetFirst(self._treegui, self._listView)
                  
                  #InsertObject(self, root, userdata, obj, dragtype, dragobject, insertmode, bCopy):
                  self._listView.InsertObject(self._treegui, self._listView, first, c4d.DRAGTYPE_FILENAME_OTHER, tex, c4d.INSERT_UNDER, True)
                  
                  # Refresh the TreeView
                  self._treegui.Refresh()
      

      And in class ListView(c4d.gui.TreeViewFunctions) I added

          def GetFirst(self, root, userdata):
              rValue = None if not self.listOfTexture else self.listOfTexture[0]
              return rValue
      
          def InsertObject(self, root, userdata, obj, dragtype, dragobject, insertmode, bCopy):
              return True
      

      But nothing is inserted.
      I think it is because of InsertObject(), because nothing is inserted in the _listView.
      So, how to insert it as a child?

      -Pim

      1 Reply Last reply Reply Quote 0
      • r_giganteR
        r_gigante
        last edited by

        Hi Pim thanks for reaching out us.

        With regard to your request, rather than implementing TreeViewFunctions::InsertObject() you should take care of implementing a TreeViewFunctions::GetDown() and also to redesign the data type being responsible to store the TreeView items and their children.

        In the case presented by @m_adam a simple list was used and this was sufficient for the scope of representing a one-level tree. Also accessing the next/prev items was done by searching for the index of a given item in the list which turned to be quick and slick.

        Last but not least it's also relevant to implement a TreeViewFunctions::Open()and TreeViewFunctions::IsOpened() in order to properly manage the folding/unfolding functionality otherwise your tree might appear always folded

        Hope these few notes can lead you through the right direction.

        Best, Riccardo

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

          I'd like to add that using GeListNode and GeListHead is convenient since they already come with all functions you need.

          r_giganteR 1 Reply Last reply Reply Quote 0
          • r_giganteR
            r_gigante @mp5gosu
            last edited by

            @mp5gosu this completely makes sense and it's indeed a valuable recommendation but I wasn't sure about Pim's requirement here on deriving from Cinema 4D base classes.

            Cheers, R

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