Getting Started

Welcome to pyboxbuilder! This guide introduces the core concepts and walks you through:

  1. Creating your very first box and previewing it in 3D.

  2. Designing standalone boxes (such as dice boxes or modular token trays) without an enclosing game box.

  3. Building a complete game insert that packs multiple boxes, trays, and automatic spacer trays into a publisher’s game box.

  4. Exporting and 3D printing your designs using the built-in CLI runner.

Note

All example code below uses the interactive 3D WebGL viewer. You can rotate, pan, and zoom the rendered models directly in your browser.

Installation

Install pyboxbuilder directly from PyPI (requires Python 3.11+):

# Core library
pip install pyboxbuilder

# With packing guide PDF support (fpdf2 + Pillow)
pip install "pyboxbuilder[pdf]"

# Everything (PythonSCAD + PDF + Shapely)
pip install "pyboxbuilder[all]"

Creating Your First Box

Every box in pyboxbuilder belongs to a Project. A project defines project-wide defaults (such as wall thickness, floor thickness, and edge rounding) and holds all the boxes you create.

Here is a minimal script that creates a simple dice or token box with a sliding lid:

from pyboxbuilder import BoxType, Project

# Create a project. Setting game_box_size=None indicates a standalone box.
project = Project("Quickstart", game_box_size=None)

# Add a sliding-lid box
project.box(
    BoxType.SLIDING,
    "DiceBox",
    size=(65.0, 45.0, 25.0),
    wall_thickness=2.0,
)

# In PythonSCAD, preview the box and its lid
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

In this snippet:

  • Project initializes the project. Specifying game_box_size=None tells pyboxbuilder that this box is standalone and does not need to be packed inside a board game’s cardboard box.

  • box() registers a new box. We choose BoxType.SLIDING, give it a label ("DiceBox"), and assign it an outer size of 65 mm × 45 mm × 25 mm.

  • show() renders the pieces in PythonSCAD. Passing show_lids=True displays both the box body and its sliding lid side-by-side.

Designing Standalone Boxes

Standalone boxes are ideal when you want to print individual tabletop organizers, such as:

  • Bit trays and token holders used during gameplay.

  • Dice vaults and miniature boxes.

  • Modular organizer bins with magnetic or interlocking lids.

When game_box_size=None, each box is exported independently without constraints from an enclosing game box.

Dividing into Compartments

Rather than calculating internal wall widths and floor offsets by hand, you can define compartments using relative width and length ratios via box.compartment(...):

from pyboxbuilder import BoxType, Project

project = Project("TokenOrganizer", game_box_size=None)

tray = project.box(
    BoxType.NO_LID,
    "ResourceTray",
    size=(85.0, 55.0, 22.0),
    wall_thickness=2.0,
)

# Divide into two equal wells across the width (50% each)
# holds_pieces=True rounds the bottom corners into an ergonomic scoop
tray.compartment("Wood", width_ratio=0.5, holds_pieces=True)
tray.compartment("Stone", width_ratio=0.5, holds_pieces=True)

project.show()
Loading 3-D preview…

⬇ Download STL mesh

Key features used here:

  • width_ratio=0.5: Divides the usable interior into two equal wells. The library calculates divider wall thickness and floor spacing automatically and keeps the outer walls solid around the wells.

  • holds_pieces=True: Shapes the bottom corners into smooth ergonomic scoops so tokens can be swept out easily with a fingertip (for card or tile slots that need side-wall finger access, pass cut=FingerCut.SCOOP on the compartment).

Adding Lids, Patterns, and Labels

You can customize lids with geometric patterns, finger grips, or text labels:

from pyboxbuilder import BoxType, LidBuilder, PatternBuilder, PatternType, Project

project = Project("FancyBox", game_box_size=None)

fancy = project.box(
    BoxType.SLIDING,
    "Gems",
    size=(70.0, 50.0, 30.0),
    lid=LidBuilder(
        pattern=PatternBuilder(PatternType.HEX, border_margin_mm=4.0),
        text="GEMS",
    ),
)

See the Box Types Guide & Gallery guide for full details on each lid style and parameter options.

Box Types & Closure Mechanisms

pyboxbuilder supports 23 specialized box closure and utility types (BoxType). Every type can be created via project.box(BoxType.<TYPE>, ...) or its corresponding typed builder in pyboxbuilder.builders.

Below are working examples for all 23 box types:

Sliding & Friction Closures

Sliding Lid (BoxType.SLIDING)

A sliding dovetail lid that glides along side rails with no loose parts:

project = Project("SlidingDemo")
project.box(
    BoxType.SLIDING,
    "Tokens",
    size=(60.0, 60.0, 22.0),
    lid=LidBuilder(
        pattern=PatternBuilder(PatternType.HEX),
        text="TOKENS",
    ),
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Sliding Catch Lid (BoxType.SLIDING_CATCH)

A sliding dovetail lid with an integrated detent bump catch at the leading edge to lock the lid closed:

project = Project("CatchDemo")
project.box(
    BoxType.SLIDING_CATCH,
    "CatchBox",
    size=(60.0, 60.0, 22.0),
    lid=LidBuilder(text="LOCKED"),
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Drop-On Cap Lid (BoxType.CAP)

A friction-fit cap lid that drops straight onto the box body from above with side finger cutouts:

project = Project("CapDemo")
box = project.box(
    BoxType.CAP,
    "PlayerTray",
    size=(60.0, 60.0, 22.0),
    lid=LidBuilder(text="PLAYER 1"),
)
box.compartment("LeftWell", width_ratio=0.5)
box.compartment("RightWell", width_ratio=0.5)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Telescoping Slipover Lid (BoxType.SLIPOVER)

A full-depth outer sleeve that envelopes the inner body tray completely:

project = Project("SlipoverDemo")
project.box(
    BoxType.SLIPOVER,
    "CardsBox",
    size=(60.0, 60.0, 22.0),
    lid=LidBuilder(text="DECK"),
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Inset Flush Lid (BoxType.INSET)

A flush drop-in lid that seats onto an internal stepped perimeter rabbet:

project = Project("InsetDemo")
project.box(
    BoxType.INSET,
    "InsetBox",
    size=(60.0, 60.0, 22.0),
    lid=LidBuilder(text="INSET"),
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Matchbox Sleeve & Drawer (BoxType.SLEEVE_DRAWER)

A 4-sided outer sleeve enclosing an inner drawer tray with a solid back wall and front pull handle:

project = Project("DrawerDemo")
project.box(
    BoxType.SLEEVE_DRAWER,
    "MatchboxDrawer",
    size=(60.0, 50.0, 22.0),
    drawer_handle_length=4.0,
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Hinged & Folding Closures

Monolithic Print-In-Place Hinge Box (BoxType.PRINT_IN_PLACE_HINGE)

A zero-assembly 1-piece print laid flat at 180° on the print bed with an interlocking print-in-place knuckle hinge in the middle section and front snap catches:

project = Project("PIPHingeDemo")
project.box(
    BoxType.PRINT_IN_PLACE_HINGE,
    "MiniDeckBox",
    size=(70.0, 50.0, 25.0),
    pip_bridge_width=0.40,
    pip_bridge_thickness=0.40,
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

A side-by-side 1-piece print-in-place hinged box with a recessed conical knuckle hinge, self-aligning perimeter rim, and front latch tab (based on hinge_box.scad):

project = Project("InsetHingeDemo")
project.box(
    BoxType.INSET_HINGE,
    "InsetDeckBox",
    size=(70.0, 50.0, 26.0),
    pip_hinge_radius=3.0,
    pip_radial_clearance=0.30,
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Bifold Clamshell Book Box (BoxType.CLAMSHELL)

A book-fold box with two equal-depth tray halves joined by a mid-height filament pin hinge and front snap catch:

project = Project("ClamshellDemo")
project.box(
    BoxType.CLAMSHELL,
    "DiceBook",
    size=(60.0, 50.0, 24.0),
    filament_diameter=1.75,
    hinge_count=5,
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Filament Pin Hinge (BoxType.FILAMENT_HINGE)

Interleaving knuckles precision-bored to accept a standard 1.75mm 3D printer filament strand (or custom pin diameter via filament_diameter and hinge_count) as the hinge pin:

project = Project("FilamentHingeDemo")
project.box(
    BoxType.FILAMENT_HINGE,
    "PinBox",
    size=(60.0, 50.0, 22.0),
    lid=LidBuilder(text="GEAR"),
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Magnetic Pin Hinge (BoxType.MAGNETIC_HINGE)

A filament-hinged box at the back paired with a small magnet socket at the front to hold the lid closed:

project = Project("MagneticHingeDemo")
project.box(
    BoxType.MAGNETIC_HINGE,
    "MagChest",
    size=(60.0, 50.0, 22.0),
    magnet_diameter=4.0,
    magnet_height=2.0,
    lid=LidBuilder(text="RELICS"),
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Mechanical, Magnetic & Threaded Closures

Snap-Fit Cantilever Latch (BoxType.SNAP_FIT)

A lid with integrated cantilever spring arms and 45° lead-in retention detents mating into recessed body pockets:

project = Project("SnapFitDemo")
project.box(
    BoxType.SNAP_FIT,
    "LatchBox",
    size=(60.0, 50.0, 25.0),
    cantilever_thickness=2.0,
    cantilever_width=14.0,
    detent_height=0.8,
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Twist-Lock Bayonet Container (BoxType.BAYONET)

Quarter-turn twist-lock container with vertical entry keyways and horizontal locking channels:

project = Project("BayonetDemo")
project.box(
    BoxType.BAYONET,
    "TokenCanister",
    size=(60.0, 60.0, 40.0),
    lug_count=4,
    turn_angle=90.0,
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Threaded Screw Box (BoxType.THREADED)

Coarse 3.0mm pitch modified trapezoidal screw threads with 0.25mm clearance for effortless opening:

project = Project("ThreadedDemo")
project.box(
    BoxType.THREADED,
    "ScrewCanister",
    size=(55.0, 55.0, 40.0),
    thread_pitch=3.0,
    thread_turns=2.0,
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Magnetic Closure Lid (BoxType.MAGNETIC)

Concealed cylindrical magnet pockets in corners of the body and lid for a tactile magnetic snap:

project = Project("MagneticDemo")
project.box(
    BoxType.MAGNETIC,
    "Vault",
    size=(60.0, 60.0, 22.0),
    magnet_type=MagnetType.ROUND,
    magnet_diameter=6.0,
    magnet_height=3.0,
    lid=LidBuilder(text="VAULT"),
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Tabletop & Game Play Trays

Gravity Tile & Token Dispenser (BoxType.DISPENSER)

A tile and token dispenser tower with a flat floor (or configurable chute_angle / tile_angle ramp) and front finger-pinch cutouts for pulling out the bottom tile:

project = Project("DispenserDemo")
project.box(
    BoxType.DISPENSER,
    "TileTower",
    size=(55.0, 55.0, 70.0),
    token_thickness=3.0,
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Angled Draw & Discard Card Shoe (BoxType.CARD_SHOE)

A dealer shoe tray with a 20° slanted draw well, retaining lip, and flat discard well with thumb cutouts:

project = Project("CardShoeDemo")
project.box(
    BoxType.CARD_SHOE,
    "DealerShoe",
    size=(85.0, 65.0, 30.0),
    draw_angle=20.0,
    retaining_lip_height=10.0,
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Dice Tray & Rolling Arena (BoxType.DICE_TRAY)

Deep 25mm+ arena lid with 45° corner deflector fillets and felt pocket that functions as a tabletop dice arena:

project = Project("DiceTrayDemo")
project.box(
    BoxType.DICE_TRAY,
    "RollingArena",
    size=(75.0, 75.0, 32.0),
    arena_wall_height=28.0,
    corner_deflectors=True,
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Modular Interlocking Play Trays (BoxType.MODULAR_INTERLOCK)

Tabletop organization trays with perimeter sliding dovetails or Gridfinity-compatible tiered base profiles:

project = Project("ModularDemo")
project.box(
    BoxType.MODULAR_INTERLOCK,
    "DashboardTray",
    size=(84.0, 84.0, 25.0),
    wall_thickness=4.0,
    interlock_type=InterlockType.DOVETAIL,
    dovetail_clearance=0.15,
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Open & Stackable Trays (BoxType.NO_LID)

Open organizer trays with stepped stacking ledges and ergonomic fingertip scoops:

project = Project("StackDemo")
project.box(
    BoxType.NO_LID,
    "BaseTray",
    size=(60.0, 60.0, 16.0),
    position=(10.0, 10.0, 0.0),
)
project.box(
    BoxType.NO_LID,
    "TopTray",
    size=(60.0, 60.0, 16.0),
    position=(10.0, 10.0, 16.0),
)
project.show()
Loading 3-D preview…

⬇ Download STL mesh

Card Library Box (BoxType.CARD_LIBRARY)

High-capacity card tray with finger pull-out scoops and angled card support wedges:

project = Project("CardLibraryDemo")
project.box(
    BoxType.CARD_LIBRARY,
    "DeckLibrary",
    size=(100.0, 65.0, 32.0),
    wall_thickness=2.0,
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Custom Footprints & Polygon Shapes

Polygon Footprint Path Box (BoxType.PATH)

Open custom-profile tray whose exterior footprint follows any arbitrary 2D polygon path:

project = Project("PathDemo")
l_path = (
    (0.0, 0.0),
    (55.0, 0.0),
    (55.0, 25.0),
    (25.0, 25.0),
    (25.0, 55.0),
    (0.0, 55.0),
)
project.box(
    BoxType.PATH,
    "LShapedTray",
    size=(55.0, 55.0, 20.0),
    path=l_path,
    wall_thickness=2.0,
)
project.show()
Loading 3-D preview…

⬇ Download STL mesh

Cap Lid on Polygon Footprint (BoxType.CAP_PATH)

Drop-on friction cap lid over an arbitrary 2D polygon path footprint:

project = Project("CapPathDemo")
l_path = (
    (0.0, 0.0),
    (55.0, 0.0),
    (55.0, 25.0),
    (25.0, 25.0),
    (25.0, 55.0),
    (0.0, 55.0),
)
project.box(
    BoxType.CAP_PATH,
    "CapPathTray",
    size=(55.0, 55.0, 20.0),
    path=l_path,
    color=Color("teal"),
    lid=LidBuilder(
        label_mode=LabelMode.FRAMED,
        text_color=Color("white"),
        frame_color=Color("silver"),
        border_margin_mm=3.0,
        pattern=PatternBuilder(PatternType.HEX, spacing=8.0),
    ).titled("PARTS"),
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Slipover on Polygon Footprint (BoxType.SLIPOVER_PATH)

Full-depth telescoping slipover sleeve over an arbitrary 2D polygon path footprint:

project = Project("SlipoverPathDemo")
t_path = (
    (15.0, 0.0),
    (40.0, 0.0),
    (40.0, 30.0),
    (55.0, 30.0),
    (55.0, 55.0),
    (0.0, 55.0),
    (0.0, 30.0),
    (15.0, 30.0),
)
project.box(
    BoxType.SLIPOVER_PATH,
    "SlipoverPathTray",
    size=(55.0, 55.0, 20.0),
    path=t_path,
    lid=LidBuilder(text="T-TRAY"),
)
project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

Building a Game Box Insert

When designing an insert for a retail board game, the goal is to pack multiple sub-boxes snugly into the publisher’s cardboard box, leaving room at the top for folded boards and rulebooks.

To build a full insert:

  1. Measure the inside dimensions of the cardboard game box (width, length, height) in mm.

  2. Pass game_box_size=(W, L, H) to Project.

  3. Set board_thickness to reserve height at the top for the game board and rulebook.

  4. Set generate_spacers=True to automatically fill leftover voids with custom-fit spacer trays.

Arranging Boxes & Generating Spacers

You can position boxes declaratively using columns(), rows(), and stack(), or explicit coordinates, and let the spacer generator compute the rest:

from pyboxbuilder import BoxType, Project

# Define the game box interior: 100mm x 90mm x 28mm
project = Project(
    "GameInsertDemo",
    game_box_size=(100.0, 90.0, 28.0),
    board_thickness=6.0,   # Leaves 6mm at the top for the board
    generate_spacers=True, # Auto-fills dead space with open trays
)

# Box 1: An open card caddy
project.box(
    BoxType.NO_LID,
    "Cards",
    size=(46.0, 50.0, 20.0),
    position=(2.0, 2.0, 0.0),
)

# Box 2: A sliding token box
project.box(
    BoxType.SLIDING,
    "Tokens",
    size=(46.0, 50.0, 20.0),
    position=(50.0, 2.0, 0.0),
)

project.show(show_lids=True)
Loading 3-D preview…

⬇ Download STL mesh

In this preview:

  • The Cards and Tokens boxes are placed side-by-side.

  • The remaining void along the back of the game box is automatically detected and filled with a custom-fitted spacer tray (Spacer_...).

  • When packed into the game box, the components and spacers lock together to prevent shifting when the game is stored vertically.

Exporting and 3D Printing with CLI

Every script can be run through the unified CLI entrypoint run():

from pyboxbuilder import BoxType, Project, run

project = Project("MyInsert", game_box_size=(295.0, 295.0, 70.0))
# ... define boxes ...

if __name__ == "__main__":
    run(project)

Command-Line Usage

Preview in PythonSCAD:

python my_insert.py

Preview with all lids included:

python my_insert.py --lids

Preview only a specific box:

python my_insert.py --box Tokens

Export printable 3MF / STL files:

python my_insert.py --export --out ./output/

Next Steps