Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / Add data to a text file
  RSS 2.0 ATOM  

Add data to a text file
Rate this thread
 
63834
 
Permlink of this thread  
avatar
  • jpepper
  • Posted: 24 January 2012 08:38 AM
  • Total Posts: 40
  • Joined: 07 July 2011 04:58 PM

Well I’ve been trying to look into doing this and I can’t seem to find the right directions.
I basically have a text file that has some data inside of it.  Now I’ve figured out how to open the file and read the contents which is fine but I can’t seem to “write” to the file.

So the example is this:

Mytextfile.txt

Inside the file is the following:

James Bond=007

Now that this file exists somewhere on my harddrive I’d like to be able to write to it via maxscript if possible.

Like adding another like to it:
Lex Luther=666

So then the text file would contain:

James Bond=007
Lex Luther=666

and so on it would go.

I know how to do it via an “INI” file but that’s not exactly what I need.
So I’ve been looking through the external file methods and stringstreams and so on but nothing seems to be jumping out on this subject.

Any help would be great.

Thanks



max2010-2012 windows xp64bit
nvidia QuadroFX

Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

(
local fName "c:/test.txt"
local fh 0
   
if (doesFileExist fNamethen
   fh 
openFile fName mode:"at"
else
   
fh createFile fName

format 
"Lex Luthor=666\n" to:fh

close fh
)


Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.

Replies: 1
/img/forum/dark/default_avatar.png

Thanks a lot Steve!  I didn’t realize it was that straight forward. 

When looking through the maxscript help I was confusing FileStream with FileName_String

Your always very helpful thanks again!

Author: jpepper

Replied: 24 January 2012 03:18 PM