Freecad Make
3 minute read
Background
If you’re new to FreeCAD scripting, start with this guide on setting up FreeCAD on Linux.
Introduction
I’ve recently been working on a waveguide assembly for a time-domain reflectometer (TDR), designed in OpenSCAD and FreeCAD with simulation in openEMS. FreeCADs ability to export solid models (eg. STEP files) means I often do the design in vanilla OpenSCAD and then finalize it in FreeCAD. This particular design includes multiple interdependent parts that must stay consistent. They tend to change together as the design evolves, so managing them in a coordinated way is critical.
Project Organization
I maintain projects in a Git repository, with each conceptual version in its own subdirectory. A typical layout looks like this:
- PROJECT HOME
- WaveguideMechanics
- 0.1.0
- README.md
- …
- 0.1.1
- 0.2.0
- 0.1.0
- WaveguideMechanics
I keep historical versions around instead of overwriting them and relying solely on version control—mechanical designs rarely disappear the way software features do.
When using FreeCAD, I prefer to use the Assembly workbench and keep each component in its own source file. Assemblies reference those source files, and since they use relative or absolute paths, you can copy the whole directory and everything should still “just work.”
Enter the first issue I had: exporting the parts exposed a path problem.
Know What’s in Your Assembly
I redesigned part of the waveguide in an assembly, only to realize later that one of the parts was using an absolute path instead of a relative one. I wasn’t editing the source file I thought I was.
This is where the check-links
command comes in.
check-links
: Takes a list of files, searches for all linked objects inside them, and checks that those links are also in the file list. In a Makefile, you’d generate your list of source files and pass that to the tool.
This would’ve caught the absolute path issue immediately.
Export Functions
The CLI includes a couple of export functions. Read about those in the repo’s README.
Writing a Makefile & Organizing
One of the main goals of this tool is to allow a Makefile to generate a release artifact cleanly. Since Makefiles support generic rules, using a standard file organization helps a lot.
In each FreeCAD file I have:
- a
main
object → exported as a STEP file - a
main_Drawing
object → exported as a PDF (via TechDraw)
The naming convention looks like this:
- {FILENAME}.FCStd
- {FILENAME}: Object exported as STEP
- {FILENAME}_Drawing: TechDraw Drawing exported as PDF
This will not work for all projects and all designs but it does for most of mine. It results in a clear structure and a clean makefile. There’s an example here.
Hope it’s helpful!