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

    Dragging an object from a treeview

    Cinema 4D SDK
    r20 python
    2
    4
    604
    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 implemented a treeview and it is working great.
      I like to know whether it is possible to Drag&Drop an object (in this case a link to a image file) from the treeview to (for example) the color channel of a material in the Material Editor?

      ffc7c11a-73f2-46bc-a140-c3c1b66dd3cc-image.png

      1 Reply Last reply Reply Quote 0
      • P
        pim
        last edited by

        Or an easier request.
        I know I can drag objects to the treeview, but is it also possible to drag object from a treeview to (for example) a link field?

        Is there somewhere an example available?

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

          Hi, @pim Unfortunately from a TreeView to outside it's only possible to drag c4d.C4DAtoms and derived class.
          While GetDragType supports multiple types, it's not the case of GenerateDragArray which can only accept a list of C4DAtoms (in C++ it's a AtomArray, and it's from there the limitation comes) (Of course it can be your own BaseList2D registered with RegisterNodePlugin, but since other parts of Cinema 4D have no idea of what is this kind of BaseList2D, it will be accepted nowhere)

          So to drag from the outside, you need GetDragType to returns c4d.DRAGTYPE_ATOMARRAY

          And DragStart to let the treeView object be dragged by retuning c4d.TREEVIEW_DRAGSTART_ALLOW

          Finally in GenerateDragArray you return a list of C4DAtoms to be in the list.

              def GetDragType(self, root, userdata, obj):
                  return c4d.DRAGTYPE_ATOMARRAY
          
              def DragStart(self, root, userdata, obj):
                  return c4d.TREEVIEW_DRAGSTART_ALLOW | c4d.TREEVIEW_DRAGSTART_SELECT`
          
              def GenerateDragArray(self, root, userdata, obj):
                  bs = c4d.BaseShader(c4d.Xbitmap)
                  bs[c4d.BITMAPSHADER_FILENAME] = obj.name # Here I assume the custom TreeView item have a name parameter
          
                  elements = [bs]
          
                  return elements
          

          Note that the limitation only exists in Python as GenerateDragData is not available.

          Cheers,
          Maxime.

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

          1 Reply Last reply Reply Quote 1
          • P
            pim
            last edited by

            Thanks, sounds a bit complicated, so I have to give it some thoughts.
            For now, it is enough.

            -Pim

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