I am looking to store information of the last imported file in Maya. So when I drag and drop a file it will store file path and filename.
-
Where/How do you want the information to be stored? – DrHaze Mar 09 '15 at 13:13
1 Answers
So when you open you script editor, you can toogle History/Echo all commands
on to see which functions are called when doing stuff in Maya. In your case, the function performFileDropAction (string $theFile)
is called when you drop a file into Maya.
The file containing the code for this function is located here on my computer (I'm using Maya 2014): C:\Program Files\Autodesk\Maya2014\scripts\others\performFileDropAction.mel
I've modified the performFileDropAction (string $theFile)
to save the information you desire in a text file in the MAYA_APP_DIR
. MAYA_APP_DIR
is an environment variable containing the path to your Documents&Settings Maya folder. On my computer: C:\Users\myName\Documents\maya
The lastImportedFile.txt
where I save the informations contains this:
C:/Path/To/My/Scene/Folder/
My_Scene.ma
You can replace the performFileDropAction (string $theFile)
code with the following:
Note: I'm not a mel programmer, it took me 5 minutes to figure out how to convert a string to an array... So this code can probably be improved"
global proc int
performFileDropAction (string $theFile)
{
global string $gv_operationMode;
string $save_gv_operationMode = $gv_operationMode;
$gv_operationMode = "Import";
int $result = performFileAction ($theFile, 1, "");
$gv_operationMode = $save_gv_operationMode;
////////////////////////////////////////////////////////////////
// Modified code starts here
string $sceneArray[]; // Splitted scene array
string $sceneFolder = ""; // Your scene folder
string $sceneName = ""; // Your scene name
$sceneArray = stringToStringArray ($theFile , "/");
// loop through the array
for($i=0;$i<size($sceneArray);++$i) {
if($i == size($sceneArray)-1){
$sceneName = $sceneArray[$i];
}else{
$sceneFolder += $sceneArray[$i] + "/"; // Recreate the scene folder
}
}
// Create A String Array With you data
string $myStrArray[] = {$sceneFolder, $sceneName};
// Save your file in Documents and Settings
string $filePath = `getenv MAYA_APP_DIR` + "/lastImportedFile.txt";
// Open Your File in write mode
$fileId = `fopen $filePath "w"` ;
// Print Array To File
for($line in $myStrArray)
fprint $fileId ($line+"\n") ;
// Close File
fclose $fileId ;
////////////////////////////////////////////////////////////////
return ($result);
}
Note:
Your can modify pretty much every Maya's menus and option this way but be carefull when modifying Maya's mel scripts. Don't do stupid things or you'll have to reinstall Maya.

- 1,318
- 10
- 22