Python 如何使用Mel在maya中查找上次导入的文件路径和名称?

Python 如何使用Mel在maya中查找上次导入的文件路径和名称?,python,maya,mel,Python,Maya,Mel,我希望在Maya中存储上次导入文件的信息。 因此,当我拖放文件时,它将存储文件路径和文件名。因此,当您打开脚本编辑器时,您可以打开History/Echo all commands,查看在Maya中执行操作时调用了哪些函数。在您的情况下,将文件放入Maya时会调用函数performFileDropAction(字符串$theFile) 包含此函数代码的文件位于我的计算机上(我使用的是Maya 2014):C:\Program Files\Autodesk\Maya2014\scripts\oth

我希望在Maya中存储上次导入文件的信息。
因此,当我拖放文件时,它将存储文件路径和文件名。

因此,当您打开脚本编辑器时,您可以打开
History/Echo all commands
,查看在Maya中执行操作时调用了哪些函数。在您的情况下,将文件放入Maya时会调用函数
performFileDropAction(字符串$theFile)

包含此函数代码的文件位于我的计算机上(我使用的是Maya 2014):
C:\Program Files\Autodesk\Maya2014\scripts\others\performFileDropAction.mel

我修改了
performFileDropAction(string$theFile)
以将所需信息保存在
MAYA\u APP\u DIR
中的文本文件中
MAYA_APP_DIR
是一个环境变量,包含指向文档和设置MAYA文件夹的路径。在我的计算机上:
C:\Users\myName\Documents\maya

保存信息的
lastImportedFile.txt
包含以下内容:

C:/Path/To/My/Scene/Folder/
My_Scene.ma
您可以将
performFileDropAction(字符串$theFile)
代码替换为以下代码:

注意:我不是mel程序员,我花了5分钟才弄明白如何将字符串转换为数组。。。因此,此代码可能会得到改进。”

global proc int
performFileDropAction(字符串$theFile)
{
全局字符串$gv_操作模式;
字符串$save_gv_operationMode=$gv_operationMode;
$gv_operationMode=“导入”;
int$result=performFileAction($theFile,1,“”);
$gv\U操作模式=$save\U gv\U操作模式;
////////////////////////////////////////////////////////////////
//修改后的代码从这里开始
字符串$sceneArray[];//分割的场景数组
字符串$sceneFolder=”“;//您的场景文件夹
字符串$sceneName=“;//您的场景名称
$sceneArray=stringToStringArray($theFile,“/”);
//在数组中循环

对于($i=0;$i此处/您希望如何存储信息?
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);
}