draw.Drawing.entities
draw.Drawing: E = entities (D)
draw.Drawing: E = entities (D, NAME, VALUE, …)
draw.Drawing: [E, LOST] = entities (…)
draw.Drawing: [E, LOST, BLOCKS] = entities (…)
Lower a drawing to the flat entity struct array that dxf.write
takes.
E = entities (D) converts the draw.Drawing
object D into the entity vocabulary of the DXF layer: LINE,
POLYLINE, ARC, CIRCLE and TEXT, each on the
layer it was drawn on. The result is written with
dxf.write (FILE, E).
This is the adapter between the two representations and the only place
that
knows both. dxf deals in a file format and knows nothing of
dimensions or hatches; draw models the drawing and knows nothing
of
group codes.
A 'dim' entity carries only geometry — two points, an offset and
a
direction. It becomes six entities: two extension lines, the dimension
line, two oblique ticks and the text. Nothing associative is emitted: a
true DIMENSION needs a *D block and a DIMSTYLE
record,
and plots identically.
Ticks are the 45-degree architectural obliques rather than arrowheads.
R12
draws a filled arrowhead only as a SOLID, and at drawing scale the
tick is the conventional mark in any case.
The text is placed horizontally whatever the dimension measures — unidirectional dimensioning, which ISO 129 permits and which keeps every label on the sheet readable from one side of it.
The label always clears the dimension line, on the far side from the geometry being measured. A dimension across the sheet carries its label above or below the line; one up the sheet carries it to the left or right, since a horizontal label beside a vertical dimension has to clear the line by its width. Which side is which follows the sign of the offset.
Without a label a dimension is annotated with the distance it measures, computed at the moment of conversion, so a dimension cannot fall out of step with the geometry it spans.
Dimension ornament — tick length, text height, the gap between a
measured
point and the start of its extension line — is in millimetres of
model space, so its size on the sheet depends on the plot scale.
Pass 'DimScale' to set it: a drawing to be plotted at
wants 'DimScale', 50, which makes a nominally mm text
mm in the model and therefore mm on paper. The
default is .
One thing in the model has no R12 equivalent, and it is not dropped
silently: a 'hatch' becomes its boundary as a closed polyline, so
the
region is outlined but not filled, R12 having no HATCH entity.
Text rotation used to be the second such case and no longer is.
dxf.write emits group code 50, so a rotated 'text' arrives
in
the CAD file at the angle it was drawn at.
[E, LOST] = entities (…) returns the losses as
a struct array with fields index, type and reason,
naming the entity of D that lost something. Ask for LOST and
nothing is printed; omit it and each distinct reason is warned about
once,
because a conversion that quietly discards part of a drawing is the one
failure mode a CAD file will not show you.
See also: dxf.write, draw.Drawing
Source Code: draw.Drawing
entities lowers a drawing to the primitives a file can hold. It is what every backend goes through, so what it returns is what the recipient gets. The second output names anything that could not survive.
D = draw.Drawing ().circle ([0, 0], 10).dim ([0, 0], [40, 0], -15);
D = D.hatch ([0, -40; 40, -40; 40, -55; 0, -55]);
[E, LOST] = entities (D);
printf ('%d drawing entities -> %d file entities\n', ...
numentities (D), numel (E));
3 drawing entities -> 18 file entities
unique ({E.type})
ans =
{
[1,1] = CIRCLE
[1,2] = DIMENSION
[1,3] = LINE
[1,4] = POLYLINE
}
A dimension arrives already exploded into the lines and text that draw it
sum (strcmp ({E.type}, 'LINE'))
ans = 15
A hatch reaches the file as its boundary and the fill lines, because R12 has no hatch entity. Ask for the boundary alone and the fill is dropped, which is then reported in LOST.
D = draw.Drawing ().hatch ([0, 0; 40, 0; 40, 25; 0, 25]); numel (entities (D))
ans = 20
[E, LOST] = entities (D, 'hatch', 'boundary'); numel (E)
ans = 1
LOST(1).reason
ans = fill dropped: R12 has no HATCH, boundary emitted