I'm a long-time but low complexity maxscripter, but I know what I want to do and generally I get there through recursive tinkering.
My main issue is usually knowing the appropriate terminology to search for.
Here is a snippet of the first few lines of a file (it's an OS DTM format)
ncols 200 nrows 200 xllcorner 430000 yllcorner 250000 cellsize 50 68.6 69.2 69.6 70.2 71.2 71.9 73 74 75.3 89.2 88.2 80.3 79.4 86.7 87.8 85.9 81.5
Please note there are 200 lines of data, each with 200 entries per line in my actual file.
The area I'm struggling with is the readDelimitedString.
vert_array = #() face_array = #() in_name = getOpenFileName() if in_name != undefined then ( in_file = openFile in_name if in_file != undefined then ( -- get ncols skipToString in_file "ncols" ncols = readLine in_file as integer -- get nrows skipToString in_file "nrows" nrows = readLine in_file as integer -- get cellsize skipToString in_file "cellsize" cellsize = readLine in_file as integer num_verts = ncols * nrows --num_faces = (ncols - 1) * (nrows - 1) * 2 vert_array.count = num_verts --face_array.count = num_faces for r = 1 to nrows do ( for v = 1 to ncols do ( vert_y = readDelimitedString in_file " " as float vert_x = (v-1) * cellsize vert_z = (r-1) * cellsize x = vert_x as string y = vert_y as string z = vert_z as string xyz_array = execute ("[" + x + "," + y + "," + z + "]") index = (v)+(r) vert_array[index] = xyz_array ) skipToNextLine in_file ) close in_file --new_mesh = mesh vertices:vert_array -- debug debug= newScript() --print ncols to:debug --print nrows to:debug --print cellsize to:debug print vert_array to:debug print x to:debug print y to:debug print z to:debug )--end if )--end if
Right now this works ok, except that the last entry on every line ends in a carriage return, but I can't seem to add a syntax that allows me to run an if or while statement referencing the ncols variable.
Basically I want to say something like this:
if v < ncols ( read delimited string until " ") else ( read delimited string until "/r")
I've tried an if else statement, two if statements, and everything else I can think of but it's breaking the code. Is there a certain way I should be doing this?
I've tried this which should work?
if v < ncols do ( function) if v = ncols do ( other function)
Which I'm sure is the right maxscript syntax but it fails.
My quick bodge is find/replace on the data lines to add a trailing space before the carriage return... but I don't like bodges.
Also note my horrible array filling using a string. I can't seem to find any examples in the help files saying how to do this more elegantly.
I can't seem to find anything saying how to use point3 arrays at all.
I'm also struggling recursing through the rows/columns and indexing the correct array entry to store the vert data, but I think that will be easier once I can just run through each point3 coord at a time, filling X then Y then Z.
I've not really got to that part yet though so if my code looks iffy please ignore haha!
Many thanks for any help
I'll carry on working at it, I'm sure I'll get there eventually...