Sunday, August 19, 2018

Maya Override Drag & Drop Behavior


A friend of mine recently pointed out that you can change the default behavior of Maya's drag and drop files. I generally have not used this workflow but upon changing how it handles the open conditions, I have found drag and dropping far more useful recently.




I have changed the local Maya file performFileDropAction.mel, from exclusively choosing to do a file import, to giving the user the options they wish to perform.

You can find the original file in  C:\Program Files\Autodesk\Maya20XX\scripts\others\performFileAction.mel





Proper Distribution:
The best implementation of this updated procedure would of course be to package the modified code into a module. This is a far more reasonable approach for distribution if you need to roll out to a team. If you need more information on this process, check out Steve Theodore's article on Maya modules.


Here is a brief walk through of how the new behavior works & the updated code can be found below.









5 comments:

  1. Great tip, am going to integrate this!

    (you've missed a ; on line 41)

    ReplyDelete
    Replies
    1. I was hastily modifying code on the fly. This has been corrected.
      Thanks!

      Delete
  2. Thanks for sharing, i modified it a bit so user can input namespace when using import or reference.
    global proc string namespaceInput()
    {
    string $text;
    string $result = `promptDialog
    -title "Namespace"
    -message "Namespace input:"
    -button "OK" -button "Cancel"
    -defaultButton "OK" -cancelButton "Cancel"
    -dismissString "Cancel"`;

    if ($result == "OK") {
    $text = `promptDialog -query -text`;
    return $text;
    }

    }



    global proc int
    performFileDropAction (string $theFile)
    {
    string $msg = "Would you like to Import, Open or Reference the file?";
    string $import = "Import";
    string $open = "Open";
    string $reference = "Reference";
    string $cancel = "Cancel";
    string $response = `confirmDialog -message $msg -button $import -button $open -button $reference -button $cancel -defaultButton $cancel`;
    if ($response == $cancel)
    {
    return(1);
    }
    else if ($response == $open)
    {
    global string $gv_operationMode;
    string $save_gv_operationMode = $gv_operationMode;
    $gv_operationMode = "Open";
    int $result = performFileAction ($theFile, 1, "");
    $gv_operationMode = $save_gv_operationMode;
    return ($result);
    }
    else if ($response == $import)
    {
    file -import -namespace (basenameEx(namespaceInput())) $theFile ;
    return(1);
    }
    else if ($response == $reference)
    {
    file -reference -namespace (basenameEx(namespaceInput())) $theFile ;
    return(1);
    }

    }

    ReplyDelete