I am using Rhino 5 and I am having trouble importing an ASC file format. This format is compatible with Rhino, yet nothing appears when opening the file. This forum will not let me upload this file, as it is not an allowed filetype, so here is a link to it: http://s000.tinyupload.com/?file_id=01181216005909925690
Hello - if the goal is to import points, the format should be
12, 2.4, 5
10, 6.7, 2.9
The file you linked is like this:
Test Asc.zip (133 Bytes)
Looks like this type of file…
One would need to write a special importer for it.
I routinely deal with ASCII Grid files which also have an .asc extension, but this is not the same animal.
What kind of data does this file represent?
I understand how these files are supposed to look, but the file I’m working with is not set up that way for whatever reason. It’s an old file that was on a system that had some sort of old software that use to read these files. The problem is that system is no longer functioning properly, so I am trying to find a way to open it on a modern machine.
This is supposed to be a file that has point data. The format in the file, i’m told, worked fine with a particular old software on a now defunct computer.
OK, then several assumptions need to be made, as the data does not hold x, y, z values for each entry, some only have two of the three, some only have one.
Two ways I see of interpreting the data:
- No presence = 0 - any x, y or z value not present is given a 0 value
- No presence = previous value - this works like CNC G-Code where values are “modal”, i.e. assumed to be the last used value until a new value changes it
You would need to decide how the data is to be interpreted and then an import script could probably be written with a bit of work.
I believe the data was actually used on an older cnc machine that we used to have in our shop. The software used was called CAMX Command, which is no longer supported. The second option is the proper interpretation, where no presence = previous value.
Are there any guides around to writing such a script??
This Python code reads the sample file to variables x,y,z:
It now also draws the shape using straight curves
This will not work if there are changes in x value in the file, nor if there are any headers.
This link gives more information about manipulating text in Python including the strip and split methods I used here:
import rhinoscriptsyntax as rs with open('EARM.asc') as f: xy,z = f.readline()[1:].strip().split('Z') x,y = xy.split('Y') x = float(x) y = float(y) z = float(z) for line in f.readlines()[1:]: x0,y0,z0 = x,y,z if 'Y' not in line: break if 'Z' in line: dy,dz=line[1:].strip().split('Z') y+= float(dy) z+= float(dz) else: dy = line[1:].strip() y+= float(dy) rs.AddCurve([(x0,y0,z0), (x,y,z)])
In addition to the sample code posted above, I can just say that if you are going to use this as a CNC cutting file, you really do not need to do anything except add a header and some speed/feed info in a text editor…
thank you very much, this was really helpful!!
unfortunately, it seems this program gets hung up on the x value. There are changes in the x coordinate throughout the program, but after getting to the second X setting it seems the translation into rhino just stops. Apparently, this file is supposed to represent something that resembles wood grain. Or rather, it is supposed to look like how a CNC machine would cut out a wood grain.
removing the lines:
“if ‘Y’ not in line:
produces something that looks like this:
running this script:
import rhinoscriptsyntax as rs with open('C:\Users\JRankin\AppData\Local\Temp\EARM.asc') as f: xy,z = f.readline()[1:].strip().split('Z') x,y = xy.split('Y') x = float(x) y = float(y) z = float(z) for line in f.readlines()[1:]: x0,y0,z0 = x,y,z if 'Z' in line: dy,dz=line[1:].strip().split('Z') y= float(dy) z= float(dz) else: dy = line[1:].strip() y= float(dy) rs.AddCurve([(x0,y0,z0), (x,y,z)])
which is a bit closer to what the file should look like.
Top and tail with
To speed up the process. Then it just needs some added logic for the X values. The best way would be to use regular expressions (re module in python)
If you have a problem and you decide to use regular expressions to solve them then you have 2 problems…
@DanBayn and I developed a G-Code parsing script back in 2014, Dan said it’s OK to release it here, it seems to work fine on your file above… I just added a file browse function that looks for .asc files, that could be modified to any kind of text file extension…
GCodeParser.py (3.0 KB)
yes this works perfectly!! Thank you very much!
well, i thought it worked perfectly at first anyways, but it seems that the converter is not converting things properly or something. for some reason, some of the curves fall on top of each other, like this:
The purpose of recovering this file is for use in SURFCAM. While the .3dm file is viewable in Rhino, it does not show up very well in SURFCAM. Many of the lines are skewed at a weird angle, and some of them just do not show up at all. Converting to IGES format does not even allow the file to be read by SURFCAM.
Well the input data is poor - I do see that the script is throwing a lot of errors in not being able to create line segments because the start and end points are the same… Will have to look why that happens.
OK, there was definitely a problem in the script with interpreting lines that had just a single letter, I have fixed that and the results look better, but there is still some overlapping going on, will need to investigate further.
Try this one on for size…
GCodeParser11.py (3.4 KB)
Before running it make a new file (I think in inches?) and set the tolerance to 0.0001 - as there are some segments in there that are very tiny, and joining them at the end messes things up if the tolerance is too loose.
Here I get one continuous trace now. Still some jumpyness, could definitely be smoother.
The file that this script output looks correct and was able to be read properly in SURFCAM. Even the old grumpy guy I work with thought it was acceptable! thanks again for your assistance!!
I used to be an old grumpy guy who worked with Surfcam. Now I’m just an old grumpy guy.