@Sea-Haven
"The Op is backward redoing a Gcode output. So file format should be consistent."
Yes the G-code file format is consistent in that G-code has rules that it must follow.
"Notice in the 1st Txxx that there is lines with X 6.0 no Y, I guess this means use prior Y for missing value."
Correct. If there is only an X or only a Y then the previous/prior Y or X respectively is to be used.
@Moshe-A
"I do not think the absence of ability to choose data file is your problem and as it looks like (at least for now) no one here familiar with your CNC machine \ G-Code but still there are many experts here that can help you bring your wish to life if only you give us all the info needed."
I was trying to express that the main reason I could not run the LISP you sent is because I don't know where (what file path/directory) your LISP routine is looking for the file "DATA POINTS for TESTING purposes5.txt". The program gives me the message "can not find DATA POINTS for TESTING purposes5.txt" file. Our IT department has pretty tight controls on things, so there are only certain directories that I have write access to.
In the LISP routine that I provided the starting function is "(defun cnc ()..." . In order to start this LISP routine at the command line one would have to enter "(cnc)". I don't know if redefining the function as "(defun c:cnc ()..." would work.
I don't know what other information you want me to provide.
@Sea-Haven
"Can I ask the dumb question, why are you reverse engineering the gcode, is it because you have lost the original Dwg ?"
Some of our machines are older machines for which the records have been lost as the machines have moved from one building to another. So the programs exist on the CNC machine and may not exist anywhere else.
Being able to graphically represent the toolpaths with polylines in AutoCAD is just one additional tool in being able to fix or troubleshoot a CNC machine program when appropriate.
@komondormrex
"you need to write a better parser for cnc-program that can read the entire cnc-program into a list of say dotted pairs (as John suggested), which you then process to every function code in it accordingly."
This would have some advantages but I don't even know how to go about this at this point. Setting flags in the LISP routine to indicate that a specific command has been requested is the way I believe I might be able to incorporate more functionality at some point.
G-code was developed back in the infancy of computers and computer numeric control (CNC). As such, many CNC machines were only capable of processing one line of code at a time.
Again though, I was just looking for a way to handle the first X0.0 Y0.0 and the X999 Y999 at this stage with this post. I believe I have since figured out a way to handle the possibility of X999 Y999 being a valid data point in a G-code program.
@pbejse
"It would ne nice if we can get a peek of what you consider the most complete data and describe each and every variation.
To be honest, i started reading thru every post by @mmazanec explaining the process, in the end I'm thinking let a sample drawing and a more complete data file speaks for it self."
G-code is a programming language just like LISP is a programming language. People can program G-code differently for a CNC machine and still get the same result for the finished processed part. With that said, just like with LISP, there are rules that G-code follows, and so as long as the G-code program follows those rules, it will run on the CNC machine.
To describe each and every variation would be like describing each and every variation for how to program a LISP routine. Ideally, you should be able to pull anyone's valid G-code program from the internet and use it as a data file for the LISP routine I provided. The routine may not understand everything, and I am not asking it to, but ideally it should not fault out or miss XY points before reaching the end of the G-code program.
On a related note, rules can change, just like with LISP, sometime Autodesk changes commands within AutoCAD and that can break someone's existing LISP routine. Also, different machines might have slightly different forms of G-code, but again, I was not asking for help with making this LISP routine do everything. I was just trying to figure out how to better handle the X0.0 Y0.0 issue I found with the routine skipping that initial data point because the programs start-up values are 0.0, and the X999 Y999 issue I found because the program was using 999 as an end indicator of sorts. As I indicated above, I believe I have since fixed the 999 issue.