Enclosures
Generate a case around what goes inside it: a ready electronics board, a
battery holder, your own part. The case reads its contents’ size, mounting
holes and connectors, then builds bosses under the holes, cutouts on the
walls the connectors face and windows over LEDs and buttons, in the
manufacturing style you pick. This is the cadbuildr-enclosures library,
built on Foundation.
Prerequisites: pip install cadbuildr-enclosures (it installs
cadbuildr-foundation, cadbuildr-stdlib and cadbuildr-electronics).
Put a board in a printed case
from cadbuildr.foundation import show
from cadbuildr.electronics.boards import ESP32DevKit
from cadbuildr.enclosures import Enclosure, PrintedShell
case = Enclosure(contents=[ESP32DevKit()], style=PrintedShell(vents="slots"))
print(case.summary()["inner"]) # cavity x, y, h in mm
show(case)The micro-USB cutout lands on the wall the connector faces, the board stands
on its seat above the floor (high enough to clear the through-hole leads),
and the lid is held by four screws into corner pillars. Swap the board for
RaspberryPi() and the case grows to fit it.
Check that everything lines up
Every cutout, boss and window is joined to the content feature it answers
with connect, so the assembly check proves they line up:
issues = [i for i in case.check() if i["severity"] != "info"]
assert issues == []If you change a board after generating its case, connecting fails with
LoopMismatch instead of leaving a misaligned hole. Generate the case again.
Pick a manufacturing style
| Style | What you get |
|---|---|
PrintedShell() | 3D-printed tray and lid. closure="snap", bosses="insert" (heat-set inserts), vents="hex", gasket=1.5, ears=True, din="TS35x7.5", label="NODE 1" |
SheetMetalShell() | U-shaped base and U-shaped lid in 1 mm sheet, board on spacers |
FlatPackBox() | six laser-cut 3 mm plates with tabs and slots |
ExtrudedBox() | aluminium tube in Hammond 1455 sizes with card guides and end panels; series="auto" picks the smallest that fits |
from cadbuildr.enclosures import BoardEnclosure
show(BoardEnclosure(board="RaspberryPi", style="sheet_metal"))BoardEnclosure takes every option as an input, so in the viewer’s
configuration bar you can change the board, the style or the vents and watch
the case re-fit.
Several items, glands and mounting
from cadbuildr.enclosures import BatteryHolder
case = Enclosure(
contents=[ESP32DevKit(), BatteryHolder(cell="AA", count=2)],
style=PrintedShell(),
glands=[("auto", "M12")], # cable gland on the wall with the fewest openings
headroom=8,
)Items are laid out side by side (arrange="row" or "column",
rotate=[0, 90]). A case with din=... exposes a din interface that
connects to a DinRail; ears=True adds wall-mount ears.
Reference
- Hardware with interfaces:
CableGland(M12-M32, PG7-PG11),Spacer,HeatSetInsert,ButtonCap,BatteryHolder,DinRail(EN 60715),RackPanel(EIA-310 19” / 10”). - Errors:
FitError(does not fit the style: wall too thin for a gasket, no extruded series large enough, no room for a gland),LoopMismatch,IncompatibleInterfaces(cutout smaller than the port, wall thicker than the gland thread). - Your own content works when it carries a
bottomPlaneFace,ScrewHoles in groupmount_under, andConnectorPort/PanelFeatureinterfaces.