//ChangeFilePath // // Date: 2004/01/30 // Author: Dai Sato dstruevision@dstruevision.com http://www.dstruevision.com // Procedure Name: ChangeFilePath // // Description: This scripts enable you to change file path. // For example, if you wanna change file path to relative one, just type sourceimages then press change button. // How to use: Just type ChangeFilePath 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 mySelectDir(string $folder,string $something) { string $selectedDir = (toNativePath($folder)); textField -e -tx $selectedDir CFP_newFilePath; } global proc myGetDir() { fileBrowserDialog -m 4 -fc "mySelectDir" -ft "omage" -an "Select Dir"; } global proc changeFilePath () { $textureNodes = `ls -typ file`; string $newFilePath = `textField -q -tx CFP_newFilePath`; string $path = fromNativePath($newFilePath); $progressMax = size($textureNodes); if($progressMax != 0) { progressBar -edit -beginProgress -isInterruptable true -status "Calculation ..." -maxValue $progressMax mainProgressBar; for ($node in $textureNodes) { string $fullFileName = `getAttr($node+".fileTextureName")`; string $fileName = extractFileName($fullFileName); string $newFileName = $path+"/"+$fileName; print $newFileName; setAttr ( $node + ".fileTextureName") -type "string" $newFileName; progressBar -edit -step 1 mainProgressBar; } progressBar -edit -endProgress mainProgressBar; } } global proc ChangeFilePath () { global int $progressMax = 10; global int $progressMax = 10; global int $progressMax = 10; string $nativeWD = `workspace -q -rd`; string $currentWD = toNativePath($nativeWD); string $defaultDir = $currentWD + "sourceimages"; workspace -dir $defaultDir; if ((`window -ex ChangeFileWindow`) == true) deleteUI ChangeFileWindow; window -t "ChangeFilePath" -s true -mnb true -mxb true -mb true -w 100 -h 200 ChangeFileWindow; columnLayout mainLayout; frameLayout -label "File Path"; columnLayout; text -l "please enter new file path"; rowColumnLayout -numberOfRows 1; textField -ed false -w 150 -tx "sourceimages" CFP_newFilePath; button -label "Dir" -c "myGetDir()"; setParent mainLayout; columnLayout -rs 3; progressBar -width 150 -height 10 mainProgressBar; rowColumnLayout -numberOfRows 1; button -l "Change" -w 50 -h 30 -c "changeFilePath()"; button -l "Undo" -w 50 -h 30 -c "undo"; window -e -width 250 -height 130 ChangeFileWindow; showWindow; }