[Closed] Read and re-writing a file
I’m sure this is probably a 4 line script for you guys…but can someone show me how to read in values from a file and perform some operations on some of the values and then output it to a new file.
Basically i have 6 columns of numbers (first 3 are position and last three are RGB) and i need to convert and write a file that has the RGB converted to float.
So…
1 2 3 255 240 230
would be…
1 2 3 1.0 .94 .90
Thanks!
the task looks funny to me. you want to help someone to read the data from file… but all that you do is dividing some values by 255.0
where is a point?
is it a file format that i don’t know?
Quick N hacky way. I’m sure others will have a more elegant solution involving the faster stringstreams and a less “locked in” way to read the data.
(
theOrigFilename = @"C: est.txt"
theNewFilename = @"C: estNew.txt"
theOrigFile = openFile theOrigFilename
theNewFile = createFile theNewFilename
while not eof theOrigFile do
(
theText = ""
for i = 1 to 6 do
(
theVal = readvalue theOrigFile
if i > 3 do theVal = theVal/255.0
theText += theVal as string + " "
)
format "%
"theText to:theNewFile
)
close theOrigFile
close theNewFile
)
Its actually a point cloud format that i need to re-order to get vertex colours to display properly when meshed with Frost. There is something happening when Frost does the conversion on its own that makes the colours not right…so until i complete my testing i want to be able to try it out on full point clouds…millions and millions of points. Instead of inserting into excel and being limited by there million or so row count. I really appreciate the help by the way.
An alternative, Bobo showed me over on the Frost forums how to do these calculations within Frost / Krakatoa’s PRT loader: http://forums.thinkboxsoftware.com/viewtopic.php?f=89&t=5988
I’m kind of scratching my head here! I’m converting a 3670684 kb pointcloud file and it crashes everytime the converted file reaches 2792906 kb. I don’t think its a hardware issue, i have 24 gigs of ram and a terrabyte hard drive. I’ve converted files up to 1.35 gig so far. Just not sure why it would crash…it may be something in the file but i doubt it because i can mesh it with Frost without issue…its just when i try to convert it crashes. I’m going to keep looking into this…just want to check in with you guys to see if there may be an issue in maxscript.
Oh and i tried increasing the heapsize to more then the actual size of the file…same crash!
Thanks for the help guys!
If it’s crashing at the same spot, it might be that there’s an anomaly in the file you’re reading from. Maybe add some sort of check if the data is the format that you’re expecting. Maybe write a different file out at the same time that just outputs the current unmodified data so you can use that to search and find the (possible) problem in the source data.
Or maybe try manually splitting the file, converting the 2, then manually join them back together.
Or maybe try doing a garbage collection and/or an undobuffer clear for every 100 lines that you read/convert.