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.
Forum topic · Scripts Wanted
show data from a text/csv file
By cuatcside · 2021-06-11
Description
Comments (4)
.
jahman · 2021-06-11
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 · 2021-06-11
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 · 2021-06-12
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
.
jahman · 2021-06-12
try to replace currentTime with sliderTime and see if it works