Solved Dragging an object from a treeview

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?


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?

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):

    def GenerateDragArray(self, root, userdata, obj):
        bs = c4d.BaseShader(c4d.Xbitmap)
        bs[c4d.BITMAPSHADER_FILENAME] = # 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.


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