FreeCAD programming

1 hr Workshop @ HSBXL for Software Freedom Day, 18.09.2021

by Yorik van Havre -

Abstract: FreeCAD is a well known 3D modelling platform, but its real power lies in how easily it can be programmed and extended with very simple Python scripts. Come discover and practice a few things with us!

Requirements: Your computer with FreeCAD installed - No programming experience needed

Level:: basic understanding of FreeCAD


1. Python starter anyone? A quick intro to Python

  • Python FTW: Why Python is awesome
  • The interpreter
  • Variables: a = "yorik"; b = 48.2; c = b
  • Functions: print("something")
  • Classes and modules: import FreeCAD
  • A peek at a complete Python script

2. Python in FreeCAD

  • The Python console
  • Macros
  • Code / Workbenches
  • Documentation
  • What you can do with it
    • Create/modify document contents
    • Modify the interface
    • Modify the 3D scene
    • Just about anything else

3. Recording a macro

  • Draw a Draft rectangle with filleted corners
  • Extrude it
  • Tweak the recorded macro

4. Create a shape from Python code

  • Create 4 vectors
  • Create a closed wire
  • Create a face + extrude
  • Create a cylinder
  • Duplicate it + make a compound
  • Create a subtraction

Useful links