Skip to main content

Crate acadrust

Crate acadrust 

Source
Expand description

§acadrust

A pure Rust library for reading and writing CAD files in DXF and DWG formats.

acadrust provides comprehensive support for both file formats with a focus on correctness, type safety, and completeness. Inspired by ACadSharp, it brings full-featured CAD file manipulation to the Rust ecosystem.

§Highlights

  • DXF — Read and write ASCII and Binary DXF (R12 through R2018+)
  • DWG — Read and write native DWG binary files (R13 through R2018+)
  • 41 entity types, 9 table types, 20+ non-graphical objects
  • Type safe — strongly-typed entities, tables, and enums
  • Failsafe mode — error-tolerant parsing that collects diagnostics
  • Encoding support — automatic code page detection for pre-2007 files

§Quick Start — DXF

use acadrust::{CadDocument, DxfReader, DxfWriter};

// Read
let doc = DxfReader::from_file("input.dxf")?.read()?;
println!("Entities: {}", doc.entities().len());

// Write
DxfWriter::new(&doc).write_to_file("output.dxf")?;

§Quick Start — DWG

use acadrust::{CadDocument, DwgReader, DwgWriter};
use acadrust::entities::*;
use acadrust::types::Vector3;

// Read
let doc = DwgReader::from_file("input.dwg")?.read()?;

// Create and write
let mut doc = CadDocument::new();
let line = Line::from_coords(0.0, 0.0, 0.0, 100.0, 50.0, 0.0);
doc.add_entity(EntityType::Line(line))?;
DwgWriter::write_to_file("output.dwg", &doc)?;

§Module Overview

ModuleContents
documentCadDocument — the central drawing container
entities41 graphical entity types (Line, Circle, Spline, …)
tablesTable entries (Layer, LineType, TextStyle, DimStyle, …)
objectsNon-graphical objects (dictionaries, layouts, styles)
typesPrimitives (Vector3, Color, Handle, DxfVersion, …)
ioReaders and writers for DXF and DWG
classesDXF class definitions (CLASSES section)
xdataExtended data (XData) attached to entities
errorError types (DxfError) and Result alias
notificationStructured parse diagnostics

§File Version Support

CodeAutoCADDXFDWG
AC1009R12R/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

Re-exports§

pub use error::DxfError;
pub use error::Result;
pub use types::DxfVersion;
pub use types::BoundingBox2D;
pub use types::BoundingBox3D;
pub use types::Color;
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::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::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 document::CadDocument;
pub use io::dxf::DxfReader;
pub use io::dxf::DxfWriter;
pub use io::dwg::DwgReader;
pub use io::dwg::DwgReadOptions;
pub use io::dwg::DwgWriter;

Modules§

classes
DXF class definitions (CLASSES section)
document
Central CAD document structure.
entities
Graphical entity types.
error
Error types for acadrust.
io
File I/O for DXF and DWG formats.
notification
Parse notification / diagnostic system.
objects
Non-graphical objects (OBJECTS section)
tables
Table types and the generic Table container.
types
Core types used throughout acadrust.
xdata
Extended Data (XDATA) support

Constants§

VERSION
Library version