FreeCAD and Python – 7 learning tips

I started 3D modeling as a hobby, to create simple parts fix everyday household items. It took roughly10 hours of focused learning form me to feel comfortable enough with FreeCAD to create simple sketch models. It took me a couple more days to figure out how to script in Python well enough to automate tedious and repetitive actions in FreeCAD.
Full disclosure – I had prior coding experience from web development, but was new to both tools and 3D modeling in general, before diving in.

FreeCAD is a great gateway to learning Python. Taken from the FreeCAD Scripting Basics page:

FreeCAD is built from scratch to be totally controlled by Python scripts. Almost all parts of FreeCAD, such as the interface, the scene contents, and even the representation of this content in the 3D views, are accessible from the built-in Python interpreter or from your own scripts. 

wiki.freecadweb.org

The following tips benefited me the most in starting my FreeCAD and Python learning journey.

Tips

1. Watch Tutorials

The first and tip is to watch tutorials.
3D modeling is a very visual process, so video tutorials are the most natural way to observe features in action. A good tutorial can explain in minutes what might take hours of reading documentation to grasp.

Andrew CAD

Joko Engineeringhelp

FreeCAD Academy


If you’re still on the fence for about committing to learning FreeCAD, I suggest watching ..Is it Worth Learning FreeCAD? Can It Be Used Commercially? |JOKO ENGINEERING|
This video helped put away any doubt I had as to which CAD software to start learning.

Though I didn’t use Skillshare, it seems to be another great resource for FreeCAD instruction, for anyone with a subscription.

2. Read the Documentation

FreeCAD documentation is hosted on a wiki and is honestly more flushed out when compared with documentation for many other paid software that I’ve used in the past.
A good place to start is the UserHub – https://wiki.freecadweb.org/User_hub


Check out the Table of Contents to see what topics. Just knowing what features exist can be useful in giving you that first clue as to where to look when you get get stuck. It also helps to get idea of the over-aching philosophy behind the software before delving into how to use specific features.

I don’t always understand what I’m reading in the moment, but eventually almost everything turns out to be useful to solve some problem and in later moment and context.

3. Use the Python Console and Record MACROS

One tip for anyone looking write their own scripts.Use the Python Console and Record MACROS
As you click about the Workbench and make edits, FreeCAD will output the python command which represents each action performed using the GUI.


And surprise – tip explicitly suggested in FreeCAD documentation.
FreeCAD will even spit out a list of commands that when replayed will reproduce the state current state of the document and models contained in it, which is very useful tool for quickly figuring out the FreeCAD was of doing things in Python.

3.1 Send to Python Console

Use the “Send to Python Console” after clicking on any object and get neat boiler code like below.

Select from "Send to Python Console" from Edit menu bar tab.
Select from “Send to Python Console” from Edit menu bar tab.
>>> doc = App.getDocument("cable_organizer_connectable")
>>> obj = doc.getObject("LinearPattern002")
>>> shp = obj.Shape

4. Take Notes

Unless you have an incredible memory, or strong experience with 3D modeling and programming in Python, it’s worth slowing down to take notes on paper. The notes can be a basic as just a word or quick scribble pointing to some central concept. Even if FreeCAD and Python live in the digital world, physical notes really help offload the burden of memory( and reduce screen time ).

5. Backup your work often

To hedge against irrecoverable crashed projects, I suggest making regular backups. As a beginner, it’s pretty easy to make mistake or run into errors and not understand why they happened or even how to undo or recover to previous working state. If you are comfortable using Git for versioning, that also works nicely for having historical record to look back on.

6. Ask for help

FreeCAD is an incredibly rich and complex tool, expect to get perma-stuck as a beginner.
There are different channels for finding help to get unstuck, check out FreeCAD’s official IRC chat or the very active forum.
I was impressed with how quickly someone responded to the first question I ever asked on the forum, regarding how to change the size of the tooltip text.
Members of the forum had offered two unique solutions!!
https://forum.freecadweb.org/viewtopic.php?t=72473
If you get stuck, don’t be shy to ask for assistance.

7. Make something!

I believe that saying that goes something like – “the best way to learn is to do”. It helps to have something specific and simple in mind that want to make.
For me that something, at the moment, is this cable organizer that I would like to iterate on and explore a number of ideas that will could take some involved Python scripting to realize.
By thinking about that thing in the back of your mind, your subconscious will be primed to use newly acquired information towards making that thing. My own learning path has been guided mostly by specific challenges faced while editing simple models.

Also, be patient with yourself and the process. While FreeCAD is powerful and easy to use, I find that it’s also pretty easy to get stuck in the beginning. I have had to revisit documentation, rewatch tutorials, and scour forums until some ideas finally clicked an allowed me to get past roadblocks. It took several hours of getting stuck and starting over before I reached a point of being able to work with some momentum.

Conclusion

By applying these tips, I was able to write my first FreeCAD Macro in Python.
It’s a script that selects all edges of particular length, allowing me to batch edit them to, for example, round those edges.
I will add the macro to the following Github once it’s in a state that’s ready to share: https://github.com/MannyAdumbire/cable-organizer-freeCAD .


Good luck on your learning journey!

Leave a comment

Your email address will not be published. Required fields are marked *