//ChangeFilePath // // Date: 2004/01/06 // Author: Dai Sato dstruevision@dstruevision.com http://www.dstruevision.com // Procedure Name: RenameFileExtension // // Description: This scripts enable you to change file extension and reload files // after you converted file textures to another format with other application like Photoshop. // How to use: Just type RenameFileExtension in comand line, then select extension and press rename button. proc string extractFileName(string $path) { string $tokens[]; int $numTokens = `tokenize $path "/" $tokens`; return $tokens[$numTokens-1]; } proc string extractExtension(string $extractedFilename) { string $tokens[]; int $numTokens = `tokenize $extractedFilename "." $tokens`; return $tokens[$numTokens -1]; } proc string cutExtension(string $fileName) { string $tokens[]; string $noExtension =""; string $buffer = ""; int $numTokens = `tokenize $fileName "." $tokens`; for ($i=$numTokens-2;$i>=0;$i--) { $noExtension = ($tokens[$i] + "." + $buffer); $buffer = $noExtension; } return $noExtension; } proc string returnDir(string $path) { string $tempFilePath = ""; string $buffer = ""; string $tokens[]; int $numTokens = `tokenize $path "/" $tokens`; for ($i=$numTokens-2;$i>=0;$i--) { $tempFilePath = ($tokens[$i] + "/" + $buffer); $buffer = $tempFilePath; } return $tempFilePath; } global proc renameExtension () { $textureNodes = `ls -typ file`; $progressMax = size($textureNodes); if($progressMax != 0) { progressBar -edit -beginProgress -isInterruptable true -status "Calculation ..." -maxValue $progressMax mainProgressBar; print ($progressMax+"\n"); for ($node in $textureNodes) { string $fullFileName = `getAttr($node+".fileTextureName")`; string $fileName = extractFileName($fullFileName); string $extension = extractExtension($fileName); string $fileDir = returnDir($fullFileName); string $cutFilename = cutExtension($fileName); string $newExtension = `radioCollection -q -sl selectedExtension`; string $newFileName = $fileDir+$cutFilename+$newExtension; print ($newFileName+"\n"); setAttr -type "string" ( $node + ".fileTextureName") $newFileName; progressBar -edit -step 1 mainProgressBar; } progressBar -edit -endProgress mainProgressBar; } } global proc RenameFileExtension () { global int $progressMax = 10; if ((`window -ex RenameFileWindow`) == true) deleteUI RenameFileWindow; window -t "RenameFileExtension" -s true -mnb true -mxb true -mb true -w 100 -h 200 RenameFileWindow; columnLayout; frameLayout -label "Extension"; columnLayout; text -l "please select renaming extension"; radioCollection selectedExtension; radioButton -label "gif" gif; radioButton -label "jpg" jpg; radioButton -label "iff" iff; radioButton -label "rla" rla; radioButton -label "sgi" sgi; radioButton -label "pic" pic; radioButton -label "tga" tga; radioButton -label "tif" tif; radioButton -label "bmp" bmp; radioButton -label "bot" bot; radioButton -label "map" map; setParent ..; setParent ..; radioCollection -edit -select gif selectedExtension; columnLayout -rs 3; progressBar -width 150 -height 10 mainProgressBar; rowColumnLayout -numberOfRows 1; button -l "Rename" -w 50 -h 30 -c "renameExtension()"; button -l "Undo" -w 50 -h 30 -c "undo"; window -e -w 175 -h 280 RenameFileWindow; showWindow; }