ScriptSpot home

Forum topic · General Scripting

syntax help with maxSaveFile

By joel · 2012-05-18

New forum topics are on pause. Signed-in members can reply to existing topics. Contact ScriptSpot if you need help.

Description

This should be an easy one but I am stuck. I am concatenating some strings together to give a final file path, which I will later use in the saveMaxFile command. Here is the code.
finalFile = (finalRoot + "\\" + curAsset + ".max") as string

"finalFile" ends up being a valid string such as "C:\Users\jdeehr\Documents\sandBoxForAssetBrowser\models\few\jh\kj\kj.max" I even queried the type to be extra sure and sure enough, it is a string.

However, if I call the command saveMaxFile(finalFile) it says "cannot convert undefined to type:fileName." How is it that MAX thinks finalFile is undefined?

The other strange thing is if I hardcode in saveMaxFile("C:\Users\jdeehr\Documents\sandBoxForAssetBrowser\models\few\jh\kj\kj.max") It works.

How are finalFile (which obviously is going to vary) and hardcoding in a path such as "C:\Users\jdeehr\Documents\sandBoxForAssetBrowser\models\few\jh\kj\kj.max" different in the context of saveMaxFile()? Thanks.

Comments (7)
joel

Thanks much.

Branko Živković

Explanations for your question

In maxscript help find the topic MAX File Loading and Saving. There you will find the best explanation.
At the buttom of topic page look for SEE ALSO topics.

Willian Kim

Hi man, I tested a solution that can resolve to you

--- Defines base directory
finalRoot = "C:\Users\digital\Desktop"

--- Defines final file
finalFile = (finalRoot + "\\" + maxFileName) as string

saveMaxFile finalFile

or

--- Defines base name
baseName = "tst"

--- Defines base directory
finalRoot = "C:\Users\digital\Desktop"

--- Defines final file
finalFile = (finalRoot + "\\" + baseName + ".max" ) as string

saveMaxFile finalFile

Thanks. Can you also give an explanation why my method didnt work? I got the code to work with a dirty workaround but I would really like to understand why.

Reply to joel
Willian Kim

really is missing only the definition of variables, the code was correct. barigazy spoke as a look at help for a better understanding

Reply to Willian Kim
Branko Živković

This concept also works

finalRoot = @"C:\temp\"
fileext = "test.max"
saveMaxFile (append finalRoot fileext)

joel

update

I was able to do a workaround by putting finalFile into an array, and then iterating through that array and calling saveMaxFile for each item in the array. (In this case, only one item was in the array)

I still have no idea why this works though. Any insight would be great! Thanks.