draw.Drawing

Methods

Method Reference: 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 one character vector, its lines separated by newlines, 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 x = 1600 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.

Options

'Scale'Plot scale denominator: 50 means 1:50, which is a common scale for a general-arrangement plan and the default. A drawing at 1:1 wants 1.
'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, and 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.

Dimensions and hatches

A dimension, a centre mark and a leader are drawn as the lines and text draw.Drawing.entities breaks them into, as draw.Drawing.plot draws them: labels unidirectional, ticks the 45-degree architectural obliques, their size on paper nominal whatever the scale. A label is a node anchored at the start of its baseline, where draw.Drawing.entities places it from an estimate of its width. A hatch is drawn as its outline and its fill lines.

What the document needs

The output needs no 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.plot, draw.Drawing.write

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 (geom.Polyline ([0, 0; 40, 0; 40, 25; 0, 25], ...
                                'Closed', 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 31.75mm off 6.35mm on 6.35mm off 6.35mm] (18.5,12.5) -- (21.5,12.5);
    \draw[red, dash pattern=on 31.75mm off 6.35mm on 6.35mm off 6.35mm] (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 12.7mm off 6.35mm
scale 1:20  dash pattern=on 12.7mm off 6.35mm