OpenSCAD User Manual/SVG Import
Import() of an SVG Design
[Note: Requires version 2019.05] Scalable Vector Graphics (SVG) supports flexibly rendering images with support for interaction and animation.
For the purposes of 2D design all animation features and most visual properties are discarded during import. In particular some commonly used features not imported are:
- Text
- Clipping and Masking
- Objects using templates
What is left is the geometric information that defines the shapes of interest. One thing that is not lost is the resolution assigned in the design to guide the rendering of it as polygonal line segments. The $fn, $fa, and $fs parameters (described below) can only increase resolution.
Shapes - Closed and Open
In OpenSCAD lines and open polygons are not allowed so the import process promotes such objects to be 3D polyhedronal "tubes" that use their original stroke-width as their thickness.
Closed shapes are converted to equivalent geometry discarding information about fill and stroke-width. SVG closed polylines are an exception , which are treated as open polygons and defined by their stroke-width.
An SVG design is imported as a filled, 2D shape in the X+ Y+ quadrant, at Z=0, bounded by a closed polygonal line. It is rendered, by default, in preview as a one unit high plane centered vertically at Z=0.
import("file.svg");
import(file = "file.svg", center = false, dpi = 96);
import("file.svg", $fn = 100); // [Note: Requires version dev snapshot]
Parameters
- filename
- String Required. This is, in fact, the path name of the file to import.
- center
- Boolean default=false. When true the shape's bounding box will be centered horizontally on the X-Y origin.
- dpi (Dots Per Inch)
- optional non-negative number. Used to calculate the size of the view-box Limitation: If the file gives the design's width or height this parameter is ignored
.
- $fn
- non-negative number. The number of polygon segments to use when converting to polygons. [Note: Requires version Development snapshot]
- $fa
- non-negative number. The minimum angle step to use when converting to polygons. [Note: Requires version Development snapshot]
- $fs
- non-negative number. The minimum segment length to use when converting to polygons.
- id
- String. The id of an element or group to import.
- layer
- String. Name of the layer to import following the Inkscape convention.
Note: the $fn, $fa, and $fs parameters require the dev snapshot to be available
Path Name Syntax
The filename parameter is required to be a path name giving the input file's location in the file system, as well as its name and extension. While this is clearly file system dependent the path may be absolute or relative and use the commonly understood syntax, for instance "../beside/file.svg" The case of the characters in the name must match the file system's expectations and the file extension must match the file's content for the import to succeed
ON Windows : folder names in the path should be separated by Unix style slash ('/') characters rather than the native Windows backslash ('\'), thus "C:/base/folder/file.svg"
DPI Affects Scaling
The DPI setting is only used when the file does not set the width and/or height for the design. Otherwise the DPI value is used to set the view-box to the the desired scaling.
For example, when the SVG unit is to be 1 mm we convert 1 inch to 25.4 mm by setting dpi=25.4.
Note: When width or height is set in the file using absolute units (px/pt/pc/in/mm/cm) the DPI value is ignored .
ViewBox handling
The ViewBox attribute of the SVG file defines the initial coordinate system the design. import() supports the transformations, including the preserveAspectRatio attribute.
The article Understanding SVG Coordinate Systems and Transformations describes how the view-box attributes affect the display.
Category:Book:OpenSCAD User Manual#Importing%20Geometry/SVG%20Import%20