draw.Drawing.tikz
draw.Drawing: S = tikz (D)
draw.Drawing: S = tikz (D, NAME, VALUE, …)
Render a drawing as a TikZ picture for inclusion in the LaTeX report.
S = tikz (D) returns the TikZ code for the
draw.Drawing object D as a character array, one line per row
of
the drawing, ready to be written to a .tex file and pulled into a
document with \input.
The picture is emitted at a stated plot scale, so it arrives on the page
at
the size a drawing is meant to be read at rather than at whatever size
fits.
Model coordinates are written unchanged, in millimetres, and the scale is
carried by the x and y unit vectors of the
tikzpicture: a wall at appears in the output as
1600 whatever the scale, which is what makes the generated source
readable against the drawing it came from.
Radii, text sizes and dimension ornament cannot follow that convention, since they must come out at a fixed size on paper regardless of scale. Those are emitted in absolute millimetres and points, already divided by the scale.
'Scale' | Plot scale denominator: means , which is a common scale for a general-arrangement plan and the default. A drawing at wants . |
'File' | Also write the result to this file. The code is returned either way. |
'Styles' | Emit a \tikzset block defining one
empty
style per layer, so that the document can restyle a layer by redefining
it.
True by default; set it false when the styles are already defined and
redefining them would undo that. |
'LTScale' | Multiplies line-type dash lengths. Patterns
are model lengths times this factor, exactly as in
draw.Drawing.plot and as
CAD’s own LTSCALE works. Defaults to the drawing scale, which
cancels the reduction so dashes reach the page at their nominal size —
a
centre line reads as a centre line whether the view is at 1:1 or 1:50 —
while leaving the factor visible and adjustable. |
Source Code: draw.Drawing
Dimensions are rendered here rather than reused from
draw.Drawing.entities, which is the point of storing them
semantically. A
TikZ node anchors itself, so the label is positioned by naming the side
it
should sit on and letting TikZ measure the text — where the DXF path
has
to estimate the width of a string from its character count. The same
drawing therefore gets properly centred labels on the report figure and
approximately centred ones in the CAD file, from one model and without a
flag anywhere.
Labels are unidirectional, matching draw.Drawing.entities, and
ticks are the
45-degree architectural obliques.
A hatch is emitted as \path[pattern=…], which requires
\usetikzlibrary{patterns}. Nothing else in the output needs a
library beyond TikZ itself.
Text is written through as UTF-8 and LaTeX’s special characters are
escaped. Greek text needs a Unicode-aware engine — xelatex or
lualatex — or babel configured for Greek; that is a
property
of the document, not of this output.
See also: draw.Drawing, draw.Drawing.entities
Source Code: draw.Drawing
The LaTeX backend, for a drawing that belongs in a report rather than in a CAD program. Each layer becomes a TikZ scope with a style of its own, so the document can restyle a layer by redefining it.
D = draw.Drawing ('bracket');
D.Layer = 'BODY';
D = D.polyline ([0, 0; 40, 0; 40, 25; 0, 25], true).circle ([20, 12.5], 6);
D.Layer = 'AXES';
D.Linetype = 'CENTER';
D.Colour = 'red';
D = D.centremark ();
S = tikz (D, 'scale', 2);
disp (S);
% Generated by the drafting package: draw.Drawing.tikz
% Drawing: bracket
% Plot scale 1:2. Coordinates are model millimetres.
\tikzset{
drAXES/.style={}, % layer 'AXES'
drBODY/.style={}, % layer 'BODY'
}
\begin{tikzpicture}[x=0.5mm, y=0.5mm, line width=0.18mm]
% layer: AXES
\begin{scope}[drAXES]
\draw[red, dash pattern=on 1.25mm off 0.25mm on 0.25mm off 0.25mm] (18.5,12.5) -- (21.5,12.5);
\draw[red, dash pattern=on 1.25mm off 0.25mm on 0.25mm off 0.25mm] (20,11) -- (20,14);
\end{scope}
% layer: BODY
\begin{scope}[drBODY]
\draw (0,0) -- (40,0) -- (40,25) -- (0,25) -- cycle;
\draw (20,12.5) circle[radius=3mm];
\end{scope}
\end{tikzpicture}
Dash lengths are model dimensions times a line-type scale, as CAD's LTSCALE works. Defaulting that factor to the drawing scale brings the dashes to the page at nominal size whatever the view is drawn at.
D = draw.Drawing ();
D.Linetype = 'DASHED';
D = D.line ([0, 0], [50, 0]);
for sc = [1, 20]
S = tikz (D, 'scale', sc);
m = regexp (S, 'dash pattern=[^]]*', 'match');
printf ('scale 1:%-3d %s\n', sc, m{1});
endfor
scale 1:1 dash pattern=on 0.5mm off 0.25mm scale 1:20 dash pattern=on 0.5mm off 0.25mm