Last active
February 18, 2021 20:22
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.