ixmilia / dxf-rs

MIT License
95 stars 29 forks source link

Issue creating polyline in 0.5.0 #41

Open btdevine opened 1 year ago

btdevine commented 1 year ago

Hi,

First off, many thanks for creating this, I just started using it and it's awesome!

I'm running into an issue with creating polylines in version 0.5.0. When I upload the generated DXF to viewer.autodesk.com, I get the following error. Likewise, opening in Civil3D does not work.

Processing failed Design is empty. Please check the design. AutoCAD-InvalidFile Sorry, the drawing file is invalid and cannot be viewed. - Please try to recover the file in AutoCAD, and upload it again to view. TranslationWorker-InternalFailure Unrecoverable exit code from extractor: -1073741831

I can, however, properly create a polyline in version 0.4.0; the exported file loads correctly into viewer.autodesk.com, and I can open it in Civil3D.

Looking at the diffs between the two output files (attached, converted to .txt files), 0.4.0-works.txt 0.5.0-broken.txt it appears as though the primary difference, aside from what appear to be some numbering convention changes, is that 0.5.0 has added tables to the TABLES section, whereas tables are absent in the file created by 0.4.0.

The following works in v0.4.0

let mut drawing = Drawing::default();
let mut polyline = Polyline::default();

polyline.vertices = [
    Vertex::new(Point::new(0.0, 0.0, 0.0)),
    Vertex::new(Point::new(10.0, 0.0, 0.0)),
    Vertex::new(Point::new(10.0, 10.0, 10.0)),
    Vertex::new(Point::new(0.0, 10.0, 10.0)),
    Vertex::new(Point::new(0.0, 0.0, 0.0)),
]
.to_vec();

polyline.set_is_3d_polyline(true);
polyline.set_is_closed(true);

let polyline_entity = Entity::new(EntityType::Polyline(polyline));
drawing.entities.push(polyline_entity);

The following does not work in v0.5.0

let mut drawing = Drawing::new();
let mut polyline = Polyline::default();

polyline.add_vertex(&mut drawing, Vertex::new(Point::new(0.0, 0.0, 0.0)));
polyline.add_vertex(&mut drawing, Vertex::new(Point::new(10.0, 0.0, 0.0)));
polyline.add_vertex(&mut drawing, Vertex::new(Point::new(10.0, 10.0, 10.0)));
polyline.add_vertex(&mut drawing, Vertex::new(Point::new(0.0, 10.0, 10.0)));
polyline.add_vertex(&mut drawing, Vertex::new(Point::new(0.0, 0.0, 0.0)));

polyline.set_is_3d_polyline(true);
polyline.set_is_closed(true);

let polyline_entity = Entity::new(EntityType::Polyline(polyline));
drawing.add_entity(polyline_entity);