Table of Contents

Class DxfWriter

Namespace
GeometryHelper.Dxf
Assembly
GeometryHelper.dll

Writes shapes as a DXF file of version R2000 (AC1015), which AutoCAD, Tekla Structures and every CAD viewer open.

public sealed class DxfWriter
Inheritance
DxfWriter
Inherited Members

Remarks

Every shape added is drawn on a layer, named as given and made on first use in the colour AutoCAD calls white, with the continuous line; none given means layer 0. CAD colours by layer, so there is no colour to pass. The drawing is in millimetres. Numbers are written exactly, as a text that reads back to the same double on .NET Framework and on .NET 10 alike (the digits may differ between the two). A shape with a number in it that is not finite (NaN or infinity) is refused with an ArgumentException before anything of it is written.

In the plane a shape is written as the entity AutoCAD has for it, not as chords: a polygon, a rectangle, a triangle and each ring of a face as a closed lightweight polyline, a chain or loop with arcs as one too with the bulge of each arc edge, a circle as a CIRCLE, an arc as an ARC, an ellipse as an ELLIPSE, a ray as a RAY, a line without ends as an XLINE and a spline as a SPLINE of its own knots and control points. A clockwise arc is written from its end to its start, since DXF arcs run counter-clockwise only. A face is its rings and not a filled area: SvgWriter fills.

In space a segment, a point, a ray, a line without ends, an ellipse and a spline are written as they are, a chain and a polygon as a 3D polyline, and anything with a surface as 3DFACEs: one per triangle of a face, a body or a ball, one per face of a mesh that has three or four corners and turns one way, and six for a box, written from its corners. Where a face, a side of a body or a face of a mesh is cut into triangles, the edges between its own triangles are marked invisible, so a wireframe shows its outline and not the cut; triangles given as they are keep every edge.

A curve in space (an arc, a circle, a chain or loop with arcs) is written as itself when no chord tolerance is given: an arc as an ARC and a circle as a CIRCLE, each in the coordinate system of its own plane (the arbitrary axis algorithm AutoCAD itself uses), a chain or loop that lies in one plane as one lightweight polyline with the plane's extrusion and elevation and the bulge of each arc edge, and a chain that bends out of one plane as a LINE or an ARC for each edge. Given a chord tolerance, which has no default, it is cut into chords no further from the curve than that: a circle of radius 100 at 0.1 is 71 chords, one of radius 50 000 at 0.001 is 15 708. A curve that would take more than 1 048 576 chords, counted over a whole chain or loop, is refused.

new DxfWriter().Add(plate, "plate").Add(slot, "cut").Add(bar, 0.1, "bars").Save("part.dxf");

Methods

Add(DxfShape)

Adds an entity DxfReader read: its shape, written by the overload of Add for it, on its layer, and in its colour, true colour, linetype and lineweight and with its thickness, each written only where the entity has one.

Add(DxfText, string)

Adds a text: a TEXT of one line, or an MTEXT where it is multiline, in the plane of its normal.

Add(GeoAabb3, string)

Adds a box as six 3DFACEs of four corners, written from its corners with no tolerance, so a box as flat as 100 by 100 by 0.002, or by nothing, is written and not refused.

Add(GeoArc2, string)

Adds an arc, written counter-clockwise from its start angle to its end angle; a clockwise one from its end to its start, so that it covers the same points.

Add(GeoArc3, double, string)

Adds an arc in space as an open 3D polyline of chords no further from the arc than a tolerance.

Add(GeoArc3, string)

Adds an arc in space as the ARC it is, in the coordinate system of its own plane, with no chords.

Add(GeoCircle2, string)

Adds a circle.

Add(GeoCircle3, double, string)

Adds a circle in space as a closed 3D polyline of chords no further from the circle than a tolerance.

Add(GeoCircle3, string)

Adds a circle in space as the CIRCLE it is, in the coordinate system of its own plane, with no chords.

Add(GeoEllipse2, string)

Adds an ellipse, whole, as an ELLIPSE with its centre, the end of its major axis, and the ratio of its minor radius to its major.

Add(GeoEllipse3, string)

Adds an ellipse in space, whole, as an ELLIPSE with its normal as the extrusion and its major axis in world coordinates.

Add(GeoFace2, string)

Adds a face as a closed lightweight polyline for its boundary and one for each hole, all on the layer given and none filled.

Add(GeoFace3, Tolerance, string)

Adds a face as a 3DFACE for each triangle of its surface, cut within a tolerance, the edges between its triangles invisible.

Add(GeoFace3, string)

Adds a face as a 3DFACE for each triangle of its surface, holes left open and the edges between its triangles invisible.

Add(GeoLine2, string)

Adds a segment.

Add(GeoLine3, string)

Adds a segment in space.

Add(GeoObb3, string)

Adds an oriented box as six 3DFACEs of four corners, written from its corners with no tolerance, so a box as flat as 100 by 100 by 0.002, or by nothing, is written and not refused.

Add(GeoPoint2, string)

Adds a point.

Add(GeoPoint3, string)

Adds a point in space.

Add(GeoPolygon2, string)

Adds a polygon as a closed lightweight polyline.

Add(GeoPolygon3, string)

Adds a polygon in space as a closed 3D polyline.

Add(GeoPolygonArc2, string)

Adds a loop with arcs as a closed lightweight polyline, each arc edge carrying its bulge.

Add(GeoPolygonArc3, double, string)

Adds a loop with arcs in space as a closed 3D polyline, its straight edges kept and each arc cut into chords no further from it than a tolerance.

Add(GeoPolygonArc3, string)

Adds a loop with arcs in space as one closed lightweight polyline in its plane, each arc edge carrying its bulge.

Add(GeoPolyline2, string)

Adds a chain as an open lightweight polyline.

Add(GeoPolyline3, string)

Adds a chain in space as an open 3D polyline.

Add(GeoPolylineArc2, string)

Adds a chain with arcs as an open lightweight polyline, each arc edge carrying its bulge.

Add(GeoPolylineArc3, Tolerance, string)

Adds a chain with arcs in space as it is: one lightweight polyline in its plane where it lies in one, and a LINE or an ARC for each edge where it does not.

Add(GeoPolylineArc3, double, string)

Adds a chain with arcs in space as an open 3D polyline, its straight edges kept and each arc cut into chords no further from it than a tolerance.

Add(GeoPolylineArc3, string)

Adds a chain with arcs in space as it is: one lightweight polyline in its plane where it lies in one, and a LINE or an ARC for each edge where it does not. The plane is judged at the global tolerance; Add(GeoPolylineArc3, Tolerance, string) states it.

Add(GeoRay2, string)

Adds a ray, which AutoCAD draws without end from its origin.

Add(GeoRay3, string)

Adds a ray in space, which AutoCAD draws without end from its origin.

Add(GeoRectangle2, string)

Adds a rectangle as a closed lightweight polyline of its four corners.

Add(GeoSolid3, Tolerance, string)

Adds a body as a 3DFACE for each triangle of its surface, cut within a tolerance, the edges between the triangles of one side invisible.

Add(GeoSolid3, string)

Adds a body as a 3DFACE for each triangle of the surface where its material ends, openings cut in and the edges between the triangles of one side invisible. A box 100 by 100 by 20 with a hole 20 by 20 through it is 64 triangles.

Add(GeoSphere3, double, string)

Adds a ball as a 3DFACE for each triangle of its surface, cut no further than a tolerance from the sphere, every edge visible.

Add(GeoSpline2, string)

Adds a spline as the SPLINE it is, at height nought: its degree, its knots, its weights where it is rational and its control points, as the spline holds them.

Add(GeoSpline3, string)

Adds a spline in space as the SPLINE it is: its degree, its knots, its weights where it is rational and its control points in world coordinates, as the spline holds them.

Add(GeoTriangle2, string)

Adds a triangle as a closed lightweight polyline of its three corners.

Add(GeoTriangle3, string)

Adds a triangle as a 3DFACE, every edge visible.

Add(GeoXLine2, string)

Adds a line without ends in the plane, which AutoCAD draws as an XLINE running both ways from its origin.

Add(GeoXLine3, string)

Adds a line without ends in space, which AutoCAD draws as an XLINE running both ways from its origin.

Add(GeoMesh3, string)

Adds a mesh of a flat shape: a face of three or four corners that turns right at none of them as one 3DFACE, so that the cells of a grid stay cells, and any other face as its triangles with the edges between them invisible.

Add(IEnumerable<GeoTriangle3>, string)

Adds triangles, each as a 3DFACE with every edge visible.

Save(string)

Writes the file to a path, replacing whatever is there.

ToString()

Gets the file as text.

WriteTo(TextWriter)

Writes the file to a writer.