Main > Diary > Technology

« Earth | Main | Visiting Dad's Garden Plot »

July 19, 2013

Converting CAD files to STL using FreeCAD on the Command Line

I'm working on a client project where we are receiving hundreds of CAD submissions. We need to sort, filter, and rank these submissions in order to ease analysis. Ultimately, these submissions will be 3D printed. I needed an automated way to convert the files from STEP or IGS CAD format to STL on the command line.

I discovered that the venerable FreeCAD has a Python-based command line interpreter. After a few bumps, I was able to drive it to create a simple tool to convert my files.

First, I had to add the dynamic library loading path of FreeCAD to my OSX command line environment:


Next, I wrote this little script. I figured out the syntax by first recording some macros in FreeCAD.

import FreeCAD
import Part
import Mesh

import sys
in_fn, out_fn = sys.argv[2], sys.argv[3]
o = [ FreeCAD.getDocument("Unnamed").findObjects()[0] ]
Mesh.export(o, out_fn)

It's used like this: input.step output.stl

I am fairly certain that the input file could be any input format understood by FreeCAD. Enjoy!

Posted by jordanh at July 19, 2013 12:08 PM |

Trackback Pings

TrackBack URL for this entry:


Post a comment

Remember Me?