### Paper Space Layouts and Viewports in DXF Source: https://github.com/hakanaktt/acadrust/blob/main/README.md Shows how to create DXF files with multiple layouts, including model space geometry and paper space viewports. Uses a specific DXF version and builder pattern for viewports. ```rust use acadrust::{CadDocument, DxfVersion, DxfWriter}; use acadrust::entities::{EntityType, Viewport}; use acadrust::types::Vector3; fn main() -> acadrust::Result<()> { let mut doc = CadDocument::with_version(DxfVersion::AC1027); // Add geometry to model space let line = acadrust::entities::Line::from_coords(0.0, 0.0, 0.0, 100.0, 100.0, 0.0); doc.add_entity(EntityType::Line(line))?; // Overall viewport (ID=1) for default Layout1 let mut overall_vp = Viewport::new(); overall_vp.id = 1; overall_vp.center = Vector3::new(148.5, 105.0, 0.0); doc.add_paper_space_entity(EntityType::Viewport(overall_vp))?; // Detail viewport using builder pattern let vp1 = Viewport::new() .with_center(Vector3::new(148.5, 105.0, 0.0)) .with_view_target(Vector3::new(50.0, 50.0, 0.0)) .with_scale(1.0) .with_locked(); doc.add_paper_space_entity(EntityType::Viewport(vp1))?; // Create a second layout with its own viewport doc.add_layout("Layout2")?; let mut vp2 = Viewport::with_size(Vector3::new(200.0, 150.0, 0.0), 400.0, 300.0); vp2.id = 1; doc.add_entity_to_layout(EntityType::Viewport(vp2), "Layout2")?; DxfWriter::new(&doc).write_to_file("layouts.dxf")?; Ok(()) } ``` -------------------------------- ### Read and Write DXF Files with Acadrust Source: https://github.com/hakanaktt/acadrust/blob/main/README.md Demonstrates how to read a DXF file into a CadDocument and then write it back out to a new file. Ensure the input file exists and the output path is writable. ```rust use acadrust::{CadDocument, DxfReader, DxfWriter}; fn main() -> acadrust::Result<()> { // Read let doc = DxfReader::from_file("input.dxf")?.read()?; println!("{} entities", doc.entities().count()); // Write let writer = DxfWriter::new(&doc); writer.write_to_file("output.dxf")?; Ok(()) } ``` -------------------------------- ### Read and Write DWG Files Source: https://github.com/hakanaktt/acadrust/blob/main/README.md Demonstrates reading entities from a DWG file and writing a new DWG file with a red line. Requires `drawing.dwg` to exist. ```rust use acadrust::{CadDocument, DwgWriter}; use acadrust::io::dwg::DwgReader; use acadrust::entities::*; use acadrust::types::{Color, Vector3}; fn main() -> acadrust::Result<()> { // Read DWG let mut reader = DwgReader::from_file("drawing.dwg")?; let doc = reader.read()?; // Iterate entities for entity in doc.entities() { println!("{:?}", entity); } // Create & Write DWG let mut doc = 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; doc.add_entity(EntityType::Line(line))?; DwgWriter::write_to_file("output.dwg", &doc)?; Ok(()) } ``` -------------------------------- ### Serialize and Deserialize CAD Document to JSON Source: https://github.com/hakanaktt/acadrust/blob/main/README.md Demonstrates using Serde to serialize a CAD document to a pretty-printed JSON string and then deserialize it back into a `CadDocument` object. Requires `drawing.dxf` to exist. ```rust use acadrust::{CadDocument, DxfReader}; fn main() -> acadrust::Result<()> { let doc = DxfReader::from_file("drawing.dxf")?.read()?; let json = serde_json::to_string_pretty(&doc).unwrap(); let doc2: CadDocument = serde_json::from_str(&json).unwrap(); println!("Entities: {}", doc2.entities().count()); Ok(()) } ``` -------------------------------- ### Add Acadrust to Project Dependencies Source: https://github.com/hakanaktt/acadrust/blob/main/README.md Add this to your Cargo.toml file to include the acadrust library in your project. ```toml [dependencies] acadrust = "0.4.0" ``` -------------------------------- ### Accessing Block Entities via Document Handle Lookup Source: https://github.com/hakanaktt/acadrust/blob/main/README.md After version 0.3.0, BlockRecord stores entity handles instead of owning entities directly. Access entities through the CadDocument's handle-based lookup. ```rust for &handle in &block_record.entity_handles { if let Some(entity) = doc.get_entity(handle) { // use entity } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.