G-Code Minifier
Compress long toolpaths for older CNC controls (like vintage Fanuc or Haas) with strict memory limits by stripping non-essential characters.
Original File
Minified Result
How the G-Code Minifier Works
The minifier makes a program smaller by removing characters the control does not need and, if you allow it, by merging moves that do not change the path. It is aimed at older controls with very little program memory and at slow serial (DNC) links.
Each option can be switched on or off. Removing comments, blank lines, line numbers and spaces and compacting decimals only change how the program is written. The two merging options rewrite moves, so they need more care. Sizes are counted in bytes and shown in KB, where 1 KB is 1,024 bytes.
How It Works
Worked Examples
% O1001 (BRACKET) N10 G90 G17 G20 N20 G0 X0.0000 Y0.0000 N30 G1 Z-0.1000 F15.0 N40 X0.5000 N50 X1.0000 N60 X1.5000 N70 G3 X2.0000 Y0.5000 I0.0000 J0.5000 N80 X1.5000 Y1.0000 I-0.5000 J0.0000 N90 G0 Z0.1000 ; RETRACT N100 M30 %
% O1001 G90G17G20 G0X0.Y0. G1Z-0.1F15. X1.5 G03X1.5Y1.I0.J0.5 G0Z0.1 M30 %
- N40 to N60 move X the same way along one line, so only the last point, X1.5, is kept.
- N70 and N80 are two quarter arcs about the same centre (X1.5 Y0.5), so they become one half circle from X1.5 Y0 to X1.5 Y1.
- N30 keeps its own line because it carries a feed rate. Comments, the blank line, N numbers, spaces and trailing zeros are gone.
- Direction matters: G1 X2.0 followed by X0.5 is not merged, because jumping straight to X0.5 would leave X0.5 to X2.0 uncut. A G01 peck sequence such as Z-0.2, Z0.05, Z-0.4 is kept for the same reason.
Paste the original into the page with every option switched on and you will get the same output and the same size figures.
Tips for Using the Results
- Start with the safe options. Removing comments, blank lines and spaces and compacting decimals never change the path. If that saves enough, switch the two merging options off.
- Keep N numbers the program relies on. GOTO, M97 P and M99 P jumps refer to sequence numbers, and many shops restart part-way through a program by searching for an N number.
- Keep a commented master. Comments often hold tool lists, setup notes and messages shown at an M00 or M01 stop. Store the full version and send only the minified copy to the machine.
- Check merged arcs. A merged arc takes the centre of the first arc in the run, and centres up to 0.005 apart count as the same. A control with a tight arc radius check may alarm, so backplot the output in the G-Code 3D Viewer first.
- Check your control accepts no spaces. Most ISO-style controls read G0X1.Y1. without trouble, but confirm it in your control manual before you rely on it.
Frequently Asked Questions
Minified programs are harder to read and check. Keep the original, backplot the minified version and prove it out with single block before running it unattended.