Skip to content
cadkithome
Menu

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

FormatReadWriteStatus
DXFReadASCII and binary, R12 to 2018WriteASCII, R12 to 2018Entity 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 unknown entities 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.

src/main.rs
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(())
}

DXF to SVG from the shell

More options, and the same task in every language, are in Convert DXF to SVG.

shell
cadkit convert plan.dxf plan.svg --width 1600
cadkit convert plan.dxf walls.svg --width 1600 --layer WALLS # one layer
cadkit convert plan.dxf layout.svg --model 1 # a paper layout
cadkit convert - plan.svg --explode-inserts --units mm < plan.dxf # from stdin

Reference