DougWells3D
01-29-2008, 03:44 PM
Hey guys,
I'm having a problem with an old maxscript here at work that someone wrote a while ago and he's no longer here.
The purpose of the maxscript file is to upload new textures on a model and then save them out as a seperate max file which will then be put in the render farm.
However we're getting an error when we try to run it "group() requires a node or node collection, got:undefined
Because nobody here at work is too familiar with maxscript i was hoping someone could take a look and offer some suggestions.
I'll paste the maxscript code but because this is official work I'd rather not post the max file
Here's the maxscript:
utility mergeFiles "Merge Files" width:162 height:69
(
struct csvEntry ( mergePath, mergeFile, offsetX, offsetY, offsetZ, basePath, baseFile, matList, matLib, outputFile, renderSettings )
button btnGo "Go" pos:[20,15] width:74 height:47
fn openTheFiles path infoList = (
initialFile = path + infoList.basePath + infoList.baseFile
mergeFile = path + infoList.mergePath + infoList.mergeFile
loadMaxFile initialFile
max select all
group $ name:"__Base"
print ("Merge File: " + mergeFile)
mergeMaxFile mergeFile
base = getNodeByName "__Base"
max select all
deselect base
group $ name:"__Sink"
sink = getNodeByName "__Sink"
offsets = [infoList.offsetX as float, infoList.offsetY as float, infoList.offsetZ as float]
move sink offsets
)
-- Looks through the materials section of the csv and changes the objects materials.
fn processMaterials info = (
-- matList, matLib
-- Load the material library.
if doesFileExist(info.matLib) then (
loadMaterialLibrary info.matLib
) else (
print (info.matLib + " not found")
return -1
)
if info.matList != "" and info.matList != undefined then (
matsToApply = filterString info.matList "="
theObject = getNodeByName matsToApply[1]
if theObject != undefined then (
theMat = currentMaterialLibrary[matsToApply[2]]
if theMat != undefined then (
-- Apply the material
theObject.material = theMat
)
)
)
)
-- Assigns the render settings from the csv file
fn processRenderSettings info = (
items = filterString info.renderSettings ";"
for i = 1 to items.count do (
nameAndValue = filterString items[i] "="
case nameAndValue[1] of (
"renderwidth":
renderWidth = (nameAndValue[2] as integer)
"renderheight":
renderHeight = (nameAndValue[2] as integer)
"rendoutputfilename":
rendOutputFilename = nameAndValue[2]
)
)
)
fn createFiles infoList fullPath = (
path = getFilenamePath fullPath
for i = 1 to infoList.count do (
openTheFiles path infoList[i]
processMaterials infoList[i]
processRenderSettings infoList[i]
saveMaxFile (path + infoList[i].outputFile)
)
)
-- Reads in the CSV and stores the information in an array of arrays
fn processCSV fullPath overwrite = (
infoList = #()
local curLine = 0
csvFile = openFile fullPath mode:"rt"
while not eof csvFile do (
curLine = curLine + 1
line = readLine csvFile
parts = filterString line ","
if parts.count >= 11 then (
tmp = csvEntry mergePath:parts[1] mergeFile:parts[2] offsetX:parts[3] offsetY:parts[4] offsetZ:parts[5] basePath:parts[6] baseFile:parts[7] matList:parts[8] matLib:parts[9] outputFile:parts[10] renderSettings:parts[11]
append infoList tmp
) else (
print "Error on line: " + (curLine as string)
)
)
close csvFile
return infoList
)
on btnGo pressed do (
source = "mergeList.csv" -- "C:\projects\Kohler\sinkmerge\mergelist.csv"
fullPath = getOpenFileName caption:"Open CSV File" filename:source types:"Comma Separated (*.csv)|*.csv|All Files (*.*)|*.*|"
if fullPath != undefined then (
if doesFileExist (fullPath) == true then (
infoList = processCSV fullPath overwrite
createFiles infoList fullPath
)
) else (
print "The user cancelled."
)
)
Anyway...if anyone could help I'd be ever so gratfull as this maxscript could save a lot of time
Thanks,
Doug
I'm having a problem with an old maxscript here at work that someone wrote a while ago and he's no longer here.
The purpose of the maxscript file is to upload new textures on a model and then save them out as a seperate max file which will then be put in the render farm.
However we're getting an error when we try to run it "group() requires a node or node collection, got:undefined
Because nobody here at work is too familiar with maxscript i was hoping someone could take a look and offer some suggestions.
I'll paste the maxscript code but because this is official work I'd rather not post the max file
Here's the maxscript:
utility mergeFiles "Merge Files" width:162 height:69
(
struct csvEntry ( mergePath, mergeFile, offsetX, offsetY, offsetZ, basePath, baseFile, matList, matLib, outputFile, renderSettings )
button btnGo "Go" pos:[20,15] width:74 height:47
fn openTheFiles path infoList = (
initialFile = path + infoList.basePath + infoList.baseFile
mergeFile = path + infoList.mergePath + infoList.mergeFile
loadMaxFile initialFile
max select all
group $ name:"__Base"
print ("Merge File: " + mergeFile)
mergeMaxFile mergeFile
base = getNodeByName "__Base"
max select all
deselect base
group $ name:"__Sink"
sink = getNodeByName "__Sink"
offsets = [infoList.offsetX as float, infoList.offsetY as float, infoList.offsetZ as float]
move sink offsets
)
-- Looks through the materials section of the csv and changes the objects materials.
fn processMaterials info = (
-- matList, matLib
-- Load the material library.
if doesFileExist(info.matLib) then (
loadMaterialLibrary info.matLib
) else (
print (info.matLib + " not found")
return -1
)
if info.matList != "" and info.matList != undefined then (
matsToApply = filterString info.matList "="
theObject = getNodeByName matsToApply[1]
if theObject != undefined then (
theMat = currentMaterialLibrary[matsToApply[2]]
if theMat != undefined then (
-- Apply the material
theObject.material = theMat
)
)
)
)
-- Assigns the render settings from the csv file
fn processRenderSettings info = (
items = filterString info.renderSettings ";"
for i = 1 to items.count do (
nameAndValue = filterString items[i] "="
case nameAndValue[1] of (
"renderwidth":
renderWidth = (nameAndValue[2] as integer)
"renderheight":
renderHeight = (nameAndValue[2] as integer)
"rendoutputfilename":
rendOutputFilename = nameAndValue[2]
)
)
)
fn createFiles infoList fullPath = (
path = getFilenamePath fullPath
for i = 1 to infoList.count do (
openTheFiles path infoList[i]
processMaterials infoList[i]
processRenderSettings infoList[i]
saveMaxFile (path + infoList[i].outputFile)
)
)
-- Reads in the CSV and stores the information in an array of arrays
fn processCSV fullPath overwrite = (
infoList = #()
local curLine = 0
csvFile = openFile fullPath mode:"rt"
while not eof csvFile do (
curLine = curLine + 1
line = readLine csvFile
parts = filterString line ","
if parts.count >= 11 then (
tmp = csvEntry mergePath:parts[1] mergeFile:parts[2] offsetX:parts[3] offsetY:parts[4] offsetZ:parts[5] basePath:parts[6] baseFile:parts[7] matList:parts[8] matLib:parts[9] outputFile:parts[10] renderSettings:parts[11]
append infoList tmp
) else (
print "Error on line: " + (curLine as string)
)
)
close csvFile
return infoList
)
on btnGo pressed do (
source = "mergeList.csv" -- "C:\projects\Kohler\sinkmerge\mergelist.csv"
fullPath = getOpenFileName caption:"Open CSV File" filename:source types:"Comma Separated (*.csv)|*.csv|All Files (*.*)|*.*|"
if fullPath != undefined then (
if doesFileExist (fullPath) == true then (
infoList = processCSV fullPath overwrite
createFiles infoList fullPath
)
) else (
print "The user cancelled."
)
)
Anyway...if anyone could help I'd be ever so gratfull as this maxscript could save a lot of time
Thanks,
Doug
