Class CadDrawingJson
- Namespace
- OpenCAD2D
- Assembly
- OpenCAD2D.Core.dll
A drawing written as JSON for a program that learns from drawings or reads them: every entity walked down to its shapes
(see CadFlatten) with its handle, kind, layer, colour, linetype, box, words and geometry in world
millimetres, beside the tables of layers, styles, linetypes and blocks. The document is described by a JSON Schema,
Schema, and carries "schema": "opencad2d.drawing" and "version": 1.
public static class CadDrawingJson
- Inheritance
-
CadDrawingJson
- Inherited Members
Remarks
The same drawing gives the same text on every run and on both .NET Framework and .NET: entities in the order of
their handles (a hexadecimal handle read as a number; see Walk(CadDocument, string)), tables by name, numbers rounded
to six decimals (a nanometre) and written with a point. Lengths are millimetres, as CadUnitScale reads the
drawing's INSUNITS (and the plot paper units of a layout for its paper space); a drawing of no unit is left as it is
and the units object says "normalised": false. Angles are degrees, counter-clockwise seen from above, the
way DXF writes them. Every point is [x, y]: the drawing is two-dimensional.
An entity has box, [min x, min y, max x, max y] of its extents (null where it has none), whatever its
kind; the kinds the library can describe (LINE, CIRCLE, ARC, ELLIPSE, LWPOLYLINE, POLYLINE, SPLINE, POINT, TEXT,
ATTRIB, ATTDEF, MTEXT, DIMENSION, LEADER, MULTILEADER, HATCH, SOLID, TRACE, 3DFACE and an INSERT that could not be
walked) carry geometry as well, in the fields the schema lists; any other kind has the common fields and the box. An
entity that came out of a block has path (the names of the blocks), indexPath and matrix (block
coordinates to world millimetres, 4 by 4, rows first).
Fields
- Version
The version of the document this class writes; the schema's
versionis this number.
Properties
- Schema
Gets the JSON Schema (draft 2020-12) of the document Write(CadDocument, string) gives: the common fields of an entity, the fields of each kind, the tables and the report. It is the file
docs/schemas/opencad2d-drawing-v1.schema.jsonof the repository, built into this assembly.
Methods
- Write(CadDocument, string)
Writes the drawing as a JSON document:
schema,version,name,units,layouts,layers,textStyles,dimStyles,linetypes,blocks,reportandentities. A drawing of one LINE from (0, 0) to (100, 0) in millimetres gives an entity{"handle":"2A","kind":"LINE","layer":"0",...,"start":[0,0],"end":[100,0]}.
- Write(CadFlatDrawing, CadDocument)
Writes a drawing already walked, as Write(CadDocument, string) does; for a caller that also builds the graph of the same walk (CadDrawingGraph) and walks once.