Expand description
This crate provides the ability to read and write DXF and DXB CAD files.
§Usage
Put this in your Cargo.toml
:
[dependencies]
dxf = "0.5.0"
Or if you want serde support, enable the serialize
feature:
[dependencies]
dxf = { version = "0.5.0", features = ["serialize"] }
Note that
serde
support is intended to aid in debugging and since the serialized format is heavily dependent on the layout of the structures, it may change at any time.
And finally add:
extern crate dxf;
§Examples
Open a DXF file from disk:
use dxf::Drawing;
use dxf::entities::*;
let drawing = Drawing::load_file("path/to/file.dxf")?;
for e in drawing.entities() {
println!("found entity on layer {}", e.common.layer);
match e.specific {
EntityType::Circle(ref circle) => {
// do something with the circle
},
EntityType::Line(ref line) => {
// do something with the line
},
_ => (),
}
}
Saving a DXF file to disk:
use dxf::Drawing;
use dxf::entities::*;
let mut drawing = Drawing::new();
let added_entity_ref = drawing.add_entity(Entity::new(EntityType::Line(Line::default())));
// `added_entity_ref` is a reference to the newly added entity
drawing.save_file("path/to/file.dxf")?;
§Reference
Since I don’t want to fall afoul of Autodesk’s lawyers, this repo can’t include the actual DXF documentation. It can, however contain links to the official documents that I’ve been able to scrape together. For most scenarios the 2014 documentation should suffice, but all other versions are included here for backwards compatibility and reference between versions.
R11 (differences between R10 and R11)
R13 (self-extracting 16-bit executable)
2007 (Autodesk’s link erroneously points to the R2008 documentation)
These links were compiled from the archive.org May 9, 2013 snapshot of http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=12272454&linkID=10809853 (https://web.archive.org/web/20130509144333/http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=12272454&linkID=10809853)
Modules§
Macros§
- point
- Generates a point in the xyz plane based on the following pattern:
Structs§
- Block
- A block is a collection of entities.
- Class
- Represents an application-defined class whose instances are
Block
s,Entity
s, andObject
s. - Code
Pair - The basic primitive of a DXF file; a code indicating the type of the data contained, and the data itself.
- Color
- Represents an indexed color.
- Drawing
- Represents a DXF drawing.
- Extension
Group - Represents an application name and a collection of extension group data in the form of
CodePair
s. - GeoMesh
Point - Handle
- Header
- Contains common properties for the DXF file.
- Line
Weight - Represents a line weight.
- LwPolyline
Vertex - Represents a single vertex of a
LwPolyline
. - MLine
Style Element - Point
- Represents a simple point in Cartesian space.
- Section
Geometry Settings - Section
Type Settings - Table
Cell Style - Defines a style for a table’s cell.
- Transformation
Matrix - Applies a transformation to a point.
- Vector
- Represents a simple vector in Cartesian space.
- XData
- Represents an application name and a collection of extended data.
Enums§
- Code
Pair Value - Contains the data portion of a
CodePair
. - Data
Table Value - Drawing
Item - Drawing
Item Mut - DxfError
- Expected
Type - Represents the expected data type of a
CodePair
. - Extension
Group Item - Represents a single piece of extension data or a named group.
- XData
Item - Represents a piece of extended data.