Skip to content

Handle DWG files

Every tool in the pure-ezdxf tier — survey_dxf_layers, extract_parcels, extract_annotations, list_sheets, measure_by_layer, render_svg — reads DXF only and returns an explicit error for DWG input:

{ "error": "extract_parcels reads DXF only; convert DWG to DXF first" }

This isn’t laziness. DWG is a closed, undocumented binary format; DXF is its documented text/binary sibling. ezdxf (like nearly every open-source CAD library) parses DXF natively and leaves DWG decoding to dedicated converters.

Either DXF flavor is fine, though: the analysis tools accept ASCII and binary DXF alike (the loader sniffs the encoding), so whichever encoding your converter emits works without a second conversion step.

The Open Design Alliance’s free (closed-source, registration-gated) batch converter is the fidelity benchmark. It handles every DWG version including current releases, converts round-trippably, and is what commercial tools embed. Command-line batch mode:

Terminal window
ODAFileConverter /input /output ACAD2018 DXF 0 1 "*.dwg"

Trade-offs: closed source, a manual download that can’t live in your Dockerfile without licensing care, and GUI-toolkit dependencies that make slim containers awkward.

GNU LibreDWG’s dwg2dxf is fully open source and packageable:

Terminal window
dwg2dxf -o site-plan.dxf site-plan.dwg

Trade-offs: coverage trails the format. Newer DWG versions and less-common entity types may drop or mangle; complex civil drawings are exactly where you’ll notice. Always sanity-check a LibreDWG conversion with survey_dxf_layers — if entity counts look implausibly low compared to the file size, the conversion lost content.

If you can ask the file’s author for anything, ask for a DXF (or better, an “exploded” AutoCAD-flavor export). This sidesteps conversion entirely and — for Civil 3D files — is the only path that recovers proxy-object graphics. See The Civil 3D interchange trap for why converters fundamentally can’t help with that class of file.

The FreeCAD-tier convert_cad_format tool can read DWG when FreeCAD itself has a DWG converter configured — FreeCAD delegates to an external ODA converter or LibreDWG under the hood, so the same trade-offs apply one layer down. In the default Docker image (built without FreeCAD), plan on converting before upload.

Situation Use
One-off file, fidelity matters ODA File Converter
Automated pipeline, open-source constraint LibreDWG, verified with survey_dxf_layers
You can reach the author Request DXF export from the source application
Civil 3D file with proxy objects Only a source-application export helps — read this first

Exercising a conversion pipeline needs real DWG input, and real DWG files you’re actually allowed to use are surprisingly hard to come by. These sources are all verified by download:

Source What you get License / access
GNU LibreDWG test suite (test/test-data/) The same example drawing saved across six format generations (r13 → 2018), a tiny 20 KB sample_2018.dwg, and per-entity micro-fixtures. The best cross-version corpus available. GPL
USDA Forest Service T&D drawing library 673 real engineering sheets, including genuinely ancient Release 10 (AC1006) files that stress old-format handling. US public domain
Autodesk official samples Blocks, tables, and annotation-scaling samples in 2007/2010 formats. Freely downloadable but not explicitly redistributable — fetch at test time rather than vendoring
Municipal standard-detail libraries Modern real-world sheets — e.g. the City of Raleigh publishes hundreds of DWG standard details on a public blob store. Public records

Quick identification trick: the first six bytes of a DWG are an ASCII version tag. head -c 6 file.dwg reads it directly — AC1006 is Release 10, AC1009 R11/R12, AC1015 2000, AC1018 2004, AC1021 2007, AC1024 2010, AC1027 2013, AC1032 2018. Handy for sorting a downloaded pile by format generation before pointing a converter at it.