show data from a text/csv file

I am looking for a script that reads a text/csv file (containing 2 columns of data and depending on the frame I am on, it goes to that row of data and show the data in those 2 columns as 2 labels.
I would really appreciate your help on this.
Thanks.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jahman's picture

.

all_lines = (dotnetclass "system.io.file").readalllines @"path_to_csv"
csv_separator_char = ","
data = filterString all_lines[ 1 + currentTime as integer ] csv_separator_char -- btw, what're you gonna do with negative frames?
label_1 = data[1]
label_2 = data[2]
cuatcside's picture

Thanks. I saved this code as

Thanks.
I saved this code as a .ms

all_lines = (dotnetclass "system.io.file").readalllines @"d:\test2.txt"
csv_separator_char = ","
data = filterString all_lines[ 1 + currentTime as integer ] csv_separator_char
label_1 = data[1]
label_2 = data[2]

and saved a .txt file with 3 lines of data

hello,2
big,3ab
n2,5sb

but I am getting this error when I run it:

#("hello,2", "big,3ab", "n2,5sb")
","
-- Error occurred in anonymous codeblock; filename: C:\max-scripts\text.ms; position: 231; line: 4
-- Type error: FilterString [String to filter] [Tokens] requires String, got: undefined
-- MAXScript callstack:
-- thread data: threadID:19036

jahman's picture

.

try to replace currentTime with sliderTime and see if it works

jahman's picture

.

you have to know maxscript a little to use this code

-- Type error: FilterString [String to filter] [Tokens] requires String, got: undefined

filerString expects string value, but all_lines array probably doesn't contain string for this frame so 'all_lines[ 1 + currentTime as integer ]' is equal to undefined

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.