π Tutorial: Creating Addons for FreeCAD
Lesson Goal: Set up everything necessary to create, test, and debug addons effortlessly.
- π§ Step 1. Make sure you have FreeCAD installed
- π Step 2. Find the Addon Folder
- π₯ Step 3. Configure a Text Editor (optional, but highly recommended)
- π Step 4. Explore FreeCAD’s Built-in Tools
- π§ͺ Step 5. Verification: Create a Test Folder
- π Developer Folder Structure (Summary)
- β Practical Task
- βΆοΈ What’s next?
π§ Step 1. Make sure you have FreeCAD installed
Requirements:
- FreeCAD version 0.20 or newer (1.0+ is better)
- Runs on Windows, Linux, or macOS
π If you don’t have FreeCAD yet, download it from the official website:
π https://www.freecad.org/downloads.php
Choose:
- Windows:
.exe(installer) or.7z(portable) - Linux: AppImage or package from repository
- macOS:
.dmg
π‘ Tip: For learning, it’s better to use an installed version (via installer), as it’s more stable and easier to set up.
π Step 2. Find the Addon Folder
FreeCAD looks for user-defined addons in a special Mod folder.
The path depends on your OS and installation type.
β How to find the folder precisely?
- Launch FreeCAD.
- Open the Python Console:
View β Panels β Python console - Enter the command:
import FreeCAD
print(FreeCAD.getUserAppDataDir())
- Press Enter.
You will see a path, for example:
- Windows (installed version):
C:\Users\YourName\AppData\Roaming\FreeCAD\ - Windows (portable):
D:\FreeCAD\data\ - Linux:
/home/your_name/.local/share/FreeCAD/ - macOS:
/Users/your_name/Library/Application Support/FreeCAD/
β Create the Mod folder
Inside this directory, there must be a Mod folder.
If it doesn’t exist, create it manually.
Example for Windows:
C:\Users\YourName\AppData\Roaming\FreeCAD\Mod\
π‘ Quick way to open the folder on Windows:
Press Win + R β type%APPDATA%\FreeCADβ Enter
π₯ Step 3. Configure a Text Editor (optional, but highly recommended)
While you can write code in Notepad, it’s more convenient to use an editor with:
- Python syntax highlighting
- Autocompletion
- Ability to run scripts
πΉ We recommend: Visual Studio Code (VS Code)
- Download and install: https://code.visualstudio.com/
- Install the Python extension (from Microsoft)
- (Optional) Install the FreeCAD for VS Code extension β it adds FreeCAD API hints
πΉ How to open the addon folder in VS Code?
- Launch VS Code
File β Open Folder- Select the
Modfolder (or a specific addon within it)
Now you can see the project structure and edit files comfortably.
π Step 4. Explore FreeCAD’s Built-in Tools
FreeCAD already contains everything you need for development.
1. Python Console
- Menu:
View β Panels β Python console - Allows executing commands in real-time
- Example: type
App.newDocument()β a new document will be created
2. Report View
- Menu:
View β Panels β Report view - Shows errors, warnings, logs
- Always keep it open when testing an addon!
3. Macro Recorder
- Menu:
Macro β Macros... - Record button β records your actions as Python code
- An excellent way to learn the FreeCAD API
π‘ Try this:
- Click Macro β Start recording
- Create a box (
Part β Box)- Stop recording
- Open the macro β you’ll see the actual code for creating the object!
π§ͺ Step 5. Verification: Create a Test Folder
To ensure everything is working:
- In the
Modfolder, create a subfolder:
TestAddon
- Inside, create an
__init__.pyfile (it can be empty) β this tells Python that the folder is a module. - Restart FreeCAD.
- Open the Report view.
If you don’t see any errors β it means FreeCAD successfully scanned the Mod folder.
β If an
ImportErrorappears β check:
- Correctness of the folder name (no spaces or Cyrillic characters)
- Presence of
__init__.py(not always mandatory in newer versions, but safer to add)
π Developer Folder Structure (Summary)
By the end of this lesson, you should have this structure:
(FreeCAD user folder)
βββ Mod/
βββ TestAddon/
βββ __init__.py β can be empty
And you know:
- Where
Modis located - How to open Python Console and Report View
- How to use the Macro Recorder
- How to set up VS Code (optional)
β Practical Task
- Find the
Modfolder viaFreeCAD.getUserAppDataDir() - Create a
MyFirstAddonfolder insideMod - Add an empty
__init__.pyfile to it - Restart FreeCAD
- Make sure there are no errors in the Report view
π― Goal: FreeCAD should launch without errors and “see” your folder.
βΆοΈ What’s next?
In Lesson 2, we will create a real working addon:
- Add a button
- Make it do something
- Learn to register commands and workbenches