Skip to content
cadkithome

Inspect a drawing and its layers

Inspection comes in two depths. A header inspection reads only what the file declares about itself: format, version, units, code page and, where the format records it, whether the drawing is 3D and which application wrote it. It does not decode entity streams, so it is cheap even for large files. A full read gives you every layer, block, model, entity and warning.

Each program takes the file as its first argument and works the same for DWG, DGN and DXF.

src/main.rs
use std::collections::BTreeMap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let path = std::env::args().nth(1).ok_or("usage: inspect_drawing <file>")?;
let header = cadkit::inspect_file(&path)?; // header only: no entity decoding
println!("{:?} {} {:?}", header.format, header.version, header.units);
let doc = cadkit::open(&path)?;
let mut per_layer: BTreeMap<&str, usize> = BTreeMap::new();
for entity in doc.models.first().map(|m| m.entities.as_slice()).unwrap_or_default() {
*per_layer.entry(entity.layer.as_deref().unwrap_or("0")).or_default() += 1;
}
for layer in &doc.layers {
let state = if layer.visible { "on" } else { "off" };
let count = per_layer.get(layer.name.as_str()).copied().unwrap_or(0);
println!("{:<24} {state:<4} frozen={} {count} entities", layer.name, layer.frozen);
}
for warning in doc.warnings.iter().take(20) {
println!("warning: {} {}", warning.code, warning.message);
}
Ok(())
}

The C API returns the header and the summary as JSON strings. cadkit_document_info gives the counts as a plain struct, and the full document JSON (cadkit_document_to_json) has the layer table.

shell
cadkit inspect plan.dwg --json # header only: format, version, units, code page
cadkit info plan.dwg --warnings # summary plus the first 20 warnings
cadkit layers plan.dgn --json # DGN levels are layers
cadkit blocks plan.dxf # block definitions with entity counts
cadkit dump plan.dxf --kind arc # one line per entity of a kind
  • Layers. DGN levels are reported as layers. Each layer has visible, frozen and locked flags and a colour. An entity’s layer names its layer; entities without one belong to the default layer.
  • Entity kinds. Points, lines, polylines, circles, arcs, ellipses, splines, text and multiline text, block references (insert), hatches, dimensions, leaders, faces, polygons, meshes, images, viewports and groups. Records a reader cannot model become unknown entities rather than being dropped.
  • Warnings have a stable code (for example dgn.unknown_element.type_36), a message and, where known, the byte offset in the file. They mean the reader kept going past something it could not fully decode.
  • Format-specific data that the neutral model has no field for is kept in props with a dwg., dgn., dxf. or gml. key prefix.

The full shape is in the document JSON schema.