[Closed] 100 scene file?
hi all, I’m just wondering if theres a easy way on doing this…my problem is let say I’ve got 100 max scene file and maybe I need to set up something (scale or move my object…etc) on each file is there a command to tell Max to open each file and modify that object and then save that file again?..this is how I would do it in Maya:
global proc gdp_newNames()
{
global string $targetDirectory;
string $path = $targetDirectory;
string $tempPath = gdp_currentSceneName();
string $command = ("global proc nn_renameGamePath()
{
string $files[] = ls -type \"file\"
;
for ($file in $files)
{
int $nTokens = 0;
string $buff[0];
string $originalPath = `getAttr ($file + \".fileTextureName\")`;
$nTokens = `tokenize $originalPath \"//\" $buff`;
changeGameDir($nTokens, $file, $buff);
}
}
global proc changeGameDir(int $nTokens, string $file, string $dummy[])
{
string $pathSource = ” + $tempPath + “;
string $sourceImagePath = fromNativePath($pathSource);
string $fileName = ($dummy[$nTokens – 1]);
setAttr -type \"string\" ($file + \".fileTextureName\") ($sourceImagePath + $fileName);
}
nn_renameGamePath();”);
string $buffer[0];
string $sceneName[0];
string $allFolders = system("dir \"" + $path + "\*.mb\" /b")
;
int $nTokens = `tokenize $allFolders "
” $buffer`;
for ($i = 0; $i < $nTokens; $i++)
{ $sceneName[$i] = `strip $buffer[$i]`; }
string $native = fromNativePath($path);
for ($i = 0; $i < $nTokens; $i++)
{
file
-f
-options "v=0"
-typ "mayaBinary"
-o ($native + $sceneName[$i]);
if (!`objExists ($sceneName[$i] + "_script")`)
{ string $nodeName = `scriptNode -st 2 -bs $command -n ($sceneName[$i] + "_script")`; }
print($sceneName[$i] + "
“);
SaveScene;
}
}
This script basically opens all the Maya Binary files in the specified directory and it adds a sciptNode to the scene. Next time you open up those files the scriptNode will run and it will look for the correct path of the textures. So basically what I want is to tell Max to open all the files and modify something on each files then save it again.
Thanks All
Originally posted by Technofreak
[B]hi all, I’m just wondering if theres a easy way on doing this…my problem is let say I’ve got 100 max scene file and maybe I need to set up something (scale or move my object…etc) on each file is there a command to tell Max to open each file and modify that object and then save that file again?..this is how I would do it in Maya:…lots of hard to read code removed…
So basically what I want is to tell Max to open all the files and modify something on each files then save it again.
Thanks All [/B]
Behold the beauty of MAXScript! :wavey:
–Here is the basic body of a max file batch-processing script
–What will be done to the files depends on you – place your
–code inside the loop and you are set.
thePath = getSavePath() –get a path dialog to specify the path
if thePath != undefined do –if the user did not cancel
(
theFiles = getFiles (thePath+”\*.max”) –collect all max files in the dir.
for f in theFiles do –go through all of them
(
loadMaxFile f –load the next file
–do some scripted stuff here,
–or register a persistent callback script
–to execute next time the file is opened…
saveMaxFile f –save the file back to disk
)–end f loop
resetMaxFile #noPrompt –at the end, you can reset
)–end if
–Alternatively, you could use the path of the currently open scene:
thePath = maxFilePath
if thePath != “” do –if there is a scene loaded, the path will not be empty
(
–and so on, same as above…
Hope this helps.
Btw, I am exposing myself to MEL script right now and it is good to see some comparison between the ways to do the same in both packages. The question about “which is better” is often seen on these forums, and my usual answer is that MEL is deeper, while MAXScript is friendlier…
Cheers,
Bobo