| Crates.io | dxf-tools-rs |
| lib.rs | dxf-tools-rs |
| version | 0.1.4 |
| created_at | 2026-01-20 13:18:58.152559+00 |
| updated_at | 2026-01-20 22:47:50.940497+00 |
| description | A pure Rust library for reading and writing CAD files in DXF format (ASCII and Binary) |
| homepage | https://github.com/hakanaktt/dxf-tools-rs |
| repository | https://github.com/hakanaktt/dxf-tools-rs |
| max_upload_size | |
| id | 2056535 |
| size | 1,327,097 |
A high-performance, pure Rust library for reading and writing CAD drawing exchange files.
DXF-Tools-RS provides comprehensive support for CAD file formats with a focus on performance, memory efficiency, and ease of use. Inspired by ACadSharp, this library brings the power of CAD file manipulation to the Rust ecosystem.
| Version Code | Description |
|---|---|
| AC1012 | R13 |
| AC1014 | R14 |
| AC1015 | 2000 |
| AC1018 | 2004 |
| AC1021 | 2007 |
| AC1024 | 2010 |
| AC1027 | 2013 |
| AC1032 | 2018+ |
Complete support for all standard tables:
| Table | Description |
|---|---|
| Layer | Drawing layers with color, linetype, and visibility |
| LineType | Line patterns and dash definitions |
| TextStyle | Font and text formatting settings |
| DimStyle | Dimension appearance and behavior |
| BlockRecord | Block definition registry |
| AppId | Application identifier registry |
| View | Named view configurations |
| VPort | Viewport configurations |
| UCS | User coordinate system definitions |
Full support for application-specific extended data:
Add DXF-Tools-RS to your Cargo.toml:
[dependencies]
dxf-tools-rs = "0.1.4"
Or install via cargo:
cargo add dxf-tools-rs
use dxf_tools_rs::{CadDocument, DxfReader};
fn main() -> dxf_tools_rs::Result<()> {
// Open and read a file
let doc = DxfReader::from_file("drawing.dxf")?.read()?;
// Access document properties
println!("Version: {:?}", doc.header().version);
// Iterate over entities
for entity in doc.entities() {
println!("Entity: {:?}", entity);
}
Ok(())
}
use dxf_tools_rs::{CadDocument, DxfWriter, Line, Layer, Vector3};
fn main() -> dxf_tools_rs::Result<()> {
// Create a new document
let mut doc = CadDocument::new();
// Add a layer
let layer = Layer::new("MyLayer");
doc.layers_mut().add(layer)?;
// Create and add a line
let line = Line {
start: Vector3::new(0.0, 0.0, 0.0),
end: Vector3::new(100.0, 100.0, 0.0),
..Default::default()
};
doc.add_entity(line);
// Write to file
DxfWriter::new(&doc).write_to_file("output.dxf")?;
Ok(())
}
use dxf_tools_rs::{CadDocument, Layer, Color};
fn main() -> dxf_tools_rs::Result<()> {
let mut doc = CadDocument::new();
// Create a custom layer
let mut layer = Layer::new("Annotations");
layer.color = Color::from_index(1); // Red
layer.is_frozen = false;
layer.is_locked = false;
doc.layers_mut().add(layer)?;
// Access existing layers
if let Some(layer) = doc.layers().get("0") {
println!("Default layer color: {:?}", layer.color);
}
Ok(())
}
use dxf_tools_rs::{CadDocument, LwPolyline, LwVertex, Vector2, Circle, Arc};
fn main() -> dxf_tools_rs::Result<()> {
let mut doc = CadDocument::new();
// Create a rectangle using LwPolyline
let mut polyline = LwPolyline::new();
polyline.vertices = vec![
LwVertex { position: Vector2::new(0.0, 0.0), ..Default::default() },
LwVertex { position: Vector2::new(100.0, 0.0), ..Default::default() },
LwVertex { position: Vector2::new(100.0, 50.0), ..Default::default() },
LwVertex { position: Vector2::new(0.0, 50.0), ..Default::default() },
];
polyline.is_closed = true;
doc.add_entity(polyline);
// Create a circle
let circle = Circle {
center: Vector3::new(50.0, 25.0, 0.0),
radius: 10.0,
..Default::default()
};
doc.add_entity(circle);
Ok(())
}
DXF-Tools-RS uses a trait-based design for maximum flexibility and extensibility:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CadDocument โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Header โ โ Tables โ โ Entities โ โ
โ โ Variables โ โ โ โ โ โ
โ โโโโโโโโโโโโโโโ โ - Layers โ โ - Lines, Circles โ โ
โ โ - LineTypes โ โ - Polylines, Arcs โ โ
โ โโโโโโโโโโโโโโโ โ - Styles โ โ - Text, Dimensions โ โ
โ โ Blocks โ โ - DimStyles โ โ - Hatches, Splines โ โ
โ โ โ โ - VPorts โ โ - 3D Entities โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ Objects โโ
โ โ Dictionaries, Groups, Styles, PlotSettings, XRecords โโ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Trait | Purpose |
|---|---|
Entity |
Base trait for all graphical entities |
TableEntry |
Base trait for table entries (layers, styles, etc.) |
CadObject |
Common interface for all CAD objects |
| Type | Description |
|---|---|
CadDocument |
Central document container |
Handle |
Unique object identifier |
Vector2 / Vector3 |
2D and 3D coordinate types |
Color |
CAD color (indexed or true color) |
LineWeight |
Line thickness enumeration |
Transform |
Transformation matrices |
DXF-Tools-RS is built on a foundation of high-quality Rust crates:
| Crate | Purpose |
|---|---|
thiserror / anyhow |
Error handling |
nom |
Parser combinators for binary parsing |
byteorder |
Cross-platform byte order handling |
flate2 |
Compression/decompression |
nalgebra |
Linear algebra and transformations |
indexmap |
Ordered hash maps |
rayon |
Parallel iterators |
encoding_rs |
Character encoding support |
bitflags |
Type-safe bitflags |
Run the test suite:
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Run specific test
cargo test test_read_minimal_dxf
Run benchmarks:
cargo bench
DXF-Tools-RS is optimized for performance:
| Metric | Compared to C# |
|---|---|
| Parse Speed | 2-3x faster |
| Memory Usage | 30-50% less |
| Large Files | Parallel processing support |
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)# Clone the repository
git clone https://github.com/hakanaktt/dxf-tools-rs.git
cd dxf-tools-rs
# Build the project
cargo build
# Run tests
cargo test
# Check formatting
cargo fmt --check
# Run clippy
cargo clippy
This project is licensed under the MIT License - see the LICENSE file for details.
Made with โค๏ธ in Rust