I have a problem where I need to convert GCODE files (essentially .txts) to the correct format. Essentially I need to get rid of E-codes from a line (without otherwise altering it) and frame lines that had them with M-codes.
IE If a file contained the following text
G1 X0 Y0G1 X95.522 Y98.212G1 X95.669 Y98.424 E3.08527G1 X95.669 Y104.331 E4.73024G1 X104.331 Y95.669 E8.14186G1 X104.331 Y101.576 E9.78683G1 X101.576 Y104.331 E10.87210G1 X125.325 Y104.333G1 X101.576 Y106.221
I would like to turn it into
–
G1 X0 Y0G1 X95.522 Y98.212M182; G1 X95.669 Y98.424G1 X95.669 Y104.331G1 X104.331 Y95.669G1 X104.331 Y101.576G1 X101.576 Y104.331M183;G1 X125.325 Y104.333G1 X101.576 Y106.221
So basically look for blocks of lines of the form "G1 X<number> Y<number> E<number>" insert "M182;" before the first one and "M183;" after the last one. Then go through the document and delete everything of the form "E<number>"
Here's a pseudocode of how I think it would work
open filen=0;format="G1 X<number> Y<number> E<number>"for all lines one by one if line = format and n=0 create line above with M182 set n=1 end if line != format and n=1 create line above with M183 set n=0 end if textinline="E<number>" delete textinline endend
Best Answer