Skip to main content

Crate acadrust

Crate acadrust 

Source
Expand description

§acadrust

A pure Rust library for reading, writing, and inspecting CAD files in DXF (ASCII and binary) and native binary DWG formats. DXF support spans R12 through R2018+; DWG support spans R12 through R2018+.

§Highlights

  • 48 top-level EntityType variants for geometry, annotations, dimensions, meshes, solids, regions, bodies, and surfaces.
  • ACIS/SAT/SAB parsing and writing, including solid history and primitive builders.
  • Tables and objects for layers, styles, dictionaries, layouts, fields, materials, and associative data.
  • Failsafe reads with bounded ReadDiagnostic values and aggregate ReadStats returned by DxfReader::read_with_stats and DwgReader::read_with_stats.
  • Automatic code-page handling for older drawings.
  • Optional Serde serialization and 3D import support.
  • ACAD Arch classes: preserve native AEC records, construct straight walls, doors, and windows, and edit supported parameters. See classes::arch.

§Feature Flags

FeatureDefaultDescription
parallelYesRayon parallelism for native DWG reading and writing.
serdeNoEnables serde::Serialize and serde::Deserialize implementations.
importNoEnables STL, COLLADA, OBJ, glTF/GLB, and FBX importers.
[dependencies]
acadrust = { version = "0.6.8", features = ["serde", "import"] }

Use default-features = false to omit acadrust’s Rayon dependency and run DWG work sequentially on the calling thread:

[dependencies]
acadrust = { version = "0.6.8", default-features = false }

Cargo features are additive, so another dependency can enable parallel. Applications already disabling default features must explicitly enable parallel to retain native parallelism. WebAssembly stays sequential.

§Limit DWG Concurrency

With parallel enabled on native targets, DWG reads and writes use the current Rayon pool, falling back to Rayon’s shared global pool. Add rayon = "1" to your application’s dependencies, create a pool once, and reuse it for all batches to share a worker limit with acadrust’s internal work:

use acadrust::DwgReader;
use rayon::prelude::*;

let pool = rayon::ThreadPoolBuilder::new().num_threads(4).build()?;
let paths = ["first.dwg", "second.dwg"];
let counts: Vec<usize> = pool.install(|| {
    paths.par_iter().map(|path| {
        let mut reader = DwgReader::from_file(path)?;
        let doc = reader.read()?;
        Ok(doc.entities().count())
    }).collect::<acadrust::Result<_>>()
})?;
println!("Entity counts: {counts:?}");

Wrap DWG writes in pool.install too. Calls outside this pool and separate pools are not covered by its limit. A one-thread pool still uses a Rayon worker; disabling parallel keeps acadrust’s work on its calling thread.

§Quick Start — DXF

use acadrust::DxfReader;
use acadrust::DxfWriter;

let doc = DxfReader::from_file("input.dxf")?.read()?;
println!("Entities: {}", doc.entities().count());
DxfWriter::new(&doc).write_to_file("output.dxf")?;

§Quick Start — DWG

use acadrust::{CadDocument, Color, DwgReader, DwgWriter, EntityType, Line};

let mut reader = DwgReader::from_file("input.dwg")?;
let doc = reader.read()?;
println!("Entities: {}", doc.entities().count());

let mut output = CadDocument::new();
let mut line = Line::from_coords(0.0, 0.0, 0.0, 100.0, 50.0, 0.0);
line.common.color = Color::RED;
output.add_entity(EntityType::Line(line))?;
DwgWriter::write_to_file("output.dwg", &output)?;

§Failsafe Reading and Diagnostics

Set DxfReaderConfiguration::failsafe to continue past recoverable record errors. The returned ReadOutcome contains the document plus source/decode counts and structured diagnostics; strict mode remains the default.

use acadrust::{DxfReader, DxfReaderConfiguration};

let config = DxfReaderConfiguration { failsafe: true, ..Default::default() };
let outcome = DxfReader::from_file("drawing.dxf")?
    .with_configuration(config)
    .read_with_stats()?;
println!("{} entities, {} diagnostics", outcome.stats.output_entities,
    outcome.stats.diagnostics.len());

§Optional 3D Imports

With features = ["import"], import_file auto-detects STL, COLLADA, OBJ, glTF/GLB, and FBX by extension and converts them to a CadDocument.

use acadrust::{import_file, ImportConfig};

let doc = import_file("model.glb", &ImportConfig::default())?;
println!("Imported {} entities", doc.entities().count());

§Serde

With features = ["serde"], document types implement Serde traits and can be serialized to JSON using your chosen JSON crate.

use acadrust::{CadDocument, DxfReader};

let doc = DxfReader::from_file("drawing.dxf")?.read()?;
let json = serde_json::to_string(&doc).unwrap();
let restored: CadDocument = serde_json::from_str(&json).unwrap();
assert_eq!(restored.entities().count(), doc.entities().count());

§ACAD Arch

classes::arch recognizes AEC, structural, and building-systems classes. A same-version DWG save preserves the native class body. wall, door, and window build an AC1032 drawing from parameters. decode reads any Arch class, and supported setters update native parameters together with cached graphics. The calling guide is src/classes/arch/API.md.

§Module Overview

ModuleContents
documentCadDocument — central drawing container
entities48 top-level entity variants
entities::modificationEntity explosion, mirroring, transforms, and translation
tablesTable entries such as Layer and LineType
objectsNon-graphical objects, dictionaries, layouts, and styles
typesPrimitives such as Vector3, Color, and DxfVersion
ioDXF, DWG, and optional import readers and writers
entities::acisACIS/SAT/SAB parsing, writing, and primitive builders
notificationStructured parse notifications and recovery counts
classes::archACAD Arch entities, objects, constructors, and edits

§File Version Support

CodeACADDXFDWG
AC1009R11/R12R/WR/W
AC1012R13R/WR/W
AC1014R14R/WR/W
AC10152000R/WR/W
AC10182004R/WR/W
AC10212007R/WR/W
AC10242010R/WR/W
AC10272013R/WR/W
AC10322018+R/WR/W

DXF R11/R12 is written as R13 unless requested explicitly with DxfWriter::with_version, which emits a genuine R12 file and converts newer entities to R12 entities.

R/W describes the format-level reader and writer paths. Entity availability varies by file version. See the R11/R12 support status for confirmed AC1009 fidelity gaps. DXF export promotes R11/R12 documents to R13 or later. Compatibility results describe tested fixtures and CAD-engine audits rather than a guarantee for every possible drawing.

Re-exports§

pub use audit::AuditIssue;
pub use audit::AuditIssueCode;
pub use audit::AuditLocation;
pub use audit::AuditReport;
pub use audit::AuditSeverity;
pub use audit::RepairAction;
pub use audit::RepairReport;
pub use error::DxfError;
pub use error::Result;
pub use types::BoundingBox2D;
pub use types::BoundingBox3D;
pub use types::Color;
pub use types::DxfVersion;
pub use types::Handle;
pub use types::LineWeight;
pub use types::Transparency;
pub use types::Vector2;
pub use types::Vector3;
pub use entities::Arc;
pub use entities::Circle;
pub use entities::Ellipse;
pub use entities::EmbeddedEntity;
pub use entities::Entity;
pub use entities::EntityType;
pub use entities::Line;
pub use entities::LwPolyline;
pub use entities::MText;
pub use entities::Point;
pub use entities::Polyline;
pub use entities::ProxyGraphicRecord;
pub use entities::ProxyGraphics;
pub use entities::ProxyUnicodeText;
pub use entities::Spline;
pub use entities::Text;
pub use tables::AppId;
pub use tables::BlockRecord;
pub use tables::DimStyle;
pub use tables::Layer;
pub use tables::LineType;
pub use tables::Table;
pub use tables::TableEntry;
pub use tables::TextStyle;
pub use tables::Ucs;
pub use tables::VPort;
pub use tables::View;
pub use tables::VxTableRecord;
pub use document::BlockGraph;
pub use document::CadDocument;
pub use document::Preview;
pub use document::PreviewFormat;
pub use document::SemanticEntityV1;
pub use document::SemanticInventoryV1;
pub use document::SemanticNodeV1;
pub use document::SemanticObjectV1;
pub use document::SemanticPartV1;
pub use document::SemanticReferenceV1;
pub use document::SemanticRelationshipKindV1;
pub use document::SemanticTableRecordV1;
pub use document::SolidHistoryGraph;
pub use document::SEMANTIC_INVENTORY_VERSION;
pub use layer_state::LayerState;
pub use layer_state::LayerStateLayer;
pub use layer_state::LayerStateMask;
pub use io::dwg::DwgReadOptions;
pub use io::dwg::DwgReader;
pub use io::dwg::DwgWriter;
pub use io::dwg::MeshFaceBudget;
pub use io::dxf::DxfOmission;
pub use io::dxf::DxfReader;
pub use io::dxf::DxfReaderConfiguration;
pub use io::dxf::DxfWriter;
pub use io::read::push_read_diagnostic;
pub use io::read::ReadDiagnostic;
pub use io::read::ReadOutcome;
pub use io::read::ReadStage;
pub use io::read::ReadStats;
pub use io::read::SourceFormat;
pub use io::read::MAX_READ_DIAGNOSTICS;
pub use io::recover::RecoverOutcome;
pub use entities::acis::primitives;
pub use entities::acis::SabReader;
pub use entities::acis::SabWriter;
pub use entities::acis::SatParser;
pub use entities::acis::SatWriter;
pub use entities::acis::SatDocument;
pub use entities::acis::SatHeader;
pub use entities::acis::SatPointer;
pub use entities::acis::SatRecord;
pub use entities::acis::SatToken;
pub use entities::acis::SatVersion;

Modules§

audit
Structural integrity checks and conservative repair for CAD documents.
classes
DXF class definitions (CLASSES section)
compound_file
Microsoft Compound File Binary (CFB) storage used by OLE and VBA payloads.
count
document
Central CAD document structure.
entities
Graphical entity types.
error
Error types for acadrust.
fields
Dynamic text field (AcDbField) evaluation engine.
io
File I/O for DXF and DWG formats.
layer_state
Native ACAD layer-state storage.
nested_copy
notification
Parse notification / diagnostic system.
objects
Non-graphical objects (OBJECTS section)
plot_style
Plot style tables: the CTB (color-based) and STB (named) files a plot reads its pens from.
sheet_set
tables
Table types and the generic Table container.
types
Core types used throughout acadrust.
vba
Semantic Microsoft Office VBA project streams stored in OLE compound files.
xdata
Extended Data (XDATA) support

Constants§

VERSION
Library version