View Full Version : drag'n'drop Callback - HOWTO?

12 December 2003, 12:07 AM
has anyone ever fiddled around with the dragCallback- and/or dropCallback-flags one can attach to a lot of MEL commands?

does anyone have put them to any good usage, and/or can provide examples e.g. hints to manual-pages or example-code?

by the looks and sounds of it it's something i could really use right now, but i have no clue whatsoever on how to do that.


12 December 2003, 04:19 PM
This reply is by Gary Fixler from an old thread on the Maya mailing list.


Drag and drop controls can be a little confusing. Most controls have
drag and drop flags, so rather than explain the intricacies of using
them with the scriptTable, I'll just give you this brief example, then
a quick description of what you're seeing:


// define the drag control function
global proc string[] testDrag
(string $drag, int $x, int $y, int $mods) {
print ("------------------------------\n");
print ("dragging (" + $drag + ")\nfrom position " + $x + ", " + $y);
print ("\n------------------------------\n");
string $messages[] = {"your", "message(s)", "here"};
return $messages;
// define the drop control function
global proc testDrop
(string $drag, string $drop, string $msgs[], int $x, int $y, int $mods) {
print ("dropped (" + $drag + ")\nonto (" + $drop + ")\n");
print ("at position " + $x + ", " + $y + "\n");
print ("------------------------------\n");
print ("messages =\n");
print ($msgs);
// make a window w/ 2 buttons that can use drag and drop functions
window -rtf 1 testWin;
columnLayout -adj 1;
-w 150
-dgc testDrag
-dpc testDrop;
-w 150
-dgc testDrag
-dpc testDrop;
showWindow testWin;


Run that and you'll see a window with two generic buttons that do
nothing. Notice in the MEL here, how each of them is calling the same
drag and drop controls (testDrag/testDrop), which I defined up top.
When you middle mouse on either button, it fires off the testDrag
callback. It also passes it arguments. $drag gets the name of the
control (button) you middle moused on, $x and $y tell where, relative
to that control, you clicked on it, and $mods will be an int from 0 to
3, each of which indicates if no key, shift, control, or shift and
control were held down when you middle-clicked on the button,
respectively. Also note that the proc is of type string[]. That means
it returns a string array, which I've done with an example ("your
message(s) here"). This array gets passed to the testDrop callback
if and when it's called.

testDrop gets called whenever you release the middle mouse over either
of these buttons, since we set the -dpc flag to testDrop. The string[]
that testDrag returned gets passed into this proc via the $msgs[]
array, and you can see that my testDrop proc prints those messages out
at the end ("your message(s) here"). You also get both the drag
control name, and the drop control name, and the x and y of wherever
you dropped, relative to the drop control. Finally, you get another
$mods int to tell which, if any modifier keys were being held down
when you dropped.

Leave your script editor open as you drag and drop the buttons on one
another, and you'll see my debug info print out - that should help
clear up things for you. You can use this little script to poke around
a bit. Drag a layer name from the layer panel onto a button, and
you'll see the full pathname print out, and the message sent by the
layer's drag control (which for me just says:


Anyway, hope that helps - you get tons of control over your scripts
for easy user interface with drag/drop. You can add -dgc and -dpc to
tons of things in Maya, including shelf buttons, shelves, the controls
in your windows layouts, and even the actual layouts themselves, like
columnLayout, etc. Neat stuff.

12 December 2003, 11:09 PM
hey CaptainSam,


it's all a lot clearer now!
I'm glad you remember your shit such a long way back!


CGTalk Moderation
01 January 2006, 10:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.