Skip to content

Instantly share code, notes, and snippets.

Last active Feb 18, 2021
What would you like to do?
A converter script from OpenSCAD's .csg or .scad to .dxf using FreeCAD
# -*- coding: utf-8 -*-
import FreeCAD
import importCSG
import importDXF
def csg_to_dxf(src, dst):
doc =
importDXF.export([doc.TopologicalSortedObjects[0]], dst) # assumes it has single root object
csg_to_dxf(u"???.csg", u"???.dxf")
Copy link

okapies commented Aug 21, 2019

Background: OpenSCAD exports curved/circular shapes as a set of polygons instead of a single circle object due to the limitation(?) of the underlying CGAL. On the other hand, FreeCAD can recognize circles in CSG, which is an intermediate file format for OpenSCAD, and maps it to DXF circle entity directly. This script simply opens a CSG file in FreeCAD and export it as a DXF.

You need to configure "Maximum number of faces for polygons" parameter more than 0 in OpenSCAD preferences. See here for more details.

Note that importCSG also supports .scad file. It invokes OpenSCAD to convert .scad to .csg internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment