Almost everything in FreeCAD can be controlled with Python. You can automate repetitive work, generate parts from data, or build your own tools.

Open the Python console

Use View → Panels → Python console. Also open the Report view from the same menu: it shows errors and messages. When you click buttons in FreeCAD, the matching Python commands often appear in the console, which is a great way to learn.

Your first script

import FreeCAD as App
import Part

doc = App.newDocument("Example")
box = doc.addObject("Part::Box", "MyBox")
box.Length = 40
box.Width = 20
box.Height = 10
doc.recompute()

This creates a parametric box object. Because it is a real FreeCAD object, you can still change its properties later, by hand or with code (box.Height = 25 followed by doc.recompute()).

Working with shapes

import Part

cyl = Part.makeCylinder(5, 30)       # radius, height
hole = Part.makeCylinder(2, 30)
tube = cyl.cut(hole)                 # Boolean cut
Part.show(tube)

Part.show() adds a shape to the document as a simple, non-parametric object. This is handy for quick tests and generated geometry.

Record a macro

  1. Choose Macro → Macro recording and give the macro a name.
  2. Do your steps with the normal tools.
  3. Stop recording. FreeCAD saves the steps as a Python file (.FCMacro).
  4. Run it again from Macro → Macros, or edit it to add loops and parameters.

Where to go next

  • Use a Spreadsheet plus a script to generate many variants of a part.
  • Install ready-made macros from the Addon Manager and read their code.
  • Write your own scripted objects: Python classes that behave like built-in parametric features.