Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
I have User Area with some images. Now I want to drag&drop one of those images in the UA to a Gui field, so I can get the filename of the chosen image. Something like this. .
Questions:
Hope you can help me with a example.
-Pim
Hi @pim you have to use GeUserArea.HandleMouseDrag.
Here an example for file.
import c4d class DraggingArea(c4d.gui.GeUserArea): def InputEvent(self, msg): filePath = "MySuperPath" self.HandleMouseDrag(msg, c4d.DRAGTYPE_FILENAME_IMAGE, filePath, 0) return True class MyDialog(c4d.gui.GeDialog): """ Creates a Dialog with only a GeUserArea within. """ def __init__(self): # It's important to stores our Python implementation instance of the GeUserArea in class variable, # This way we are sure the GeUserArea instance live as long as teh GeDialog. self.area = DraggingArea() print "droped" def CreateLayout(self): """ This method is called automatically when Cinema 4D Create the Layout (display) of the Dialog. """ self.AddUserArea(1000, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT) self.AttachUserArea(self.area, 1000) return True def main(): # Creates a new dialog dialog = MyDialog() # Opens it dialog.Open(dlgtype=c4d.DLG_TYPE_MODAL_RESIZEABLE, defaultw=500, defaulth=500) if __name__ == '__main__': main()
In any case, I will extend the python documentation to have all information about each type but here a summary:
DRAGTYPE_FILES
DRAGTYPE_FILENAME_SCENE
DRAGTYPE_FILENAME_OTHER
DRAGTYPE_FILENAME_IMAGE You should pass a string.
DRAGTYPE_ATOMARRAY A list of c4d.C4DAtom object
DRAGTYPE_DESCID A dict {"did": the c4d.DescID, "arr": a list of c4d.C4DAtom object}
DRAGTYPE_RGB A c4d.Vector
DRAGTYPE_RGB_ARRAY A list of c4d.Vector
DRAGTYPE_RGBA_ARRAY A maxon.BaseArray(maxon.ColorA)
Other types are not supported.
Cheers, Maxime.
Yes, it works great.
Some questions:
does HandleMouseDrag() now replace MouseDrag(), MouseDragStart() and others.
how to get the mouse coordinates where the drag started. Or better, I will have some pictures in the UA, how to know which picture is being dragged&dropped?
where and when to call self.SetDragDestination(c4d.MOUSE_CROSS). Just before HandleMouseDrag in InputEvent()?
HandleMouseDrag() is in the UA InputEvent(). For which message ID should I look before starting HandleMouseDrag(). In my InputEvent() function also other messages are handled.
Correct, You can then process this as a standard Cinema 4D drag operation and react to BFM_DRAGRECEIVE in your GeUserArea Message method.
You can retrieve it from BFM_INPUT_X and BFM_INPUT_Y
def InputEvent(self, msg): mouseX = msg[c4d.BFM_INPUT_X] mouseY = msg[c4d.BFM_INPUT_Y]
As you will do in a normal drag process so in your Message method override.
InputEvent is only called with BFM_INPUT, so if you want to do something before handling the drag, then do it previously and avoid HandleMouseDrag.
Hope it helps, Cheers, Maxime.
@pim I'm trying to figure out how you did this. Could you please share a sample code of this example? I'm trying to get the full path of an image by dragging it into a edit text field...
Cheers