So here's my code. I need to read in values from a *.csv and make an object move up and down while rotating. Essentially I'm trying to have a box bob up and down on a sinusoildal wave created from another program.
(
AssyFile = openfile "C:\Documents\3dsMaxDesign\Scripts\\MotionTest.csv"
set animate on
if (AssyFile != undefined) then
(
skiptonextline AssyFile
select $Box001
while not eof AssyFile do
(
TransformName = readdelimitedstring AssyFile ","'
XRot = readValue AssyFile
ZTrans = readValue AssyFile
sliderTime = 0
max set key keys
sliderTime = sliderTime + 15
move $ [0,0,ZTrans]
rotate $ (angleaxis XRot [1,0,0])
)
)
else
(
messageBox "Open Failed" title:"Error!"
)
)
My spread sheet reads like this
TransformName | XRot | ZTrans |
1 | 10 | 1 |
2 | 10 | 1 |
3 | 10 | 1 |
4 | 10 | 1 |
5 | 10 | 1 |
6 | 0 | 0 |
7 | -10 | -1 |
8 | -10 | -1 |
9 | -10 | -1 |
10 | -10 | -1 |
11 | -10 | -1 |
12 | 0 | 0 |
I get this error
--Syntax error: at end of script, expected end of literal
--In line: )
I've no idea what this means or what's wrong. Any help?
( local st = 1 local theBox = $Box001 AssyFile = openfile "C:/Documents/3dsMaxDesign/Scripts/MotionTest.csv" if (AssyFile != undefined) then ( skiptonextline AssyFile with animate on ( while not eof AssyFile do ( TransformName = readvalue AssyFile XRot = readValue AssyFile ZTrans = readValue AssyFile -- format "tn=% X=% Z=%\n" TransformName XRot ZTrans at time (st * 15) ( move theBox [0, 0, ZTrans] rotate theBox (angleaxis XRot [1,0,0]) ) st += 1 ) ) ) else ( messageBox "Open Failed" title:"Error!" ) )
Thanks a bunch, I'll try to get that working. As for the csv I copied it from excel, hence the lack of commas.
First it worked great, then I couldn't get the file to read.
I tried
AssyFile = openfile "C:\Scripts\\Motion.csv"
AssyFile = openfile "C:\Scripts\Motion.csv"
AssyFile = openfile "C:/Scripts/Motion.csv"
but I keep getting a read fail error. What gives?
st += 1 ) ) close AssyFile -- missing this line ) else
Yeah the file is there. I had it in several locations because I got the same error when using the path you see. So I moved it into what I thought was the simplest location. It read fine and when I closed the scene and reopened it suddenly couldn't find the file. Now I'm trying it on another computer and get the same error. No clue why it can't find the file. I'm using windows 7 and max design 2014 if that makes a difference.
I just got the file to read on a network drive. My guess is there's something wrong w/ reading the file directly when it wants to read something like MyComputer>Documents etc. I'm not sure what to input to fix this but right now it's working if I use a network drive. However when I try to work at home I'm lost as to what to do.
AssyFile = openfile "C:/Documents and settings/Administrator/My Documents/3dsmax/MotionTest.csv"Load a test scene, run the script, load the scene, run the script... no file errors of any kind. Max/Max Design shouldn't make a difference, W7 vs XP might, though as I don't have a W7 installation yet I can't test that.