Exporting drawings

Exporting drawings

Once you have a cross-section, you don't have to stop at a view on screen — you can export it as a print-ready 2D drawing. Twinfinity gives you two routes: bare section lines as a plain SVG, or the same section laid into a titled drawing sheet with a frame, scale bar and logo.

Exporting a section to SVG

printToSvg takes the geometry your section already computed and returns an SVG string — the cut, visible and hidden lines, outlines and silhouettes turned straight into a file you can open or print. Hidden linework — occluded silhouettes included — comes out dashed and lighter, following drafting convention.

It works in model units (metres), so line widths and scale are set in real units rather than pixels. A model is tiny in metres, so you normally project into paper-millimetres at a drawing scale: at 1:100, 1 m on the model becomes 1000 / 100 = 10 mm on paper. You feed that factor through planeBasis (a top-down basis that drops Y and keeps X / -Z), and then the stroke widths below read as real pen weights in millimetres.

import { printToSvg } from '@twinfinity/printing'; // `result` is the computed SlabSection geometry. Project metres -> mm at 1:100. const mmPerMetre = 1000 / 100; const svg = printToSvg(result, { includeXmlDeclaration: true, backgroundColor: '#ffffff', planeBasis: { origin: { x: 0, y: 0, z: 0 }, right: { x: mmPerMetre, y: 0, z: 0 }, up: { x: 0, y: 0, z: -mmPerMetre } }, styles: { cutLines: { stroke: '#000000', strokeWidth: 0.5 }, visibleLines: { stroke: '#404040', strokeWidth: 0.35 }, hiddenLines: { stroke: '#999999', strokeWidth: 0.25, strokeDasharray: '1.5 1' } } }); // Hand the string to a Blob and trigger a download. const blob = new Blob([svg], { type: 'image/svg+xml' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = 'plan-02.svg'; link.click(); URL.revokeObjectURL(url);

Try it in the playground: Export plan to SVG

Full drawing sheets (A3 layout)

When you want more than bare lines, renderDrawing lays a section into a layout template and returns a complete sheet SVG. The template is just JSON — it describes the page, a viewport (where the section draws, auto-scaled to fit), a frame, a title, a scale bar and a logo, all in millimetres on the page. You hand renderDrawing your template and the computed section, and it does the section → SVG conversion, item extraction and colouring for you, returning a ready-to-print sheet (plus any layout warnings).

import { renderDrawing } from '@twinfinity/printing'; const { svg, warnings } = await renderDrawing({ template, // your A3 layout JSON sections: section, // the computed plane section options: { allowRemoteAssets: true } // lets a remote logo load });

Try it in the playground: Drawing sheet (A3 layout)

See also

The section geometry you're exporting comes from a cross-section — see Cross-sections for how to compute one.