I'm looking for a fast way to write a lot of text lines in a file (several files actually).
Using maxscript's Filestream takes around 40 seconds for 32 files with over 720k lines total. This is a too long and I'm looking to optimize it by writing the text through dotNET instead.
I'm a noob at .NET, but after scouring the internet I managed to get it working by appending all my text lines in an array and using WriteAllLines
contents = #() for v in vertices do append contents ("v " + v.x as string + " " + v.y as string + " " + v.z as string) for vn in normals do append contents ("vn " + vn.x as string + " " + vn.y as string + " " + vn.z as string) for f in faces do append contents ("f " + (f.x as integer) as string + "//" + (f.x as integer) as string + " " + (f.y as integer) as string + "//" + (f.y as integer) as string + " " + (f.z as integer) as string + "//" + (f.z as integer) as string) (dotNetClass "System.IO.File").WriteAllLines myfile contents
1. write each line directly in the file
This should speed up the process by eliminating the need to append an array. I also learned from experience that maxscript can get slow when using huge arrays, and the ones I'm working with end up having over 100k text elements.
2. Write floats and integers without converting to text
I've seen that the StreamWriter class has methods to write the text representation of values, which might also speed up the process.
I am clueless on how to implement these 2 ideas. Could anyone please help with examples on how to use this StreamWriter class?