Skip to content

Instantly share code, notes, and snippets.

@okapies
Last active February 18, 2021 20:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okapies/55a36da8385a4268f382837167cd593b to your computer and use it in GitHub Desktop.
Save okapies/55a36da8385a4268f382837167cd593b to your computer and use it in GitHub Desktop.
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 = importCSG.open(src)
importDXF.export([doc.TopologicalSortedObjects[0]], dst) # assumes it has single root object
FreeCAD.closeDocument(doc.Name)
csg_to_dxf(u"???.csg", u"???.dxf")
@okapies
Copy link
Author

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