Pass a number to an Atom file import command (MEL)


#1

This should be simple but I can’t seem to figure it out.

Say I have a command to import animation using ATOM, and it reads like this :


   file -import -type "atomImport" -ra true -namespace "atomTest2" -options ";;targetTime=1;time=1:12;option=replace;match=hierarchy;;selected=selectedOnly;search=;replace=;prefix=;suffix=;mapFile=F:/- - - Projects/- - iAnimate/Workshop_5_Assignment1/data/;" "C:/Users/Brian/Desktop/atomTest2.atom";

But if I want to script this and I want to be able to dynamically pass in start/end frames to it, how can I achieve that?

I’ve tried this :


   int $start=1;
   int $end=12;
   
   file -import -type "atomImport" -ra true -namespace "atomTest2" -options ";;targetTime=1;time=$start:$end;option=replace;match=hierarchy;;selected=selectedOnly;search=;replace=;prefix=;suffix=;mapFile=F:/- - - Projects/- - iAnimate/Workshop_5_Assignment1/data/;" "C:/Users/Brian/Desktop/atomTest2.atom";

Which gives me -// Error: line 1: Invalid time unit: $start:$end //

I’ve also tried sending it a string as in string $times=“5:12”;
but that doesn’t work either, I’ve also tried breaking up the quotes :


 int $start=1;
 int $end=12;
 
 file -import -type "atomImport" -ra true -namespace "atomTest2" -options ";;targetTime=1;time="($start+":"+$end)";option=replace;match=hierarchy;;selected=selectedOnly;search=;replace=;prefix=;suffix=;mapFile=F:/- - - Projects/- - iAnimate/Workshop_5_Assignment1/data/;" "C:/Users/Brian/Desktop/atomTest2.atom";
 

But that gives me a ‘too many arguments’ error.
I’m sure I’m just missing something obvious here, any help much appreciated, I have a ton of animation to get through and would really like to leverage Atom to automatically drop in cycles at specific points without having to use the ATOM import dialogue to speed things up.

Cheers,
Brian


#2
if (`window -exists DJYi`) deleteUI DJYi;
window -height 221 -width 388 -title "DJ一把死守" -rtf 1 DJYi;
    columnLayout -columnWidth 372 -height 198 -width 372;
        rowLayout -columnWidth2 80 275  -height 23 -numberOfColumns 3 -width 355;
            text -height 17 -label "文件夹路径:" -width 80;
            textField -height 23 -width 200 atomFilePath;
            button -label "Browse" -w 75 -command "browseFiles()";
            setParent ..;
        rowLayout -columnWidth1 224  -height 28 -numberOfColumns 1 -width 224;
            button -command "bianKa" -height 28 -label "开始变卡" -width 224;
            setParent ..;
    setParent ..;
showWindow DJYi;
proc bianKa(){
    //读取路径dirPath且改为可识别模式
    string $dirPath=`textField -q -tx atomFilePath`;
    //遍历atom
    string $projectFiles[] = `sak_getFiles $dirPath "*.atom" $projectFiles`;
    //
    //
    //代码循环主体
    //
    //
    for ($ff in $projectFiles){
        //获取文件本名,文件完整路径
        string $ffOriName=substituteAllString($ff, ".atom", "");
        string $ffFullPath=$dirPath+"/"+$ff;
        string $ffOutputPath=$dirPath+"/fbx/"+$ff;
        $ffOutputPath=substituteAllString($ffOutputPath, ".atom", ".fbx");
        //读取atom的起止时间
        string $filePath = $ffFullPath ;
        $fileId = `fopen $filePath "r"` ;
        string $nextLine = `fgetline $fileId` ;
        $nextLine = `fgetline $fileId` ;
        $nextLine = `fgetline $fileId` ;
        $nextLine = `fgetline $fileId` ;
        $nextLine = `fgetline $fileId` ;
        $nextLine = `fgetline $fileId` ;
        string $startTime = strip($nextLine) ;
        $startTime=substituteAllString($startTime, "startTime ", "");
        $sT=(int)$startTime;
        $nextLine = `fgetline $fileId` ;
        string $endTime = strip($nextLine) ;
        $endTime=substituteAllString($endTime, "endTime ", "");
        $eT=(int)$endTime;
        $resu=$eT-$sT;
        //
        //string $fileInPutMethon=";;targetTime=1;srcTime="+$startTime+":"+$endTime+";dstTime=0:"+$resu+";option=scaleInsert;match=hierarchy;;selected=selectedOnly;search=;replace=;prefix=;suffix=;";
        //
        select -r boneFBXASC0451 ;
        select -hi;
        file -import -type "atomImport" -ra true -namespace $ffOriName -options "suffix=;" $ffFullPath;
        currentUnit -time ntscf;
        playbackOptions -min $sT -max $eT;
        select -cl  ;
        select -r boneFBXASC0451 ;
        file -force -options "fbx" -typ "FBX export" -pr -es $ffOutputPath;
        select -cl  ;
        select -r boneFBXASC0451 ;
        select -hi;
        selectKey -add -k `ls -typ animCurve`;
        cutKey -animation keys -clear;
    }
}
proc browseFiles()
{
    textField -edit -text `fileDialog2 -fm 3` atomFilePath;
}
proc string[] sak_getFiles (string $dir, string $fType, string $allFiles[]){
    string $files[] = `getFileList -fld $dir -fs $fType`;
    return $files;
}

#3

Hope it is helpful for somebody. The code is in line 48