Freecad Internals (dev) 🚧

Developer hub / Power users hub / mastodon / FreeCAD Developers Handbook

Advanced Screwdriver Modeling screenshot

Organisation

FreeCAD is designed from the ground up with Python integration at its core. It provides a powerful Python API that allows users to script, automate, and extend almost every part of the application. - ChatGPT

You can write Python scripts outside of FreeCAD and run them using:

$ freecadcmd script.py

Tree source

The FreeCAD source code

The FreeCAD code is programmed mainly in C++, but relies heavily on Python. A very large part of its functionality provides associated Python bindings, and it is part of the core philosophy of the FreeCAD development to always offer python access to any new feature implemented in C++. To obtain this, CPython (the C interfacing tools provided by Python itself) and specially PyCXX are heavily used throughout FreeCAD. Many templates and custom tools are also provided in the FreeCAD code itself to turn the building of associated python bindings very easy. Some more high-level parts of the FreeCAD code are coded fully in Python.

Part Module

Essentially all 2D and 3D drawing functions in every workbench (Workbench Draft.svg Draft, Workbench Sketcher.svg Sketcher, Workbench PartDesign.svg PartDesign, etc.), are based on these functions exposed by the Part Workbench. Therefore, the Part Workbench is considered the corGUI component of the modelling capabilities of FreeCAD.

Part objects are more complex than mesh objects created with the Mesh Workbench, as they permit more advanced operations like coherent boolean operations, modifications history, and parametric behaviour.

caption

Sketcher scripting

Interface Creation

  • Interface in a .ui file - This is the recommended approach.
  • Interface completely in Python code - This method is recommended only for small interfaces that don’t define more than a few widgets, for example in macros.

caption

GUI / Coin3D (SceneGraph)

In FreeCAD, normally, we don’t need to interact directly with the Open Inventor scenegraph. Every object in a FreeCAD document, being a mesh, a part shape or anything else, gets automatically converted to Open Inventor code and inserted in the main scenegraph that you see in a 3D view. That scenegraph gets updated continuously when you modify, add or remove objects. In fact every object (in App space) has a view provider (a corresponding object in Gui space) responsible for issuing Open Inventor code.

see also

Building Freecad

FreeCAD Developers Handbook

Dependencies

Technicals Guide

A guide for developers learning their way around the FreeCAD codebase.

The FreeCAD developer’s tool set:

  • C++ and Python
  • Qt: a cross platform development framework
  • OpenCascade: a geometry library
  • Coin3d: a scenegraph manager based on OpenInventor that handles drawing in the 3d window.
  • Pivy: a Python binding for Coin3d

deps

Compiling (Linux)

Wiki page advocate to first clone the Freecad Repo to yourself (for future PR). If you do so, you may want to disable the github actions in your copy.

  • Repository → Settings → Actions → General: Disable actions
$ git clone --recurse-submodules <your repo>/FreeCAD FreeCAD-src
# or 
$ git clone <your repo>/FreeCAD.git
$ git submodule update --init --recursive # if forgotten

Nix Flake

# get depandencies
$ cd Freecad
$ nix develop

Once all dependancies are available

# from your freecad-source folder:
$ mkdir build
$ cd build
# enable ninja and optionally ccache
$ cmake -G Ninja .. \
  -DCMAKE_C_COMPILER_LAUNCHER=ccache \
  -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
$ ninja -j$(nproc --ignore=2)    # or cmake --build .

Note: ccache can be used as a proxy towared icecream to distribute compilation

Troubleshooting 🚧

  • QT / GL don’t work => Freecad doesn’t start
  • PySide6 - Compilation is ok. but FreeCAD can’t locate the modules when ran.

Project 💭

  • have embeded profiling for freecad dev
Written on July 3, 2023, Last update on June 18, 2025
freecad code-review python in-progress