CNC Router Toolpath Generator
Operator: Abdulla Al Fahad. How tools are built and checked
A drawing says where the edge of a part is; a CNC router needs to know where the centre of the cutter goes. Cut on the line and the part is a cutter's width too small or too large. From an SVG or DXF drawing the tool offsets the drawn paths by the cutter's radius, steps down in passes, adds holding tabs and ramps, and writes G-code for GRBL, Marlin or LinuxCNC.
It shows the cutting moves over a simulation of the stock being carved, so you can see an island that was left standing or a pocket that missed a corner before any wood is cut. It never connects to a machine.
Key features
- SVG paths, rectangles, circles, ellipses, polygons and lines, and DXF lines, polylines, circles and arcs, with units from the file or your own scale
- Profile outside, profile inside, cut on the line, pocket (offset rings or zig-zag with a wall pass) and drilling at circle centres
- Stepdown per pass, holding tabs with count, width and height, ramped or plunged entry, climb or conventional direction, and separate feed and plunge rates
- Pockets with islands, so a shape inside a pocket outline is left standing
- GRBL, Marlin and LinuxCNC output as named dialects, a material-removal preview and a run-time estimate
- Open shapes are joined end to end where their ends meet, so a drawing made of separate lines can still be profiled
Operations, scale and the G-code dialects
SVG curves are flattened to line segments with a chord error of 0.05 mm, and arcs in G-code are written as those short straight moves, not G2 or G3. Group and element transforms are applied; text, images and clones are skipped with a note, and an SVG with scripts or entities is refused.
The scale comes from the SVG's width and viewBox when the file has a physical size, otherwise 96 dpi is assumed; DXF files use their $INSUNITS header, otherwise millimetres. You can override either with millimetres per drawing unit, and the page states which rule it applied.
The program zero is the drawing's origin in X and Y and the top of the stock in Z. Cuts have negative Z. The three dialects differ in their header and footer (G21 G17 G90, or G54 and path blending for LinuxCNC with % delimiters, and an M2 end) and in how the spindle is started.
Polygon work uses the Clipper2 library (Boost licence). Its own offset routine gave wrong shapes for shrinking polygons in the version used here, so offsets are built from exact union and difference operations on capsule-shaped buffers of every edge.
How it works
An outside profile grows the closed shape by the tool radius, an inside profile shrinks it by that radius, and each result's boundary becomes the path, run CCW for climb cutting outside and CW inside. Pockets repeatedly shrink the region by the stepover until nothing is left and cut the rings from the middle outward, so the last ring is the wall.
Each ring is cut at every depth level from the stepdown to the final depth. A ramp descends along the ring at your angle; on the last pass the ramped stretch is retraced at full depth. Tabs split the path where they begin and end so the tool rises straight up over each.
The simulation stamps a flat disc of the tool's size along every cutting move into a height grid and shades it by depth.
Typical uses
- A sign shop cuts 12 plywood letters from an SVG with tabs, so the letters stay in the sheet until the end.
- A maker routes a 45 × 90 mm tray pocket with a 6 mm cutter and a 10 mm island, with a wall pass for a clean edge.
- A hobbyist drills 6 mm holes at the circle centres of a DXF bracket before profiling its outline.
Building one
- Open an SVG or DXF and check the scale line under the file.
- Enter the tool diameter, safe height, rates and spindle speed, and pick a dialect.
- Add an operation, choose its type, tick its shapes and set depth and stepdown.
- Add tabs or a pocket style if needed, then press Generate toolpath.
- Check the preview and warnings, run the file in a simulator, then download the .nc file.
- Air-cut at a safe height on the machine before cutting stock.
Example
An SVG with a 50 mm square, a 30 × 25 mm rectangle for a pocket, a 20 × 20 mm square with a 10 × 10 mm island, and a 6 mm circle; 6 mm flat end mill
Profile the square outside, 6 mm deep, 2 mm stepdown, plunge entry; pocket the rectangle 3 mm deep at 40% stepover; island pocket; drill the circleToolpath extents, pocket coverage and tab length
The outside profile's toolpath measured 56.000 × 56.000 mm (50 plus the 6 mm cutter), the inside profile 44.000 × 44.000 mm. The pocket reached the full depth over 99.76% of its interior cells (the rest is the rounded corner cusp a 6 mm tool must leave) and cut nothing outside its outline. The 10 × 10 mm island was untouched in all 100 sampled cells. With four 6 mm-wide tabs on the square, 24.00 mm of the last pass ran at tab height.Tips for best results
- Profile inside shapes before the outside, so the part is still held by the stock when you cut the holes.
- Use tabs on any profile that cuts the part free, and set the height to about a third of the material thickness.
- Choose ramp entry in wood and plunge in soft foam; ramps are skipped on the passes where tabs apply.
- Start at a conservative stepdown, around half the cutter's diameter, and adjust from there.
Things to check before you rely on it
A flat end mill cannot cut sharp inside corners. The pocket's corners come out with the tool's radius, which the preview shows.
Self-intersecting or doubled paths in an SVG can produce odd offsets. Clean the drawing and remove duplicate paths first.
Feeds and speeds here are yours. The page does not know your machine, tool or material.
Text in the drawing is skipped; convert it to paths first.
Common errors and how to fix them
- A shape is skipped as too small for the tool
- A hole smaller than the cutter cannot be cut inside; use a smaller tool or drill it.
- An open path was ignored in an outside or inside profile
- Only closed shapes can be cut outside or inside. Join its ends in the drawing, or use On the line.
- Tabs are rejected
- Tab height must be below the cut depth and the count, width and height positive.
Best practices
- Run the G-code through a simulator such as CAMotics before the machine sees it.
- Set the zero on the stock top with a touch plate or paper, and check the safe height clears your clamps.
- Keep the first run an air cut, a few millimetres above the stock.
Safety
The G-code written here is a set of instructions for a machine that can injure people and break tools. It cannot see your stock, clamps or zero, and a mistake in any of them cuts the wrong thing. Treat every file as untested until you have simulated it and air-cut it, stay by the stop button while it runs, and wear eye and ear protection.
Frequently asked questions
Can it cut arcs as G2 and G3?
Not in this version. Curves are written as short straight moves with 0.05 mm chord error, which every controller accepts but which makes larger files.
How does climb versus conventional get chosen?
For a clockwise spindle, climb cuts an outside profile counter-clockwise and an inside profile or pocket clockwise. Pick conventional to reverse that, and note that On the line follows the drawn direction.
Why is my estimated time different from the machine's?
The estimate adds each move's length divided by its feed, with rapids at the rate you gave and no acceleration or look-ahead, so a real machine is usually slower on short moves.
Does it write an op for engraving a V-bit?
No. It assumes a flat end mill; use On the line with a V-bit only if you accept a constant depth.