PDA

View Full Version : Help with reading values from a text file


Scott Ayers
11-01-2010, 04:23 PM
Hey guys,

I've figured out how to read values from an external text file and use them to control objects.
But the problem is I can only use the last value listed in the text file.
Can anyone tell me how to target specific text entries from the text files?

Here's my text value reader code: var name = doc->GetFilename();
name->SetFullString("C:/Users/user/Desktop");
name->AddLast("values.txt");
var filename = name;
var file = new(BaseFile);
file->Open(filename, GE_READ);
var str = file->ReadString(file->GetLength());

var y = evaluate(str); //Converts string info from the file into a float value
op#ID_BASEOBJECT_REL_POSITION:VECTOR_Y = y;// Set the Y position to this value

Here's what's inside of my text file: 150;20;50;


-ScottA

mayajunky
11-01-2010, 07:13 PM
Hey Scott, not to much help here... just a link I found in the python docs when looking into the same thing last week. I was actually looking into it for writing out data, but am sure is still some useful tidbits in there.

http://docs.python.org/tutorial/inputoutput.html

I haven't tested it at all but is the import Ascii still messed up in R12 when importing csv's that have been formatted on a mac... or was it a pc?

Scott Ayers
11-01-2010, 08:23 PM
Thanks for the link.
It did help me out a little bit to figure out how the Coffee functions work.

Here's the same script that only reads the fourth and fifth characters to use as object positions: var name = doc->GetFilename();
name->SetFullString("C:/Users/user/Desktop");
name->AddLast("values.txt");
var filename = name;
var file = new(BaseFile);
file->Open(filename, GE_READ);
var str = file->ReadString(file->GetLength());
var pos = file->GetPosition(); // Gets total number of characters
var seek = file->Seek(4,false);// Gets the fourth character
var read = file->ReadString( seek+1, GE_XBIT );// reads the fourth and fifth characters

var y = evaluate(read); //Converts string info from the file into a float value
op#ID_BASEOBJECT_REL_POSITION:VECTOR_Y = y;// Set the Y position to this value


I still need to learn how to use /n so I can target specific paragraphs though.
Lennart seems to have done a lot of this text referencing stuff and I'll bet he could shed some light on this stuff. But he's been very quiet lately.

This is my first venture into external files. And I've never tried importing ASCII stuff so I don't know about your question mj.

-ScottA

CGTalk Moderation
11-01-2010, 08:23 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.