pyboxbuilder

High-Precision Board Game Inserts & Parametric 3D Printable Box Toolkit for PythonSCAD

pyboxbuilder is a declarative 3D modeling and board game insert design framework. Built on top of PythonSCAD and pybosl2, it transforms high-level descriptions of games, boxes, and game pieces into production-ready CSG geometry, interactive 3D WebGL models, multi-material 3MF files, and exploded assembly layout PDFs.

The library’s governing principle is good defaults, not options: you describe the physical storage you need — the game box footprint, card counts, token divisions, scoops, and lid patterns — without manually calculating wall offsets, sliding dovetail tolerances, 3D printing nozzle clearances, or draft angles.

project = Project(
    "Showcase",
    game_box_size=(100.0, 90.0, 28.0),
    board_thickness=6.0,
    generate_spacers=True,
)
project.box(
    BoxType.SLIDING,
    "Tokens",
    size=(46.0, 50.0, 20.0),
    position=(2.0, 2.0, 0.0),
    color=Color("midnightblue"),
    lid=LidBuilder(
        label_mode=LabelMode.FRAMED,
        frame_color=Color("gold"),
        text_color=Color("white"),
        pattern=PatternBuilder(PatternType.HEX, spacing=8.0),
    ).titled("TOKENS"),
)
tray = project.box(
    BoxType.NO_LID,
    "Dice",
    size=(46.0, 50.0, 20.0),
    position=(50.0, 2.0, 0.0),
    color=Color("coral"),
)
tray.compartment("D6", width_ratio=0.5, holds_pieces=True)
tray.compartment("D20", width_ratio=0.5, holds_pieces=True)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Why pyboxbuilder?

Designing board game inserts by hand in traditional CAD requires tedious trial-and-error math: subtracting wall thicknesses, offsetting dovetail channels, computing lid clearances, and laying out rectangular coordinates. When a box size or card count changes, the entire model must be manually recalculated.

pyboxbuilder replaces manual arithmetic with declarative constraints:

  • Specify What You Need, Not the Booleans: Define box types, dimensions, card counts, token divisions, and lid decorations. The library derives all mating clearances, corner roundings, draft angles, and boolean carve-outs automatically.

  • Guaranteed Printability: Every geometric parameter has defaults derived from the box’s scale and 3D printing physics (0.4mm nozzle standards, 45° overhang limits, ergonomic reach).

  • Multi-Color Interactive 3D Previews: Inspect models in PythonSCAD’s GUI or embed interactive WebGL viewers directly in documentation and web pages, with multi-color visual separation between bodies, lids, inlays, and spacers.

  • Production 3MF & PDF Pipelines: Export multi-color (MMU) or single-color 3MF files with geometric change detection (unchanged boxes build in milliseconds) alongside multi-page exploded 3D assembly guides (layout.pdf).

Core Design Workflow

Creating a custom game insert with pyboxbuilder follows seven declarative steps:

1. Declare the Project & Game Box Constraints

Start by declaring a Project with the inside dimensions of the game box:

from pyboxbuilder import Project

project = Project(
    "TerraformingMars",
    game_box_size=(290.0, 290.0, 70.0),
    board_thickness=12.0,       # reserves vertical clearance for folded boards
    generate_spacers=True,      # sweeps empty voids into snug removable trays
)

2. Choose Box Types & Closure Mechanics

pyboxbuilder supports 25 specialized box types spanning 6 closure families (see the Box Types Guide & Gallery):

3. Divide into Ergonomic Compartments

Subdivide box interiors by ratio without tedious wall arithmetic. Set holds_pieces=True to generate smooth cylindrical corner fillets, allowing small chits, cubes, and tokens to scoop effortlessly into fingertips:

tokens = project.box(BoxType.CAP, "ResourceTray", size=(120.0, 80.0, 24.0))
tokens.compartment("Credits", width_ratio=0.33, holds_pieces=True)
tokens.compartment("Steel", width_ratio=0.33, holds_pieces=True)
tokens.compartment("Titanium", width_ratio=0.34, holds_pieces=True)

4. Auto-Size from Real Game Pieces & Cards

Never guess well dimensions. Specify card counts, dimensions, and sleeve allowances, and let pyboxbuilder compute the required box footprint and height:

cards = project.box(BoxType.SLIDING, "CorporationCards")
cards.cards("Corporations", count=40, size=(63.5, 88.0), sleeved=True)

5. Style Lids with Patterns & Multi-Color Inlays

Decorate lids with open ventilation/saving patterns, framed borders, and contrasting multi-color text labels using LidBuilder:

from pyboxbuilder import Color, LabelMode, LidBuilder, PatternBuilder, PatternType

lid_style = LidBuilder(
    label_mode=LabelMode.FRAMED,
    frame_color=Color("gold"),
    pattern=PatternBuilder(type=PatternType.HEX, spacing=10.0),
).titled("CARDS", text_color=Color("white"))

6. Relative Layout & 3D Packing

Organize boxes cleanly inside the game box using declarative relative layouts (columns(), rows(), stack()) or automated 3D skyline bin packing:

from pyboxbuilder import columns, stack

project.arrange(columns(
    "CorporationCards",
    stack("ResourceTray", "DiceTray"),
))

7. Production Export & Assembly Guides

Export per-piece 3MF models ready for single-color or multi-material slicers (Bambu Studio, PrusaSlicer, OrcaSlicer) and an exploded assembly layout guide:

project.export("output/")

Interactive Feature Showcase

Here are interactive examples highlighting key capabilities of the toolkit. Each example renders an interactive 3D model with multi-color visual separation between box bodies, lids, labels, and accents.

Example 1: Deck Box Sized from Cards with Framed Accent Lid

This example defines a sliding card box where the internal height and depth are calculated automatically from the card deck dimensions and thickness. The lid features a framed contrasting label:

project = Project("CardGame")
cards = project.box(
    BoxType.SLIDING,
    "Cards",
    size=(75.0, 105.0, None),
    color=Color("darkslateblue"),
    lid=LidBuilder(
        label_mode=LabelMode.FRAMED,
        frame_color=Color("gold"),
        text_color=Color("white"),
        pattern=PatternBuilder(PatternType.DENSE_HEX),
    ).titled("CARDS"),
)
cards.cards("Deck", count=100, size=(63.5, 88.0))
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Example 2: Token Organizer with Ergonomic Piece Scoops

This 4-compartment token organizer uses ratio-based dividers and rounded interior bottoms (holds_pieces=True) so wooden meeples, plastic cubes, and cardboard tokens slide smoothly out into your hand:

project = Project("TokenOrganizer")
tokens = project.box(
    BoxType.CAP,
    "Tokens",
    size=(120.0, 70.0, 26.0),
    color=Color("darkgreen"),
    lid=LidBuilder(
        label_mode=LabelMode.FRAMED,
        frame_color=Color("gold"),
        text_color=Color("white"),
        pattern=PatternBuilder(PatternType.OCTAGON),
    ).titled("RESOURCES"),
)
tokens.compartment("Coins", width_ratio=0.25, holds_pieces=True)
tokens.compartment("Gems", width_ratio=0.25, holds_pieces=True)
tokens.compartment("Wood", width_ratio=0.25, holds_pieces=True)
tokens.compartment("Ore", width_ratio=0.25, holds_pieces=True)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Example 3: Monolithic Print-in-Place Hinged Box

This box prints flat in a single operation with zero assembly required. It joins body and lid along their shared rim with a 3D-printable flexible bridge hinge and integrated front tactile snap catches:

project = Project("HingeCase")
box = project.box(
    BoxType.PRINT_IN_PLACE_HINGE,
    "Tools",
    size=(90.0, 60.0, 24.0),
    color=Color("teal"),
    pip_bridge_width=0.40,
    pip_bridge_thickness=0.40,
    lid=LidBuilder(
        label_mode=LabelMode.FRAMED,
        frame_color=Color("goldenrod"),
        text_color=Color("white"),
        pattern=PatternBuilder(PatternType.HEX, spacing=8.0),
    ).titled("KIT"),
)
box.compartment("Bits", width_ratio=0.5, holds_pieces=True)
box.compartment("Drivers", width_ratio=0.5, holds_pieces=True)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Core System Architecture

Subsystem

Description & Capabilities

Box Builders

25 typed builders in pyboxbuilder.builders (see Box Types Guide & Gallery) supporting sliding dovetails (SLIDING, SLIDING_CATCH), friction caps (CAP), telescoping slipovers (SLIPOVER), print-in-place, filament-pin, magnetic-catch, and sliding-catch hinges (PRINT_IN_PLACE_HINGE, INSET_HINGE, CLAMSHELL, FILAMENT_HINGE, MAGNETIC_HINGE, SLIDING_HINGE), mechanical/magnetic closures (SNAP_FIT, BAYONET, THREADED, MAGNETIC, INSET, SLEEVE_DRAWER), stackable open bins (NO_LID), tabletop utilities (CARD_LIBRARY, DISPENSER, CARD_SHOE, DICE_TRAY, MODULAR_INTERLOCK), and polygon path footprints (PATH, CAP_PATH, SLIPOVER_PATH).

Compartments & Ergonomics

Ratio-based compartment division (box.compartment(...)), ergonomic rounded token scoops (holds_pieces=True), full-depth push-through holes, hex grids, and arbitrary SVG pocket silhouettes.

Lid Decoration

20 surface patterns and multi-color tessellations (hex, dense hex, triangles, octagons, voronoi, leaf tessellations, dice, rings, checkerboards, stepped 3D cubes, tumbling blocks, chevrons, Penrose, and Ammann–Beenker tilings — see Lid Patterns Guide & Gallery), thin multi-color MMU inlays with a selectable backing lattice, and framed/frameless labels or multi-color top-layer logos with automatic font scaling (Lid Labels Guide & Showcase, LidBuilder).

Layout & 3D Packing

Declarative relative layout trees (columns(), rows(), stack()) or automated 3D skyline bin packing within the declared game_box_size.

Automatic Spacers

3D void sweep, merge, and generation of custom-fit open spacer trays (generate_spacers=True) to secure components during vertical shelf storage.

Card & Sleeve Support

Built-in card dimension catalog and sleeve clearance formulas for standard board game card sizes and premium sleeves.

Installation & Quickstart

pyboxbuilder requires Python 3.12+ and PythonSCAD for geometry evaluation:

python3 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"

To verify your installation and run the test suite:

PYBOXBUILDER_EXPORT_FN=12 python3 -m pytest tests/test_pyboxbuilder/ -q
ruff check pyboxbuilder/ boxes/
mypy pyboxbuilder/

Documentation Index

User Guide

API Reference