Format · DXF
DXF reader and writer for Rust, Python and JavaScript
Read ASCII and binary DXF from R12 to 2018 and write ASCII DXF in any of seven versions with cadkit, from Rust, Python, JavaScript (WebAssembly) and C.
What is supported
| Format | Read | Write | Status |
|---|---|---|---|
| DXF | ReadASCII and binary, R12 to 2018 | WriteASCII, R12 to 2018 | Entity coverage is still growing. |
Supported
- Reading ASCII and binary DXF, R12 to 2018, with code page detection and a fallback code page for files that declare none
- Model space, layouts, layers, linetypes, text styles and blocks
- Lines, points, circles, arcs, ellipses, splines, polylines and meshes, text and multiline text, attributes, block references, hatches, dimensions, leaders, faces, images and viewports
- Writing ASCII DXF as R12, R2000, R2004, R2007, R2010, R2013 or R2018, also with legacy 8-bit output code pages such as
DOS857 - The same document from DWG, DGN or CityGML, written as DXF
Not supported yet
- Writing binary DXF
- 3D solids, regions, subdivision meshes, multileaders, multilines, tables, wipeouts, rays, construction lines and shapes: read as
unknownentities with their group codes, not written back - Complex linetype elements, hatch gradients, group objects, dimension style variables and viewport frozen-layer lists
- Code-page selection in
\M+double-byte character escapes is best effort
Read DXF and write another version
Open a DXF file and write it as R2000. The writer creates the tables and handles each version needs; see the writer notes for what each version keeps.
fn main() -> Result<(), cadkit::Error> { let doc = cadkit::open("plan.dxf")?; // ASCII or binary let dxf = cadkit::to_dxf(&doc, cadkit::DxfVersion::R2000)?; std::fs::write("plan-r2000.dxf", dxf)?; Ok(())}import cadkit
doc = cadkit.read("plan.dxf") # ASCII or binaryprint(doc.format, doc.version, len(doc.layers), "layers")with open("plan-r2000.dxf", "w", encoding="utf-8") as f: f.write(doc.to_dxf(version="r2000"))import { readFileSync, writeFileSync } from "node:fs";import { read } from "cadkit-wasm/node";
const doc = read(readFileSync("plan.dxf")); // ASCII or binarywriteFileSync("plan-r2000.dxf", doc.toDxf("r2000"));doc.free();#include <stdio.h>#include "cadkit.h"
int main(void) { cadkit_document *doc = NULL; char *dxf = NULL; if (cadkit_read_file("plan.dxf", NULL, &doc) != CADKIT_OK) return 1; /* ASCII or binary */ if (cadkit_document_to_dxf(doc, CADKIT_DXF_R2000, &dxf) == CADKIT_OK) { FILE *out = fopen("plan-r2000.dxf", "wb"); if (out) { fputs(dxf, out); fclose(out); } cadkit_string_free(dxf); } cadkit_document_free(doc); return 0;}DXF to SVG from the shell
More options, and the same task in every language, are in Convert DXF to SVG.
cadkit convert plan.dxf plan.svg --width 1600cadkit convert plan.dxf walls.svg --width 1600 --layer WALLS # one layercadkit convert plan.dxf layout.svg --model 1 # a paper layoutcadkit convert - plan.svg --explode-inserts --units mm < plan.dxf # from stdin