Table of Contents

Class DwgWriter

Namespace
GeometryHelper.Dwg
Assembly
GeometryHelper.dll

Writes a drawing as a DWG file, the mirror of DwgReader: a DxfDatabase with every record it holds, or a DxfDocument as the drawing DxfWriter makes of its shapes.

public static class DwgWriter
Inheritance
DwgWriter
Inherited Members

Remarks

The drawing is written as its DXF, and each record of that DXF is encoded into the object of the DWG that says the same, with the handles of the drawing: the header variables, the classes, the nine tables, the blocks, the entities and the objects. Written are the tables and their records, the blocks, LINE, POINT, CIRCLE, ARC, ELLIPSE, SPLINE, RAY, XLINE, LWPOLYLINE, the 2D and 3D POLYLINE with their vertices, the polygon and polyface mesh, TEXT, MTEXT, ATTDEF, INSERT, alone or as an array, with its ATTRIBs, of one line or of several, SOLID, TRACE, 3DFACE, DIMENSION, VIEWPORT, HATCH, LEADER, MULTILEADER, TOLERANCE, MLINE, OLE2FRAME, IMAGE, WIPEOUT, ACAD_TABLE, and REGION, 3DSOLID and BODY with their ACIS data in the data store of the file, and of the objects DICTIONARY, XRECORD, LAYOUT, GROUP, MLINESTYLE, MLEADERSTYLE, TABLESTYLE, DBCOLOR, IMAGEDEF, RASTERVARIABLES, WIPEOUTVARIABLES, MATERIAL, VISUALSTYLE (in the form of each version), the detail and section view styles, the manager of the persistent names of subentities beside solids, the TABLECONTENT and TABLEGEOMETRY a table keeps for a round trip, the data of a dynamic block of a linear parameter and a stretch action (from AutoCAD 2007; a block whose graph holds another expression is written without it), and the small ones a new drawing holds, so that a new drawing is written whole. A table goes in the form of R2010: its cells, their overrides and borders, merged ranges, sizes and style from the groups DXF keeps of R2007, the cell styles of its rows, columns and whole from the TABLECONTENT it keeps for a round trip or else from its own overrides (93 to 96), and its table style's cell styles from the style's rows, then those of its own (101 on) from the CELLSTYLEMAP AutoCAD writes in DXF alone; that map, and the extension dictionary of the table style that holds it, are not written from R2010, as AutoCAD writes no such object there (a file before it holds them). A REGION, 3DSOLID or BODY is written with its ACIS data in the data store of the file: where the section ACDSDATA holds its SAB, as a DXF of R2013 and later gives it, and where it holds SAT text, as a DXF of R2004 to R2010 gives it, turned into the SAB AutoCAD 2021 writes for R2018 and named by a GUID, the one its extended data kept (else one made of its handle, so that the same drawing gives the same bytes); the 11 solids and 3 regions of a drawing of AutoCAD 2004, 2007 and 2010 written so open in AutoCAD 2021 with AUDIT finding 0 errors and the volumes and areas of the DXF. The ACIS 4.00 text of R2000 and a SAT with a record the grammars do not place are left out. The section THUMBNAILIMAGE of the DXF (a bitmap of Windows without its file header, or a PNG file) is written as the preview of the DWG, the picture of the file in Explorer and in the Open dialog. A SHAPE is written where its DXF gives its number (group 70, or a number as its name), of the first text style of a file of shapes; one given by its name alone is left out. The FIELD and FIELDLIST of fields, the SORTENTSTABLE of the draw order of a block and the DATALINK of a table linked to data are written as AutoCAD writes them, with their class listed where the DXF lists none, as a drawing made in code does. A record of another type, and a record that has no handle, which a DWG cannot name, is left out, every handle to it written as 0 and every dictionary entry naming it dropped, and one Warn line of GeometryHelperLog counts them by type.

The file is of AC1032 (AutoCAD 2018 and later), the form AutoCAD 2021 saves in, unless a version is given: AC1027 (AutoCAD 2013), AC1024 (2010) or AC1018 (2004) are written too, a drawing of a later version made first into the DXF of the version, as Save(string, string) would give it, and what the version cannot hold left out or replaced as it is there (the objects of R2007 and later that a file of R2004 keeps as AutoCAD keeps them: the multileaders with the version they were made by, the texts of their graphics in 8 bits, the fields in the form of before R2007). AC1015 (2000) is written too (the file of sections in sequence AutoCAD 2000 has), and AC1021 (2007), a container of its own, a file header and pages coded by Reed-Solomon. The same bytes come of the same drawing every time.

DxfDatabase database = DxfDatabase.Open("plan.dxf");
DwgWriter.Write(database, "plan.dwg");

Fields

DefaultVersion

The version written where none is given: AC1032, AutoCAD 2018 and later.

Methods

Write(DxfDatabase, Stream, string)

Writes a drawing database as a DWG file to a stream, where it stands.

Write(DxfDatabase, string, string)

Writes a drawing database as a DWG file at a path, replacing whatever is there.

Write(DxfDocument, Stream, string)

Writes the shapes of a document as a DWG file to a stream, where it stands.

Write(DxfDocument, string, string)

Writes the shapes of a document as a DWG file at a path, replacing whatever is there: the drawing DxfWriter makes of them, each on its layer.