Format · DWG
DWG reader for Rust, Python and JavaScript
Read DWG files from R14 to 2018 in Rust, Python, JavaScript (WebAssembly) and C with cadkit: layers, blocks, layouts and entities, without a vendor SDK.
What is supported
| Format | Read | Write | Status |
|---|---|---|---|
| DWG | ReadAC1014 (R14) to AC1032 (2018), including 2007 | No writer | Read-only. R13 (AC1012) is untested; entity coverage is still growing. |
Supported
- Versions AC1014 (R14), AC1015 (2000), AC1018 (2004), AC1021 (2007), AC1024 (2010), AC1027 (2013) and AC1032 (2018)
- Model space, paper layouts, layers, linetypes, text styles and block definitions
- Lines, points, circles, arcs, ellipses, splines, polylines and meshes, text and multiline text, attributes, block references, hatches, dimensions, leaders, faces, images and viewports
- Header-only inspection (version, units, code page) without decoding entities
- Export of the document as SVG, JSON, DXF, CityGML or (seed-based) DGN V8
Not supported yet
- Writing DWG: there is no DWG writer
- R13 (AC1012): implemented on the R14 code path, but untested for lack of a permissively licensed sample
- Password-protected (encrypted) files
- Multileaders, tables, subdivision meshes, PDF underlays, arc-length and large radial dimensions: kept as
unknownentities - ACIS solids and regions beyond their header; proxy-entity graphics
Read a DWG file
Open a drawing, print its version and layer count, and render model space as SVG. The reader detects the format, so the same code opens DGN and DXF.
fn main() -> Result<(), cadkit::Error> { let doc = cadkit::open("plan.dwg")?; println!("{} {} layers", doc.source.version, doc.layers.len()); std::fs::write("plan.svg", cadkit::to_svg(&doc, &cadkit::SvgOptions::new()))?; Ok(())}import cadkit
doc = cadkit.read("plan.dwg")print(doc.format, doc.version, len(doc.layers), "layers")with open("plan.svg", "w", encoding="utf-8") as f: f.write(doc.to_svg(width=1200))import { readFileSync } from "node:fs";import { read } from "cadkit-wasm/node";
const doc = read(readFileSync("plan.dwg"));console.log(doc.info().version, doc.layers().map((layer) => layer.name));doc.free();#include <stdio.h>#include "cadkit.h"
int main(void) { cadkit_document *doc = NULL; if (cadkit_read_file("plan.dwg", NULL, &doc) != CADKIT_OK) return 1; cadkit_info info; if (cadkit_document_info(doc, &info) == CADKIT_OK) printf("%llu layers\n", (unsigned long long)info.layer_count); cadkit_document_free(doc); return 0;}From the shell
The cadkit CLI inspects a DWG without decoding it, summarises it and lists layers and blocks.
cadkit inspect plan.dwg --json # header only: format, version, units, code pagecadkit info plan.dwg --warnings # summary plus the first 20 warningscadkit layers plan.dgn --json # DGN levels are layerscadkit blocks plan.dxf # block definitions with entity countscadkit dump plan.dxf --kind arc # one line per entity of a kind