Translates 2D DXF files into KCL (KittyCAD Language) sketch profiles for use in Zoo Design Studio. The output is a .kcl file containing one sketch() block per profile, ready to open or import directly.
Reads a DXF file and emits a KCL 2.0 source string. Each closed or open geometric profile in the DXF becomes a sketch(on = XY) block. Standalone circles get their own sketch block. No extrusion is added — the output is purely 2D sketch geometry.
| Entity | Notes |
|---|---|
LINE |
Direct mapping |
ARC |
CCW only; see workarounds below |
CIRCLE |
Direct mapping |
LWPOLYLINE |
Bulge arcs expanded; mixed CCW/CW profiles supported (see workarounds) |
POLYLINE (legacy R12) |
Same bulge expansion as LWPOLYLINE |
INSERT |
Block references recursively expanded into modelspace |
ELLIPSE |
Approximated as chained line segments via flattening(0.01mm) |
SPLINE |
Approximated as chained line segments via flattening(0.01mm) |
Entities not in this table (HATCH, TEXT, MTEXT, DIMENSION, 3DFACE, etc.) are silently ignored — they have no KCL equivalent.
All output targets KCL 2.0:
@settings(defaultLengthUnit = mm, kclVersion = 2.0)
sketch001 = sketch(on = XY) {
line(start = [var 0, var 0], end = [var 10, var 0])
arc(start = [var 10, var 0], end = [var 10, var 6], center = [var 10, var 3])
...
}Units are read from the DXF $INSUNITS header and mapped to the nearest KCL unit (mm, cm, m, in, ft); files with no unit header default to mm.
DXF allows polylines with a mix of CCW and CW arc segments. In a profile where CCW and CW arcs alternate (e.g. an S-wave), the CW arcs are approximated as dense line segments rather than true arcs. Geometry is preserved to within 0.01mm. All-CW profiles (every arc clockwise) are translated faithfully as true arcs.
DXF ELLIPSE and SPLINE entities have no direct KCL equivalent and are approximated as chained line segments with a maximum chord-height deviation of 0.01mm.
from parser.dxf_reader import read_dxf
from emitter.kcl_writer import emit_kcl
kcl = emit_kcl(read_dxf("part.dxf"))
print(kcl)python scripts/translate.py part.dxf
The package exposes an MCP server with two tools:
translate_dxf— translates a DXF file and returns the KCL stringpreview_entities— returns a count of each DXF entity type without translating
Add to your MCP host config (Claude Desktop, Cursor, etc.):
{
"mcpServers": {
"dxf-to-kcl": {
"command": "dxf-to-kcl"
}
}
}For Claude Desktop the config file is ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows).
Requires Python 3.11+.
pip install -e .
Dependencies: ezdxf, mcp.
python -m ruff check .
python -m pyright parser/ emitter/
pytest
Tests run in two tiers per fixture: exact golden file match (always runs) and KCL syntax validation via zoo kcl format (requires the Zoo CLI, auto-skipped otherwise).