Other 2D formats


Currently, OpenSCAD supports DXF only as a graphics format for 2D graphics. Other common formats are PS/EPS, SVG and AI.

PS/EPS

The pstoedit program can convert between various vector graphics formats. OpenSCAD needs the -polyaslines option passed to the dxf output plugin to understand the file. The -mm option sets one mm to be one unit in the dxf; include this if you use one unit in OpenSCAD as equal to one millimeter. The -dt options instructs pstoedit to render texts, which is usually what you want if you include text. (If the rendered text's resolution in terms of polygon count is too low, the easiest solution is to scale up the eps before converting; if you know a more elegant solution, please add it to the example.)

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

SVG

Inkscape can convert SVG to EPS. Then pstoedit can convert the EPS to DXF.

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

Makefile automation

The conversion can be automated using the make system; put the following lines in your Makefile:

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

The first line specifies which dxf files are to be generated when make is called in the current directory. The second paragraph specifies how to convert a file ending in .svg to a file ending in .eps, and the third from .eps to .dxf.

A more complete makefile could autogenerate dxf files from the any svg in the folder. In which case, put the following lines into your Makefile:

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

.PHONY: all clean clean-eps clean-dxf

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)

It's still possible to call make filename.dxf to build a particular file, but this code also allows for (re)building of all dxf files in a folder just by calling make or make all.

This code is also universal enough that it's possible to put the code in a single file and symlink every makefile in any directory that has svg files for dxf conversion by running:

ln -s /path/to/this/svg_to_dxf_makefile makefile

in each respective directory.

AI (Adobe Illustrator)

Although Adobe Illustrator CC/CC.2014 allows you to export illustrations as DXF (and select DXF format versions as early as 12), it uses DXF entities that are not supported by OpenSCAD, such as POLYLINE and SPLINE.

Since pstoedit does not natively support Adobe Illustrator files, one alternative is to use EXDXF, which is an Adobe Illustrator plug-in (30 free trial exports and then you have to pay $90 to register the plugin).

Before exporting, it is recommended that you ensure that your Artboard is the same dimensions as the component you are exporting. Although EXDXF provides you with numerous options when exporting to DXF the most important option for OpenSCAD compliance is to set Line Conversion to Line and Arc.

OpenSCAD doesn't always provide information about the issues it encountered with a DXF import. If this happens, select Design | Flush Caches and then Design | Reload and Compile.

Previous

DXF Extrusion

Next

Short and Commented Example Projects