OpenSCAD User Manual/Other 2D formats


Currently, OpenSCAD imports only DXF and SVG for 2D graphics. Other common formats are Postscript (PS), Encapsulated PS (EPS), and Adobe Illustrator (AI).

Postscript to DXF

The pstoedit program is able to convert a PS vector graphics formats. Here is an example for using this command line utility:

pstoedit -dt -f "dxf: -polyaslines -mm" infile.eps outfile.dxf

OpenSCAD cannot work with PS polygons so the -polyaslines option converts them to simple lines.

The -mm option defines one millimeter as the unit of measurement in the output file. This is not required by OpenSCAD and may have the effect of scaling the converted model.

The -dt option causes text elements to be rendered. Note that text in a small size, or in a "delicate" font, may need to be scaled up in size in the PS/EPS file in order to render curves with enough line segments to appear to be smooth.

Scalable Vector Graphics

A workable conversion process is to use Inkscape to convert SVG to EPS, then use pstoedit to convert EPS to DXF.

inkscape -E intermediate.eps infile.svg
pstoedit -dt -f dxf:-polyaslines\ -mm intermediate.eps outfile.dxf

Deprecated after Version 2015 in favor of the import module as:

import( "modelfile.svg" )

Makefile automation

Format conversion may be automated using the make tool. Place files to be converted in a folder and use a terminal program to visit that folder.

Create a makefile script:

# convert these specific files
all: my_first_file.dxf my_second_file.dxf another_file.dxf
 
%.eps: %.svg
 	inkscape -E $@ $<
 
%.dxf: %.eps
 	pstoedit -dt -f dxf:-polyaslines\ -mm $< $@

Run make on the terminal's command line so that it processes the default rule.

The second rule is for converting an .svg to an .eps, and the third rule handles from .eps to .dxf.

This alternate makefile will find and convert all SVG files in a folder to DXF:

SVG := $(wildcard *.svg)
DXF := $(SVG:%.svg=%.dxf)
EPS := $(SVG:%.svg=%.eps)

.PHONY: all clean clean-eps clean-dxf

# default rule acts on all files with extensions that can be converted
# according to the 3 name search definitions above
all: $(DXF)

%.eps: %.svg
	inkscape -E $*.eps $*.svg
 
%.dxf: %.eps
	pstoedit -dt -f "dxf: -polyaslines -mm" $*.eps $*.dxf

clean: clean-dxf clean-eps

clean-dxf: 
	rm -f $(DXF)

clean-eps:
	rm -f $(EPS)

One may run make filename.dxf to convert a particular file, but the default is that running make, or make all will convert all .svg and .eps files to DXF.

AI (Adobe Illustrator)

Adobe Illustrator CC/CC.2014 can export versions of the DXF format as early as R12), but it uses DXF entities that are not supported by OpenSCAD, such as POLYLINE and SPLINE.

There is an Illustrator plug-in EXDXF that can export a DXF that does not use the disallowed entities, but it does cost $90 to purchase after a 30 free trial period.

Best practice is to set the file's Artboard to the dimensions of the component you are exporting. Note that the EXDXF option Line Conversion needs to be set to Line and Arc for OpenSCAD compliance.

To be sure of seeing all the feedback messages from an importation use the menu itemDesign > Flush Caches followed by Design > Reload and Compile.

No Next Yet