[Tip] Converting OpenSCAD files easily to STEP with FreeCAD

Get answers & advice for all of your 3D printing & Free Software needs here!
Post Reply
User avatar
Gemini64
Posts: 247
Joined: Tue Apr 16, 2013 6:37 pm
Location: Québec City, Canada

[Tip] Converting OpenSCAD files easily to STEP with FreeCAD

Post by Gemini64 » Thu Aug 01, 2013 12:44 am

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:
ao-101_x-end-idle_scad.png
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):
ao-101_x-end-idle_freecad.png
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.
Last edited by jebba on Fri Aug 02, 2013 10:49 am, edited 1 time in total.
Reason: made sticky

User avatar
Gemini64
Posts: 247
Joined: Tue Apr 16, 2013 6:37 pm
Location: Québec City, Canada

Re: [Tip] Converting OpenSCAD files easily to STEP with Free

Post by Gemini64 » Thu Aug 01, 2013 1:09 am

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.
    FreeCAD_OpenSCAD_Module_Prefs.png
  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):
FC_imported_scad_csg_tree.png
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! :)

1013
Posts: 339
Joined: Thu May 23, 2013 9:56 am

Re: [Tip] Converting OpenSCAD files easily to STEP with Free

Post by 1013 » Thu Aug 01, 2013 10:27 am

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

jebba
Site Admin
Posts: 689
Joined: Mon Mar 25, 2013 4:11 pm

Re: [Tip] Converting OpenSCAD files easily to STEP with Free

Post by jebba » Fri Aug 02, 2013 10:51 am

Cool, thanks, I stickied this.

wmgeorge64
Posts: 410
Joined: Wed May 27, 2015 7:28 pm

Re: [Tip] Converting OpenSCAD files easily to STEP with Free

Post by wmgeorge64 » Mon Jun 01, 2015 6:20 am

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.
ULS Laser . Retired master Electrician in Iowa USA Lots of Hobbies

ohhorob
Posts: 11
Joined: Tue Jan 05, 2016 4:41 pm

Re: [Tip] Converting OpenSCAD files easily to STEP with FreeCAD

Post by ohhorob » Sun Jan 24, 2016 3:31 pm

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

DAP
Posts: 61
Joined: Sun Jul 24, 2016 8:52 pm

Re: [Tip] Converting OpenSCAD files easily to STEP with FreeCAD

Post by DAP » Wed May 17, 2017 9:26 pm

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.

User avatar
Gemini64
Posts: 247
Joined: Tue Apr 16, 2013 6:37 pm
Location: Québec City, Canada

Re: [Tip] Converting OpenSCAD files easily to STEP with FreeCAD

Post by Gemini64 » Wed May 17, 2017 9:40 pm

DAP wrote: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.
Hi,

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.

DAP
Posts: 61
Joined: Sun Jul 24, 2016 8:52 pm

Re: [Tip] Converting OpenSCAD files easily to STEP with FreeCAD

Post by DAP » Thu May 18, 2017 2:50 pm

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.

Post Reply