Update Text Object from csv or txt file

Hi Everyone,

I am looking for a simple way to have a text object update based on a file that contains a frame number and string (numbers, letters or combination).

I would like to be able to run the script so that at each frame number, a text object will update with the respective string at that frame.

I imagine some of your are probably shaking your head at this one, but I have very limited exposure to Max Script.

My text file could be anything like this:

frame show text
0 113
1 1234
2 1579
3 1321
...etc

Any help is appreciated.

Eugene

Comments

Comment viewing options

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

My bad...this works like a

My bad...this works like a charm!

Thanks so much!

Eugene

barigazy's picture

...

Glad to here that code works because I not test this but anyway... :)
Always try to run any code from listener or mxs editor by opening it first and then execute ei.evaluate.
Cheers!

bga

eliscio's picture

I ran this under "Run Script"

I ran this under "Run Script" and it gave me a

No "eof" function for undefined

barigazy's picture

...

Let say we have text file "data.txt". Content look like this:
---------------------------------
0 "max2014"
1 "maya2014"
2 "mudbox2014"
3 "adobe illustrator cs6"
4 "softimage XSI"
5 "ZBrush"
6 "VRay"
7 "Maxwell"
8 "Octane"
9 "Modo"
10 "Nuke"
---------------------------------
Runing this code you will get what you need

delete objects
txtShape = text()
fn showTxt txtObj txtFile: =
(
	local theCtrl = float_script()
	theCtrl.addNode "txtObj" txtObj
	local frameArr = #(), txtArr = #(), dataF = openFile txtFile
	slidertime = 0
	while not eof dataF do
	(
		append frameArr (readValue dataF)
		append txtArr (readValue dataF)
	)
	close dataF
	theCtrl.AddConstant "fVals" frameArr
	theCtrl.AddConstant "tVals" txtArr
	theCtrl.SetExpression "if (idx = finditem fVals f) !=0 do txtObj.text = tVals[idx]\n0" 
	txtObj.kerning.controller=theCtrl
	free frameArr ; free txtArr
)
-- change file path if your file have different location on HDD
showTxt txtShape txtFile:@"c:\\temp\\data.txt"
playAnimation()

bga

Comment viewing options

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