Code not working inside of loop (works outside of loop)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have just started working with maxscript and I am trying to write a script that will loop through a set of .max files and calculate the longest dimension of the objects in the file. I have gotten code that will work correctly on a single file, but when I run it inside of a loop, the calculation of the longest dimension breaks.
Here is the code that works:
outputPath = "C:\Work\Data\ProductImages3DS"
file = (createFile "C://tmp.txt")
f = "C:\path\to\file.max"
inputFile = f
filename = getFilenameFile f
f = pathConfig.removePathLeaf f
styleNumber = getFilenameFile f
outputSubfolder = pathConfig.appendPath outputPath styleNumber
outputFile = pathConfig.appendPath outputSubfolder filename+"_.png"
print inputFile
loadMaxFile inputFile
max select all
group selection name:"tigger"
select $tigger
foo = maxOps.cloneNodes (selection as array) cloneType:#instance newNodes:&nnl #nodialog
select nnl
nnl[1].pos = [0, 0, 0]
select $tigger
max delete
bb = (length ($tigger001.max-$tigger001.min))/2
print bb
bb = bb as string
newline = "\r\n"
format bb to:file
format ", " to:file
format inputFile to:file
format newline to:file
Here is the code that doesn't work:
fn getFilesRecursive root pattern =
(
dir_array = GetDirectories (root+"/*")
for d in dir_array do
join dir_array (GetDirectories (d+"/*"))
my_files = #()
for f in dir_array do
join my_files (getFiles (f + pattern))
my_files
)
--get all .ms files from the folder c:/temp
--and all its subfolders:
modelPath = "C:\Work\Data\ProductModelsFiltered"
outputPath = "C:\Work\Data\ProductImages3DS"
file = (createFile "C://tmp.txt")
SetQuietMode true
for f in getFilesRecursive modelPath "*.max" do
(
inputFile = f
filename = getFilenameFile f
f = pathConfig.removePathLeaf f
styleNumber = getFilenameFile f
outputSubfolder = pathConfig.appendPath outputPath styleNumber
outputFile = pathConfig.appendPath outputSubfolder filename+"_.png"
-- Begin Rendering
print inputFile
loadMaxFile inputFile
max select all
group selection name:"tigger"
select $tigger
foo = maxOps.cloneNodes (selection as array) cloneType:#instance newNodes:&nnl #nodialog
select nnl
nnl[1].pos = [0, 0, 0]
select $tigger
max delete
bb = (length ($tigger001.max-$tigger001.min))/2
print bb
--bb = (ceil (bb/25))*25
--bb = bb as integer
bb = bb as string
newline = "\r\n"
format bb to:file
format ", " to:file
format inputFile to:file
format newline to:file
)
close file
Here is the resulting text file from the code that doesn't work:
0.0173205, C:\Work\Data\ProductModelsFiltered\172957\172957A2.max
0.0173205, C:\Work\Data\ProductModelsFiltered\172957\172957A3.max
0.0173205, C:\Work\Data\ProductModelsFiltered\172957\172957A4.max
0.0173205, C:\Work\Data\ProductModelsFiltered\172957\172957A5.max
0.0173205, C:\Work\Data\ProductModelsFiltered\172957\172957A6.max
0.0173205, C:\Work\Data\ProductModelsFiltered\172957\172957A7.max
0.0173205, C:\Work\Data\ProductModelsFiltered\172957\172957A8.max
The file names are updating but the dimension (first number) is way to small and doesn't change.
Any help would be appreciated