[Closed] import spreadsheet to animation?
Is there anyway i could loop through the rows of a spreadsheet (excel file) or flat text document and extract the x y or z coordinates of each row and set a key frame for a given object in max for every row?
I’m not sure I understand what you mean when you say “extract the X Y Z components of each row”. If you mean can you take values stored in three rows of the spreadsheet and then create keys for an object in Max, the answer is yes.
IOW, if you have a text file that goes something like this:
-15.6 5.8 0.0
-22.1 30.0 5.0
15.3 20.2 1.1
etc. then you can indeed use these values to do position an object in Max space. It’s just a matter of reading the file and taking the values and applying them:
in_name = “C:/test.dat”
in_file = openFile in_name
while not eof in_file do
(
animate on
x = readdelimitedstring in_file ” “
y = readdelimitedstring in_file ” “
z = readdelimitedstring in_file ” “
$box01.position = point3 x y z
)
or some such (I’m not quite awake here right now so the syntax might be a little off, but you can examine the Maxscript manual and get the full details right).
Your close but you would have to execute the values that are returns or convert them to the float values that you need. At the moment they would all be strings.
Ah, yes, I was awake enough to realize something was wrong in my gut, but not wide enough awake to figure it out :>).
But I’m still not quite sure this is what he had in mind anyway.
sweet, ill try it out. thanks!
Is there anyway to animate in the local axis?
Lets say i would want to animate the X axis and have it move “LOCAL” rather than “VIEW”.
How would i go about doing that?
Actually, VIEW is not the default – World is the default for the coordsys.
You can use the in context to set the coordsys you want:
in coordsys local $sphere01.pos = point3 x y z
And note what Paul was saying – my code example only read strings off the file and these would need to be converted to float (which you can do as easily):
x = readdelimitedstring in_file ” ” as float
y = readdelimitedstring in_file ” ” as float
z = readdelimitedstring in_file ” ” as float
cool, thanks for the great help. ill try it out and let you know how it goes.
You can also export CSV (Comma Seperated Value) files from excel. Would change your parser slightly, but just another way to export your data.
the code never ends. it seems like its in an endless loop and my max freezes. i have to hit escape a few times to interrup the code.
heres the code:
f = openFile “somefile.dat”
while (not eof f) do
(
–do anything
)
i also tried adding
skiptonextline f
that also did’nt help
Any ideas?
I did tell you I was half-asleep when I wrote that, right?
Anyway <bg> here’s a much easier way to do this all (although the same principles are in effect):
in_name = “C: est.dat”
in_file = openfile in_name
with animate on
(
while not eof in_file do
(
slidertime = slidertime + 5 – need to account for time values somehow: could also read in
x = readvalue in_file
y = readvalue in_file
z = readvalue in_file
skiptonextline in_file
$box01.position = point3 x y z
)
)
Using readvalue also evaluates the text into a float (but make sure you specify as a float – IOW, your file needs to have values like 1.0 not just 1) and skips to next value in line (just leave spaces between values like this 22.1 10.1 5.4).
This also assumes a well-behaved file (that is, with three values each line, all floats, etc.) Good programming practice would require a lot more error checking to keep Bad Things from happening to it (converting to float, conditions if there are less than three values, etc. etc.)
(See – now I’m awake :>)