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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Randall Hess randall.hess@gmail.com | |
// Instructions: Copy this file over your local maya version to override the default behavior | |
// Maya 2022 and Higher | |
// Additional: You can also build and load this as a module and not overwrite the local maya file. | |
// Location: C:\Program Files\Autodesk\MayaXX\scripts\others\performFileDropAction.mel | |
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 $gOperationMode; | |
string $save_gOperationMode = $gOperationMode; | |
$gOperationMode = "Open"; | |
int $result = performFileAction ($theFile, 1, ""); | |
$gOperationMode = $save_gOperationMode; | |
return ($result); | |
} | |
else if ($response == $import) | |
{ | |
file -import -namespace (basenameEx($theFile)) $theFile ; | |
return(1); | |
} | |
else if ($response == $reference) | |
{ | |
file -reference -namespace (basenameEx($theFile)) $theFile ; | |
return(1); | |
} | |
} |
Great tip, am going to integrate this!
ReplyDelete(you've missed a ; on line 41)
Indeed!
DeleteI was hastily modifying code on the fly. This has been corrected.
DeleteThanks!
Thanks for sharing, i modified it a bit so user can input namespace when using import or reference.
ReplyDeleteglobal 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);
}
}
That's a good addition.
DeleteThanks Randall! The Open command doesn't work for me, it just returns "Result: 0" The other options work as they should.
ReplyDeleteMaybe it's a Maya 2020 thing?
Turns out it works if only I first open a file through the standard Open File dialogue.
Delete