Controlling drag&drop using MSG_DESCRIPTION_CHECKDRAGANDDROP
-
Hello coders. Me again.
In a Python
ObjectData
plugin I added aLINK
parameter. I want allBaseObject
s except for the plugin object itself to be droppable in here. So I put this in my .res file:LINK OMYOBJECT_LINK { ACCEPT { Obase; } }
According to the documentation of
MSG_DESCRIPTION_CHECKDRAGANDDROP
I should listen to this message and if I want the drop to not be acceptable I should returnFalse
. So this is in my code:def Message(self, node: GeListNode, type: int, data: object) -> bool: if type == c4d.MSG_DESCRIPTION_CHECKDRAGANDDROP: return False return True
Just to try it out I always return
False
. And that's where my issue is: I can still drop any object in there. It is limited toBaseObject
s so theACCEPT { Obase; }
seems to work but returningFalse
seems to not prevent the user from dropping something in the link.What am I doing wrong?
I tried removing
ACCEPT { Obase; }
from the .res file to no effect.As an addition: How do I control what the picker of a
LINK
is allowed to pick? Since it's technically not a drag&drop action it should be something other thanMSG_DESCRIPTION_CHECKDRAGANDDROP
right? -
In addition to ACCEPT the LINK gui also has a REFUSE statement. You can use that to exclude your plugin ID.
Steve
-
Hello @spedler,
Thanks, this totally works.
However this refuses to take any of my plugin objects, while in the end I only want to refuse the current plugin object; I still want to be able to drag other instances of my plugin object in there.
So in the end I'd still like to solve this using advanced logic in the
MSG_DESCRIPTION_CHECKDRAGANDDROP
message.Best regards,
Daniel -
Hi @CJtheTiger, you were close regarding
MSG_DESCRIPTION_CHECKDRAGANDDROP
as written in the documentation, you need to set the value of the `resul field of the dictionary like so:def Message(self, node: c4d.GeListNode, type: int, data: object) -> bool: if type == c4d.MSG_DESCRIPTION_CHECKDRAGANDDROP: gadgetId = data["id"] dragedObj = data["element"] data["result"] = dragedObj != node return True return True
Cheers,
Maxime. -
Hi @m_adam,
thanks a lot, that did the trick.
To close this topic off here's a snippet to allow other objects but not the current object to be dropped in there:
def Message(self, node: GeListNode, type: int, data: object) -> bool: if type == c4d.MSG_DESCRIPTION_CHECKDRAGANDDROP: relevant_id = c4d.DescID(c4d.YOUR_PARAM) # Use the ID of the parameter of your object that you want to check. current_id: c4d.DescID = data['id'] if relevant_id.IsPartOf(current_id)[0]: dragged_element = data["element"] is_same_object = node == dragged_element data['result'] = not is_same_object return True return True
Cheers,
Daniel