OpenSCAD User Manual/Import 2D

Importing 2D Shapes

In older versions of the application files of each format were imported using a module specific to it. These older modules are deprecated in newer versions but are still documented in this page.

Currently the import() Object Module processes each type of file according to its file extension to instantiate imported objects. [Note: Requires version 2015]

There are some other, purpose specific, import methods in the app:

data in a JSON file
The import() function can read structured data into an object that can then be processed by a script.

Import() Object Module

This is an Object Module that imports geometry for use in the script. The extension on the filename informs the module as to which input processor to use.

The import() function is a separate component for bringing in structured data from a JSON file.

Parameters

file
A string containing a filename and extension of form "filename.ext". The location of the file is the same as the script's file. Refer to the File System Issues page for other file path options and platform specific information.
filename
deprecated - a filename of form "filename.ext". Use "file" parameter.
origin
vector of form [xcoord,ycoord]
scale
number. A scale factor to apply to the model
width
number
height
number
dpi
non-negative integer >= 0.001. The Dots Per Inch value is used importing a SVG or DXF file to correctly size the generated geometry.
center
Boolean. When true the object is centered in the X-Y plane at the origin. [Note: Requires version Development snapshot]
convexity
non-negative integer. The convexity parameter specifies the maximum number of front sides (or back sides) a ray intersecting the object might penetrate. This parameter is needed only for correctly displaying the object in OpenCSG preview mode and has no effect on the polyhedron rendering. Optional.
id
String. For SVG import only, the id of an element or group to import. Optional. [Note: Requires version Development snapshot]
layer
For DXF and SVG import only, specify a specific layer to import. Optional.
layername
[Deprecated: layername  will be removed in a future release. Use layer instead]
$fn
Number, default 0. The number of polygon segments to use when converting circles, arcs, and curves to polygons. [Note: Requires version Development snapshot]
$fa
Number, default 12. The minimum angle step to use when converting circles and arcs to polygons. [Note: Requires version Development snapshot]
$fs
Number, default 2. The minimum segment length to use when converting circles and arcs to polygons. [Note: Requires version Development snapshot]

2D Geometry Formats

DXF and SVG are the only drawing file formats that may be directly imported but we can offer some tips for using other 2D formats.

DXF
Drawing Exchange Format developed by AutoCAD
SVG
Scalable Vector Graphics format
previously handled by import_SVG() module
PS/EPS
Postscript, see other 2D formats page.
Illustrator
see other 2D formats page.

import() Function - JSON only

[Note: Requires version Development snapshot]

This function returns an object with the structured data from a valid JSON file. Although it has the same name as the import() Module it is functionally separate in that it may only be used in an assignment statement and may not be the target action of an Operator Module.

/* "people.json" contains:
{"people":[{"name":"Helen", "age":19}, {"name":"Chris", "age":32}]}
*/
pf=import( file = "people.json" );
echo(pf);
people = pf.people;
for( p=people) {
	echo(str( p.name, ": ", p.age));
    }

or even

 people = import( file = "people.json" ).people;
 for( p=people) {
	 echo(str( p.name, ": ", p.age));
     }

both of which give the data about Helen and Chris:

ECHO: { people = [{ age = 19; name = "Helen"; }, { age = 32; name = "Chris"; }]; }
ECHO: "Helen: 19"
ECHO: "Chris: 32"

import_dxf() Function

[Deprecated: import_dxf()  will be removed in a future release. Use Use import() instead. instead]

Read a DXF file to create a 2D shape.

linear_extrude(height = 5, center = true, convexity = 10)
		import_dxf(file = "example009.dxf", layer = "plate");

import_stl Function

[Deprecated: import_stl()  will be removed in a future release. Use Use import() instead. See above. instead]

Imports an STL file for use in the current OpenSCAD model

import_stl("body.stl", convexity = 5);