π Tutorial: Creating Addons for FreeCAD
Lesson Goal: Add icons to buttons and the workbench to make the addon look professional.
πΌ Part 1. Supported Icon Formats
FreeCAD supports:
- SVG (recommended) β scales without loss
- PNG β raster, but easy to use
π‘ Icons should be simple, contrasting, and recognizable even at a small size (16×16 or 24×24 pixels).
π Part 2. Icon Folder Structure
Inside your addon’s folder, create a subfolder:
BoxBuilderAddon/
βββ Resources/
β βββ icons/
β βββ box_builder.svg β workbench icon
β βββ create_box.svg β command icon
βββ InitGui.py
βββ box_builder_workbench.py
π‘ The path
Resources/icons/is a standard convention in the FreeCAD ecosystem.
π¨ Part 3. Where to get icons?
Option 1: Use built-in FreeCAD icons
FreeCAD comes with hundreds of icons. For example:
:/icons/Part_Box.svg:/icons/Document-new.svg
But it’s better to create your own β to avoid dependency on internal paths.
Option 2: Create a simple icon manually
Example: create_box.svg
<!-- create_box.svg -->
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64">
<rect x="10" y="10" width="44" height="44" fill="none" stroke="black" stroke-width="4"/>
<line x1="10" y1="10" x2="20" y2="0" stroke="black" stroke-width="4"/>
<line x1="54" y1="10" x2="64" y2="0" stroke="black" stroke-width="4"/>
<line x1="54" y1="54" x2="64" y2="44" stroke="black" stroke-width="4"/>
<line x1="20" y1="0" x2="64" y2="0" stroke="black" stroke-width="4"/>
<line x1="64" y1="0" x2="64" y2="44" stroke="black" stroke-width="4"/>
</svg>
Save this code to create_box.svg inside Resources/icons/.
π‘ You can open the SVG in a browser to see the result.
π Part 4. Connecting icons in code
Step 1. Update box_builder_workbench.py
Add to the beginning of the file (after imports):
import os
Then find the BoxBuilderCommand class and update the GetResources method:
class BoxBuilderCommand:
def GetResources(self):
# Path to the icon
icon_path = os.path.join(
os.path.dirname(__file__),
"Resources", "icons", "create_box.svg"
)
return {
"MenuText": "Box Builder",
"ToolTip": "Create a box with custom dimensions",
"Pixmap": icon_path # β connect the icon
}
# ... rest unchanged
Step 2. Add an icon for the workbench
In the BoxBuilderWorkbench class, add the Icon property:
class BoxBuilderWorkbench(FreeCADGui.Workbench):
MenuText = "Box Builder"
ToolTip = "Create custom boxes with GUI"
# Path to the workbench icon
def __init__(self):
self.Icon = os.path.join(
os.path.dirname(__file__),
"Resources", "icons", "box_builder.svg"
)
def Initialize(self):
self.list = ["BoxBuilderCommand"]
self.appendToolbar("Box Tools", self.list)
self.appendMenu("Box Builder", self.list)
def GetClassName(self):
return "Gui::PythonWorkbench"
β οΈ If you haven’t created
box_builder.svgβ just copycreate_box.svgand rename it.
π§ͺ Step 5. Verification
- Make sure the folder structure is correct:
BoxBuilderAddon/Resources/icons/create_box.svg
BoxBuilderAddon/Resources/icons/box_builder.svg
- Restart FreeCAD
- Select the Box Builder workbench
β You should see:
- An icon next to the workbench name (in the list)
- An icon on the toolbar button
π‘ Icon Tips
- Use black on a transparent background β FreeCAD will adapt it to the theme (light/dark)
- SVG size doesn’t matter β the main thing is that it’s vector
- For PNG, use a transparent background and a size of 64×64 or 128×128
- Do not use colors β icons in FreeCAD are usually monochrome
π§ͺ Practical Task
- Create the
box_builder.svgicon (you can copycreate_box.svg) - Find a free SVG box icon online (e.g., on Flaticon or Material Icons) and adapt it
- Try using PNG instead of SVG β make sure the background is transparent
π Where to get ready-made icons?
- Material Design Icons β download as SVG
- Feather Icons β simple and clean
- FreeCAD sources β hundreds of icons in
.svgformat
βΆοΈ What’s next?
In Lesson 7 we will:
- Learn how to publish an addon via the official Addon Manager
- Create a
package.xmlfile - Prepare a GitHub repository
- Make it easy for other users to install your addon