PDA

View Full Version : Max script help


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

U.S.S. Speed
01-29-2008, 05:38 PM
I would say... Etheir your base file or the merged file doesn't contain any node.

PEN
01-29-2008, 05:39 PM
This has some issues in the way that it was written. He is using $ instead of selection so it will return two seperate things. If one object is selected it will return an object if multiple are selected it will return an array. I would say that this bug was always in there.

You would be best posting the code with code tags around it so that it can be cut and pasted with out needing reformating so that it can be read. Either that or post a link to the script for down load.

MoonDoggie
01-29-2008, 05:58 PM
PEN is correct, also please post the line it is breaking on

DougWells3D
01-29-2008, 06:10 PM
The line seems to break on " group $ name:"__Sink" "

When originally posting the script code this website wouldn't allow me to paste it in like that (with all the code specific text..ex. green, red letters) so I had to paste it into notepad and then paste it into here

Anyway....

thanks for the help guys

Doug

MoonDoggie
01-29-2008, 07:49 PM
put the code portion between "<code> </code>" tags, substitute <> for []

CGTalk Moderation
01-29-2008, 07:49 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.