Converting DXF to G-code for CNC Machining: A Complete 2D Workflow
Many 2D CNC operations — such as laser cutting, plasma cutting, engraving, and milling — begin with a DXF (Drawing Exchange Format) file. This vector-based format must be converted into G-code to be understood by your CNC machine.
This guide explains:
- What a DXF file contains
- How to prepare it for toolpath generation
- Tools and methods for G-code conversion
- Common pitfalls to avoid
🧾 What is a DXF File?
- DXF = Drawing Exchange Format, developed by AutoDesk
- Contains 2D geometry: lines, arcs, polylines, splines
- Supported by most CAD tools like AutoCAD, Fusion 360, LibreCAD
Example content:
LINE (0,0) to (100,0)
ARC (center 50,50 radius 20)
🧰 Workflow: DXF to G-code
1. Create or Prepare DXF
- Use CAD software (e.g., Fusion 360, SolidWorks, AutoCAD, FreeCAD)
- Ensure:
- All geometry is on the same plane (XY)
- No duplicate or overlapping lines
- All curves are exploded or simplified if needed
- Units (mm/inch) are set correctly
2. Import into CAM Software
Tools:
- SheetCAM – For 2D plasma/laser/waterjet
- Fusion 360 Manufacture Tab
- EstlCAM, OpenBuilds CAM, dxf2gcode (free tool)
- VCarve, LightBurn (for laser engravers)
TIP: Use Layer naming to define operations (e.g., “cut”, “engrave”, “drill”)
3. Define Toolpaths
- Select geometry to assign operations
- Set parameters:
- Cut depth, lead-in/out, tool diameter, feed rate
- Choose cutting strategy:
- Outside contour, inside contour, pocket, or engraving
- Add tabs or bridges if needed
4. Simulate and Export G-code
- Preview the toolpath
- Check for open contours or missing paths
- Export with correct postprocessor for your machine (Mach3, GRBL, Fanuc…)
Example output:
G21 G90
G0 X0 Y0
G1 X100 Y0 F500
M30
⚠️ Common DXF-to-G-code Problems
| Problem | Cause | Fix |
|---|---|---|
| Missing lines | Open contours | Join geometry or close polylines |
| Jerky motion | Too many nodes | Simplify curves or reduce resolution |
| Wrong scale | Units mismatch | Confirm mm/inch in both CAD and CAM |
| Inverted cuts | Inside/outside confused | Check path direction (CW/CCW) |
🛠️ Free Tools You Can Try
| Tool | Type | OS |
|---|---|---|
| dxf2gcode | Open source converter | Windows/Linux |
| LibreCAD + CamBam | Free DXF + CAM | Windows |
| Inkscape + Gcodetools plugin | Vector to G-code | Cross-platform |
| OpenBuilds CAM | Browser-based | All |
📁 File Structure Best Practice
- Keep original DXF files in
/drawings/ - Keep generated G-code in
/gcode/ - Add revision history:
bracket_r1.dxf→bracket_r1.nc
✅ Summary
Converting DXF to G-code is a repeatable, structured process:
- Clean DXF geometry
- Import to CAM
- Define toolpaths with correct settings
- Export and test the G-code
“Great CNC parts begin with clean drawings.”
Leave a comment