About & help
CNC File Optimizer is a free tool for making and improving CNC programs: draw a design and get G-code without CAD, turn an STL model into roughing and finishing toolpaths, or optimize G-code you already have. It runs entirely in your browser: no file is ever uploaded, and once the page has loaded it works without a network connection.
Out of the box it is set up for a LUNYEE 3018 Pro Max — an all-metal 3018-class desktop router with a GRBL controller, a 500 W spindle and an ER11 collet for 1/8 in (3.175 mm) bits. Every number in that profile can be changed under Edit machine.
From idea to first cut on a 3018
- Make the file. In Create, set the stock size and material, draw or import the shapes, and give each one an operation: Cut out, Cut hole, Pocket, Engrave or Drill. Press Generate G-code and read the safety check. For a 3-D model, drop the STL on the home page instead.
- Hold the stock down — properly. A block that is only sitting on the bed will move the moment the bit touches it, and a loose part next to a spinning cutter is how bits break and fingers get hurt. Use the clamps that came with the machine on the threaded bed (keep them outside the frame of the job), or the tape-and-glue method: painter's tape on the bed, painter's tape on the underside of the stock, a thin line of superglue between the two tapes, press for a minute. Put a sacrificial spoilboard (a flat piece of MDF or plywood) under anything you cut all the way through.
- Mount the bit. Push it well into the ER11 collet (at least two thirds of the shank), tighten with both wrenches, and leave only as much sticking out as the depth of cut needs.
- Set the zero. Every file from this site expects X0 Y0 at the front-left corner of the stock and Z0 on the top of the stock (the red corner on the drawing; the header of each file says it again). Jog the bit over that corner and zero X and Y. For Z, lower the bit onto a piece of paper on the stock until the paper just drags, then zero Z (the paper is about 0.1 mm — close enough for wood). In GRBL terms that is
G10 L20 P1 X0 Y0 Z0; every sender has buttons for it. - Run the frame job. Download the frame file and run it first: with the spindle off it traces the outer limits of the cut at the safe height. Watch that the bit stays over the stock and clear of every clamp.
- Air cut. For a first run of anything new, zero Z about 10 mm above the stock and run the real file in the air. You will see the whole job at full speed without cutting anything. Then zero Z on the stock top again.
- Cut. Safety glasses on, hair and sleeves away, hand near the red E-stop button on the gantry. Start the file and stay with the machine. If it sounds wrong — screaming, chattering, bogging down — pause (feed hold) and reduce the feed override, or stop and take shallower passes.
- Changing bits. A 3018 has no tool changer. When a design needs a second bit, you get one file per bit (or, if you prefer, one file that pauses): run the first file, change the bit, set Z0 on the stock top again — the new bit sticks out a different amount — and run the next. Do not touch the X/Y zero.
- Free the part. Cut-outs are held by small tabs so they cannot come loose at the last moment. Cut the tabs with a chisel or a flush-cut saw and sand them off.
Sending the file to the machine
- Universal G-code Sender (UGS) — free, runs on Windows, macOS and Linux, shows the toolpath and has jog, zero and probe buttons. A good default.
- Candle — small and simple, shipped with many 3018 machines (Windows and Linux).
- CNCjs — runs in a browser tab, popular on a Raspberry Pi next to the machine.
- The offline controller — the little hand-held box with an SD card: copy the
.ncfile to the card, jog and zero with its buttons, then pick the file. It cannot show a preview, so the frame job matters even more.
All of them talk to GRBL over USB at 115200 baud. The files use only plain GRBL 1.1 codes — G0, G1, G20/G21, G90, G94, G17, G4, M3, M5, M0 and M30 — with no tool changes, canned cycles or tool-length offsets.
Feeds and speeds in one minute
Three numbers decide whether a cut goes well: how fast the bit moves sideways (feed), how deep each pass is, and how fast it spins. A 3018 is light and flexes, so it likes shallow passes at moderate feeds: about half a bit-diameter deep in softwood, a quarter in hardwood such as oak, a tenth or less in aluminum. The starter numbers this site fills in for each material and bit are deliberately conservative starting points, not measurements from your machine — change them freely. Signs you should back off: burning or smoke (feed too slow or bit dull), a rough fuzzy edge or loud chatter (too deep or too fast), the bit visibly bending, lost steps (the cut ends up shifted). Small bits (1 mm, 1.5 mm) snap easily: shallow passes and gentle plunges.
Spindle speed. GRBL turns the S word into spindle power through its $30 setting (“S value at full speed”). The machine profile assumes 10,000 rpm at full speed; if your controller has $30=1000, set Spindle maximum to 1000 in Edit machine so that S1000 means full speed. If the spindle is on a manual speed knob, the S word is ignored — set the knob.
Create mode
Create is a 2-D drawing of your stock seen from above, to scale, plus a list of operations.
- Shapes — rectangle (with corner radius), circle / ellipse, polygon, star, line / polyline, freehand, and text. Move, resize and rotate with the handles or type exact numbers; snap to a grid; align; duplicate; undo and redo. Work in millimeters or inches.
- Text — three single-line engraving fonts (the bit follows each stroke once: fast, and right for a V-bit) and a bold outline font whose letters are closed shapes you can pocket or cut out. You can also load your own TrueType font (
.ttf); Convert to outlines freezes the letters into the design. - Import — SVG (paths with curves and arcs, basic shapes, transforms, real-world units), DXF (lines, arcs, circles, ellipses, polylines with bulges, splines; touching pieces are joined), or a picture: clean black-and-white art is traced into outlines, and a grayscale picture can be carved as a relief through the STL flow.
- Operations — Cut out (outside the line, through the stock, with holding tabs), Cut hole (inside the line), Pocket (clear the inside to a depth, around islands), Engrave (bit centered on the line — also the way to use a V-bit), Drill (peck drilling at the center of each shape) and Face the stock. Deep cuts are split into passes, the bit ramps into the material along the cut instead of plunging, and the order is automatic: inside features first, the cut-outs that free the part last.
- Output — GRBL G-code with a plain-words header (stock, zero, bit, depths, time), a 3-D preview, one file per bit, the frame job, and Open in the optimizer to fit arcs and shrink the file.
- Templates — coaster, name sign, finger-joint box, spur gear and spoilboard surfacing; each creates ordinary shapes you can edit.
How offsets are computed. The bit has a width, so it must run half a diameter beside the line. Instead of shifting each edge (which goes wrong on self-touching outlines, letters with counters and overlapping shapes), the design is turned into an exact distance field on a fine grid and the tool path is the contour where the distance equals the bit radius. Sharp inside corners of the path are blunted by a few hundredths of a millimeter — always away from the part.
The safety check in Create. A second, independent piece of code that shares nothing with the planner goes back to your drawing and measures every sampled tool position against it: profile and pocket cuts never enter material that must stay (limit 0.03 mm), engraving and drilling stay on their lines and points, nothing cuts deeper than asked, every holding tab is really left standing, sideways rapids happen only at the safe height, and the job fits the machine. Then the written file is parsed back and compared with the plan move for move. If any check is red, the download asks you first. What it cannot check is the real world: where the stock actually is, whether it is clamped, whether the bit in the collet is the one in the file.
Fonts. The single-line fonts are the Hershey fonts, originally created by Dr. A. V. Hershey while working at the U. S. National Bureau of Standards; the format of the font data was originally created by James Hurt, Cognition, Inc., 900 Technology Park Drive, Billerica, MA 01821. The outline font is a Latin subset of DejaVu Sans Bold (Bitstream Vera license; DejaVu changes are in the public domain) — see its license.
Optimizing G-code
Drop any G-code file (.nc, .gcode, .tap, .ngc, .cnc, .txt, .mpf …). The file is read by a real modal interpreter — it tracks G0–G3, G90/G91, planes, units, arc-center modes, canned cycles, cutter compensation, tool offsets and work offsets — so every move has a known start and end point before anything is changed. Then, depending on your settings:
- Arc fitting replaces runs of short straight moves that lie on a circle with one G2/G3 arc, within the tolerance you set. Generated arcs start exactly where the machine is.
- Simplification removes points that move the path by less than the line tolerance (Douglas–Peucker, in 3-D).
- Output resolution is the big lever when a file has far more moves than your controller needs — typical of 3-D surfacing programs that step every few hundredths of a millimeter. Choose High, Medium, Low or Draft (or enter your own figure) and the cut is rebuilt from far fewer, longer moves, each within that distance of the original path: 0.02, 0.05, 0.1 or 0.25 mm. Expect 80–95 % fewer moves on dense files. The deviation can be in any direction, into the part as well as away from it, so keep Full for a finishing pass that must hold size. Move end points are always taken from the original program, so the deepest cut and the envelope never change.
- Pass thinning keeps every n-th raster pass of finishing operations to reach a coarser stepover. Roughing and drilling are never thinned.
- Fusion 360 Personal files, which write rapids as G1 at the top feed rate, are detected; the link moves can be turned back into real G0 rapids.
- Retracts can be lowered to a safe height; canned cycles are expanded into plain moves for controllers without G81–G89; unsupported words are adapted for the target; 3D-printer commands are stripped from slicer files; numbers are normalized; a rotary wrap maps a flat axis onto a cylinder.
Moves inside cutter compensation (G41/G42), incremental (G91) sections, canned cycles and unknown syntax are always passed through untouched.
The safety self-check
Every result is re-parsed and compared with the original program before you see it:
- Envelope — the output never moves outside the original program's bounding box.
- Depth — the deepest Z is unchanged.
- Arcs — every generated arc resolves to a valid center and radius.
- Syntax — the output parses cleanly with no new warnings.
- Path — the output cutting path, sampled along its whole length, lies within the configured tolerances — or the chosen output resolution — (plus rounding) of the original cutting path, and — unless passes were deliberately thinned — every original cutting vertex is still on the output path. This is the check that catches a wrong arc or a mis-simplified corner.
If any check fails the download button turns amber and the failing check is explained. Please review such a file before running it — or loosen the settings and run again. As with any CAM output, always dry-run new programs above the stock first.
STL to toolpaths
Drop an STL model (binary or ASCII). Tell the tool which way is up and what units the model uses, choose a size (Shrink to fit my machine scales the model down evenly until it fits the travel), a material and a preset — Standard (1/8 in flat end mill to rough, 1/8 in ball nose to finish), Quick (roughing only) or Fine — and plan. The file card shows the size the model will be cut at and warns when it does not fit. With two bits you get one file per bit, plus the frame job. You get:
- Roughing — Z-level clearing with a flat, bull-nose or ball tool: raster plus a wall pass on every level, ramped entries, and links that climb only as high as the remaining stock requires. Each pocket is cleared completely before the tool moves on.
- Finishing — surface-following parallel passes, waterline contours, or a steep-and-shallow split, with a ball, bull-nose, flat or V tool.
- A gouge check on every move: roughing moves and all rapids are verified over every height-map cell they touch (cells are upper bounds of the surface, so this is a proof, not a sample); parallel finishing is verified by dense sampling against the exact triangle geometry. A path that fails this check is never offered without a warning.
Accuracy. Parallel finishing is computed with an exact drop-cutter against the model's triangles: the path stays within the path tolerance (0.01 mm by default) of the true tool-center surface, and never below it, on flat, sloped and near-vertical faces alike; it is then verified by dense sampling against the same exact geometry. Roughing, waterline finishing and all linking moves use the conservative height-map bound, so vertical walls there are resolved to about 1.5 × the grid resolution. Use the “Fine” grid for small, detailed parts; “Auto” picks a cell size that keeps planning to a few seconds. Roughing leaves the configured stock for finishing; a warning tells you where the finishing tool has to cut deeper than the roughing terraces (features the roughing tool could not enter).
Supported controllers
The target controller sets comment style, canned-cycle and tool-length-offset support, program end and line numbering:
Presets, privacy, offline
Settings and named presets are stored in your browser only (localStorage); you can export and import them as JSON. The site sets no cookies and loads nothing from third parties. It is a static page — you can save it and run it from a folder.
Tips
- Paste G-code text anywhere on the page to load it without a file.
- In the 3-D preview: drag to orbit, shift-drag or right-drag to pan, wheel to zoom,
Fto fit,1/3/5/7for top/right/front/iso. The Z slider peels the program layer by layer. - Click a line in the text view to highlight that point in the 3-D preview.
- Big files (hundreds of thousands of lines) are fine — everything runs in a background thread and can be canceled.