Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧱 BrickFace — FreeCAD Addon

FreeCAD License: MIT Python

FR — Transformez n'importe quelle face plane en face compatible LEGO® (tenons ou creux) en deux clics, directement depuis le panneau Face Tools de Part Design.

EN — Turn any planar face into a LEGO®-compatible face (studs or sockets) in two clicks, straight from the Part Design Face Tools panel.

Brique 4x3 générée / Generated 4x3 brick


🇫🇷 Français

Ce que fait l'addon

L'addon ajoute une entrée « Transformer en face de brique » (Transform to brick face) dans le panneau Face Tools (onglet Tâches) du workbench Part Design. Elle apparaît dès qu'une face plane est sélectionnée.

Entrée dans le panneau Face Tools

Un clic ouvre une fenêtre d'options, puis la géométrie est générée.

Installation

Via l'Addon Manager (recommandé, une fois l'addon indexé) : Outils ▸ Addon Manager ▸ rechercher BrickFace ▸ Installer.

Ou avec le script d'installation automatique (détecte le chemin Mod et la version de FreeCAD) :

git clone https://github.com/jacquesh82/FreeCAD-BrickFace.git
cd FreeCAD-BrickFace
./scripts/setup.sh          # Linux / macOS
# Windows : powershell -ExecutionPolicy Bypass -File scripts\setup.ps1

Le script installe l'addon par liens symboliques quand c'est possible (un git pull suffit alors pour mettre à jour), sinon par copie. Options : ./scripts/setup.sh --remove pour désinstaller, FREECAD_MOD=/chemin/Mod pour forcer la destination.

Ou manuellement — 1. Cloner le dépôt dans le dossier Mod de FreeCAD

git clone https://github.com/jacquesh82/FreeCAD-BrickFace.git \
  ~/.local/share/FreeCAD/v1-1/Mod/BrickFace

⚠️ Attention au chemin. Depuis FreeCAD 1.1, le dossier utilisateur contient un sous-dossier de version (v1-1). Pour connaître le bon chemin sur votre machine, tapez dans la console Python de FreeCAD :

import FreeCAD; print(FreeCAD.getUserAppDataDir() + "Mod")
Système Chemin typique
Linux ~/.local/share/FreeCAD/v1-1/Mod/
Windows %APPDATA%\FreeCAD\v1-1\Mod\
macOS ~/Library/Application Support/FreeCAD/v1-1/Mod/

2. Redémarrer FreeCAD. C'est tout — aucun workbench à activer, l'entrée apparaît automatiquement dans Part Design.

Alternative : lien symbolique (pour développer)
git clone https://github.com/jacquesh82/FreeCAD-BrickFace.git ~/dev/FreeCAD-BrickFace
ln -s ~/dev/FreeCAD-BrickFace ~/.local/share/FreeCAD/v1-1/Mod/BrickFace

Utilisation

  1. Ouvrez un modèle contenant un corps (PartDesign::Body).
  2. Basculez sur le workbench Part Design.
  3. Cliquez sur une face plane dans la vue 3D.
  4. Dans le panneau Tâches à gauche → Transformer en face de brique (Transform to brick face si FreeCAD est en anglais).
  5. Réglez les options, puis OK.

Fenêtre d'options

Langue de l'interface

L'interface suit la langue de FreeCAD (Édition ▸ Préférences ▸ Général ▸ Langue) : anglais par défaut, traduction française incluse. Les libellés ci-dessous sont ceux de l'interface française.

Options

Option Description Défaut
Mâle (tenons) Ajoute des tenons en relief sur la face Ø 4.8 mm × 1.8 mm
Femelle (creux) Creuse des logements pour recevoir des tenons Ø 4.9 mm × 1.8 mm
Impression FDM Ajoute du jeu sur la partie femelle : +0.3 mm au diamètre, +0.2 mm à la profondeur cochée
Colonnes (N) Nombre de tenons en largeur — pré-calculé depuis la taille de la face auto
Rangées (M) Nombre de tenons en hauteur — pré-calculé auto
Pas Entraxe entre tenons (standard de brique) 8.00 mm
Disposition Pleine (toute la face), Répartie, Bordure (anneau extérieur) ou Côtés (colonnes gauche/droite) Pleine
Densité Pour la disposition Répartie : Dense (1 sur 2, damier), Moyenne (1 sur 4) ou Faible (1 sur 9) Dense
Diamètre Diamètre des tenons ou des creux 4.8 / 4.9 mm
Hauteur / Profondeur Hauteur des tenons ou profondeur des creux 1.80 mm

La grille est toujours centrée sur la face, quelle que soit la disposition. Le texte en bas de la fenêtre affiche le nombre réel de tenons (16 tenons (grille 6 × 4) sur 48.0 × 32.0 mm en Bordure, par exemple).

💡 À quoi sert la case « Impression FDM » ? En impression FDM, les trous sortent typiquement 0.2 à 0.4 mm plus petits que modélisés. La case (cochée par défaut) élargit les creux à Ø 5.2 mm (imprimé ≈ 4.9–5.0 mm, le jeu voulu autour d'un tenon de 4.8 mm) et porte la profondeur à 2.0 mm pour que les faces se plaquent. Décochez-la pour de l'usinage ou de la résine (cotes nominales). Si l'assemblage reste trop lâche ou trop serré, ajustez le diamètre par pas de 0.1 mm.

Résultat dans l'arbre

L'addon ne crée aucun objet exotique : uniquement de la géométrie Part Design native.

Body
├── BasePad
├── BrickSketch      ← esquisse attachée à la face (MapMode = FlatFace)
└── BrickStuds       ← Pad (mâle)  ou  BrickHoles = Pocket (femelle)

Conséquences :

  • ✅ Tout reste modifiable : double-cliquez sur BrickStuds pour changer la hauteur, ou éditez BrickSketch pour déplacer un tenon.
  • ✅ Le fichier .FCStd s'ouvre sans l'addon sur n'importe quelle installation FreeCAD.
  • ✅ Compatible avec l'historique paramétrique et les répétitions (LinearPattern, Mirrored…).

Dépannage

Problème Solution
L'entrée n'apparaît pas Vérifiez le chemin d'installation (voir l'encadré ⚠️ ci-dessus) et redémarrez FreeCAD.
L'entrée est grisée Sélectionnez une seule face, et qu'elle soit plane (les faces cylindriques ne sont pas gérées).
« La face n'appartient pas à un corps » La face doit faire partie d'un PartDesign::Body. Une forme du workbench Part ne convient pas.
Erreur à la validation La grille dépasse peut-être la face : réduisez N × M ou le pas.

Tests

FreeCADCmd tests/headless_test.py

Vérifie le calcul de grille, le nombre de cercles générés et les volumes résultants (mâle et femelle), sans interface graphique.

Note technique

Gui.Control.addTaskWatcher() remplace la liste complète des task watchers — il n'existe pas d'API pour en ajouter un seul. freecad/BrickFace/watcher.py réplique donc la liste installée par PartDesignGui::Workbench::activated() (FreeCAD 1.1.3) en y insérant Brick_TransformFace, puis la réinstalle à chaque activation du workbench Part Design.

Si une future version de FreeCAD modifie son panneau Tâches, seul ce fichier est à mettre à jour. En cas d'échec, l'installation est protégée par un try/except : le panneau standard reste intact et la commande demeure accessible.


🇬🇧 English

What it does

This addon adds a "Transform to brick face" entry to the Face Tools panel (Tasks tab) of the Part Design workbench. It shows up as soon as a planar face is selected.

Entry in the Face Tools panel

One click opens an options dialog, then the geometry is generated.

Installation

Via the Addon Manager (recommended, once the addon is indexed): Tools ▸ Addon Manager ▸ search for BrickFace ▸ Install.

Or with the automatic setup script (detects the Mod path and the FreeCAD version):

git clone https://github.com/jacquesh82/FreeCAD-BrickFace.git
cd FreeCAD-BrickFace
./scripts/setup.sh          # Linux / macOS
# Windows: powershell -ExecutionPolicy Bypass -File scripts\setup.ps1

The script installs via symlinks when possible (a git pull is then enough to update), otherwise via copy. Options: ./scripts/setup.sh --remove to uninstall, FREECAD_MOD=/path/to/Mod to force the destination.

Or manually — 1. Clone the repository into FreeCAD's Mod folder

git clone https://github.com/jacquesh82/FreeCAD-BrickFace.git \
  ~/.local/share/FreeCAD/v1-1/Mod/BrickFace

⚠️ Mind the path. Since FreeCAD 1.1 the user folder contains a version subfolder (v1-1). To find the correct path on your machine, run this in FreeCAD's Python console:

import FreeCAD; print(FreeCAD.getUserAppDataDir() + "Mod")
OS Typical path
Linux ~/.local/share/FreeCAD/v1-1/Mod/
Windows %APPDATA%\FreeCAD\v1-1\Mod\
macOS ~/Library/Application Support/FreeCAD/v1-1/Mod/

2. Restart FreeCAD. That's it — no workbench to activate, the entry appears in Part Design automatically.

Alternative: symlink (for development)
git clone https://github.com/jacquesh82/FreeCAD-BrickFace.git ~/dev/FreeCAD-BrickFace
ln -s ~/dev/FreeCAD-BrickFace ~/.local/share/FreeCAD/v1-1/Mod/BrickFace

Usage

  1. Open a model containing a body (PartDesign::Body).
  2. Switch to the Part Design workbench.
  3. Click a planar face in the 3D view.
  4. In the Tasks panel on the left → Transform to brick face.
  5. Adjust the options, then hit OK.

Options dialog

UI language

The UI follows FreeCAD's language (Edit ▸ Preferences ▸ General ▸ Language): English by default, French translation included.

Options

Option Description Default
Male (studs) Adds raised studs on the face Ø 4.8 mm × 1.8 mm
Female (sockets) Cuts recesses that accept studs Ø 4.9 mm × 1.8 mm
FDM printing Adds clearance on the female side: +0.3 mm diameter, +0.2 mm depth checked
Columns (N) Stud count across the width — auto-computed from face size auto
Rows (M) Stud count across the height — auto-computed auto
Pitch Centre-to-centre spacing (brick standard) 8.00 mm
Layout Full face, Spread, Border (outer ring) or Sides (left/right columns) Full
Density For the Spread layout: Dense (1 of 2, checkerboard), Medium (1 of 4) or Sparse (1 of 9) Dense
Diameter Stud or socket diameter 4.8 / 4.9 mm
Height / Depth Stud height or socket depth 1.80 mm

The grid is always centred on the face, whatever the layout. The label at the bottom of the dialog shows the actual stud count (e.g. 16 studs (grid 6 × 4) on 48.0 × 32.0 mm with Border).

💡 What does the "FDM printing" checkbox do? FDM-printed holes typically come out 0.2–0.4 mm smaller than modelled. The checkbox (on by default) widens sockets to Ø 5.2 mm (prints at ~4.9–5.0 mm, the right clearance around a 4.8 mm stud) and deepens them to 2.0 mm so mating faces seat flush. Untick it for machining or resin printing (nominal dimensions). If the fit is still too loose or too tight, tune the diameter in 0.1 mm steps.

Result in the tree

The addon creates no exotic objects — only native Part Design geometry.

Body
├── BasePad
├── BrickSketch      ← sketch attached to the face (MapMode = FlatFace)
└── BrickStuds       ← Pad (male)  or  BrickHoles = Pocket (female)

Which means:

  • ✅ Everything stays editable: double-click BrickStuds to change the height, or edit BrickSketch to move a stud.
  • ✅ The .FCStd file opens without the addon on any FreeCAD installation.
  • ✅ Works with the parametric history and patterns (LinearPattern, Mirrored, …).

Troubleshooting

Issue Fix
Entry doesn't show up Check the install path (see the ⚠️ box above) and restart FreeCAD.
Entry is greyed out Select exactly one face, and make sure it's planar (cylindrical faces aren't supported).
"Face doesn't belong to a body" The face must be part of a PartDesign::Body. A plain Part workbench shape won't work.
Error on confirm The grid may overflow the face: lower N × M or the pitch.

Tests

FreeCADCmd tests/headless_test.py

Checks grid computation, generated circle count, and resulting volumes (male and female) — headless, no GUI needed.

Technical note

Gui.Control.addTaskWatcher() replaces the whole task-watcher list — there is no API to append a single one. So freecad/BrickFace/watcher.py replicates the list installed by PartDesignGui::Workbench::activated() (FreeCAD 1.1.3), inserts Brick_TransformFace into it, and reinstalls it on every Part Design workbench activation.

If a future FreeCAD release changes its Tasks panel, only that file needs updating. Installation is wrapped in a try/except: on failure the stock panel stays intact and the command remains reachable.


📁 Project structure

FreeCAD-BrickFace/
├── package.xml                 # Addon Manager metadata (manifest)
├── freecad/
│   └── BrickFace/               # modern namespaced layout (freecad.BrickFace)
│       ├── __init__.py         # brick constants (PITCH, STUD_D, STUD_H…)
│       ├── init_gui.py         # command registration + workbenchActivated hook
│       ├── commands.py         # Brick_TransformFace command
│       ├── task_panel.py       # options dialog (PySide)
│       ├── geometry.py         # grid maths + Sketch/Pad/Pocket creation
│       ├── watcher.py          # Face Tools panel injection
│       └── resources/
│           ├── icons/
│           └── translations/   # BrickFace_fr.ts / .qm (French UI)
└── tests/headless_test.py
    scripts/
    ├── setup.sh               # automatic install (Linux / macOS)
    └── setup.ps1              # automatic install (Windows)

📐 Brick reference dimensions (LEGO-compatible)

Dimension Value
Grid pitch / Pas de grille 8.00 mm
Stud diameter / Diamètre tenon 4.80 mm
Stud height / Hauteur tenon 1.80 mm
Plate height / Hauteur plaque 3.20 mm
Brick height / Hauteur brique 9.60 mm

📄 License

MIT © 2026 Jacques HULLU

LEGO® is a trademark of the LEGO Group, which does not sponsor, authorise or endorse this project. LEGO® est une marque du groupe LEGO, qui ne sponsorise ni n'approuve ce projet.

About

FreeCAD addon: turn any planar face into a LEGO-compatible face (studs or sockets) from the Part Design Face Tools panel

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages