[Tip] Converting OpenSCAD files easily to STEP with FreeCAD

Hey guys,

I’m guessing I am not the only one who simply won’t put any energy into trying to learn OpenSCAD. As a CAD user with more than 15 years of experience working with a few 2D and 3D CAD packages (among them the ubiquitous AutoCAD and parametric programs such as Autodesk Mechanical Desktop, Solid Edge and SolidWorks), I find it extremely hard to understand how anyone can design by programming lines of code, even less how can anyone analyze and modify OpenSCAD parts made by others.

A couple of guys have worked on an OpenSCAD module for FreeCAD and it was first included in the 0.13.1828/1830 stable version which came out last February. But until now I hadn’t used it much.

Well I tackled it in the past week and found out you can get surprisingly good results. The OpenSCAD importer reads .csg files or .scad source files and generates a CSG tree. I don’t like CSG work flow as I find it too primitive and a hassle to edit, but it beats the hell out of trying to figure out OpenSCAD syntax, or modeling the part from scratch using the STL as reference (which I had been doing until now).

For example here’s the AO-101 x-end-idle_ACME.scad file in OpenSCAD:

And here it is, converted into a B-rep solid in FreeCAD 0.14.2362 (latest development version in which the OpenSCAD has benefited from a few fixes):

And all I had to do was open the scad file, that’s it! :ugeek:

I also used the OpenSCAD import module to convert the Prusa3-vanilla parts to FreeCAD (I’m building the assembly just for fun :mrgreen: ) and only a few parts out of the lot failed to import. There are a few OpenSCAD functions that are not supported, like the hull function or the Minkowsky transform. Also, don’t even try to load those gears, FreeCAD will crash. So it is not fully functional yet, but pretty useful already.

I’ll explain how to configure FreeCAD for OpenSCAD import in the next post.

How to configure FreeCAD to import OpenSCAD parts

Of course this assumes you’ve already downloaded and installed FreeCAD! FreeCAD works well on Windows and Linux (can be installed easily on Ubuntu), but the Mac version is less up-to-date and suffers from Mac-specific bugs, and for this reason I cannot recommend it on this OS at this time. You’re of course welcome to try, but you may be disappointed.

  1. First you need to install OpenSCAD on your computer.
  2. Then you need to configure the OpenSCAD executable path. Switch to the OpenSCAD workbench from the menu View --> workbench.
  3. Go to Edit --> Preferences.
  4. Switch to the OpenSCAD preferences. Under General OpenSCAD Settings, specify the executable path by clicking on the button at the end of the field to browse your computer.
  5. Under OpenSCAD import, check both “Use ViewProvider in Tree View” and “Use Multmatrix Feature”.
  6. Set the “Maximum number of faces for polygons”. For any Openscad “polyhole” with a higher number of sides than this number, a true cylindrical surface will be created. I chose 7, because I wanted 6-sided polyholes to import as hexagons; but you can reduce this value to get circles.
  7. Click OK.

That’s it. Now open a .scad file. The import may take some time if the part is complex. If it works, the tree will look like this (it’s the one from my example in the first post):

How to export a file to STEP from FreeCAD

To export a part to STEP, you need to select the main object, which here is the “Group009” object in the tree. Then go to Edit --> Export, and type your filename and set the file type to STEP.

Note: with FreeCAD 0.13.1830 on GNOME-based Linux desktops, you need to type the “.stp” file extension manually or the file won’t save. This is an interface bug related to some Qt libraries.

Hope someone finds this useful! :slight_smile:

Very nice, I had no idea freecad could do that. I will try it out later.

Cool, thanks, I stickied this.

I have a lot of 2D CAD experience but 3D is a challenge to me. Tried TinkerCAD, seems nice if you want to print a birdhouse kit or whatever. Downloaded and tried to use a few other programs but I think FreeCAD is going to be my Go To for 3D. Thanks for posting.

This basically worked for me.

The OpenSCAD file wouldn’t open. Some error message flashed up briefly from the importer plugin.

Instead, I copy-pasted the scad code into a new document; then exported as .stp

I have been using OpenSCAD because I found FreeCAD too unstable. Both OpenSCAD and FreeCAD are incomplete, missing some critical functions, but FreeCAD, if anything goes wrong, I found I had to scrap the design and start over. I’ve never been able to fix a design once it breaks.
I have been using FreeCAD to convert OpenSCAD .scg files to STEP files, but recently ran into trouble with parts that use polyhedrons. It seeds that FreeCAD can’t deal with polyhedrons with sides using more than 3 points.
I will need to try your suggestion for having FreeCAD open native OpenSCAD files to see if that is a suitable work around.

BTW, I find the OpenSCAD language very easy to use. You do need to know your geometry though.

edit: Nope. Even reading .scad file directly, I got the same broken object when I tried to import an object with polyhedrons with faces of more than 3 sides.


I’m NormandC over at the FreeCAD forum. It is possible to fix a broken model. It seems that you never asked for pointers about it…

This is caused by what the developers have named the topological naming issue. Basically, due to the OCC kernel, topology elements (edges, faces) are given arbitrary IDs (Edge1, Edge2, Face1, Face2, etc.) which can change when the model is edited. If a sketch was mapped to Face2 and after a change upstream in the tree, the face ID gets changed, the Sketch won’t know the new ID and will be remapped to the new Face2.

The new PartDesign work flow in 0.17 will alleviate this issue because mapping sketches will no longer be a prerequisite to use subtractive features, and new datum planes will also help in that regard. There’s a GSoC student who’ll work this summer on topological naming, he likely won’t go very far (it’s a complex issue that can’t be fixed in 2-3 months) but it might be interesting what he comes up with.

The usual problem I have with FreeCAD is that after I get into a design, I find I need to adjust the dimensions in a sketch. This usually ends up with multiple things broken, and it is usually easier to start over than to try and fix the errors.
When doing a complex sketch, I got into a loop where it would start complaining that many of the constraints were redundant, and ask me to delete them. I would go through and delete the constraints it asked me to delete, and I’d end up with a severely under constrained sketch, or FreeCAD would crash.
I have tried both the stable path and the work in progress, and found both unusable. It looks like it will be very nice when they get it more stable, but for now, I’m sticking with OpenSCAD.