pyboxbuilder.project.core.Project

class pyboxbuilder.project.core.Project(name: str, game_box_size: tuple[float, float, float] | None = None, wall_thickness: float = 2.0, floor_thickness: float = 1.6, lid_thickness: float = 2.0, rounding: float | None = None, base_rounding: float | None = None, base_chamfer: float | bool | None = None, inner_rounding: float | None = None, gap_threshold: float = 10.0, min_spacer_dim: float = 15.0, min_spacer_height: float = 10.0, max_height_absorb: float = 10.0, clearance_slack: float | None = None, board_thickness: float = 0.0, board_on_bottom: bool = False, ribbon_channels: bool = False, generate_spacers: bool = True, box_defaults: dict[str, Any] | None = None)[source]

Bases: object

Top-level game insert description.

The single-import entry point for defining a board game insert. Delegates to ProjectManifest, LayoutCompiler, and GeometryPipeline (FR-093).

Examples

A two-box insert previewed as separate solids:

p = Project("Cards", game_box_size=(300, 300, 80))
p.box(BoxType.SLIDING, "Cards", size=(120, 70, 50))
p.box(BoxType.NO_LID, "Tokens", size=(80, 60, 30))
p.show()
Loading 3-D preview…

⬇ Download STL mesh

Four equal wells sharing a box’s room, sized by ratio:

p = Project("Divided", game_box_size=(200, 150, 60))
box = p.box(BoxType.NO_LID, "Sorted", size=(100, 80, 30))
for i in range(4):
    box.compartment(f"Slot{i + 1}", width_ratio=0.25)
p.show()
Loading 3-D preview…

⬇ Download STL mesh

add_box(builder: BoxBuilder) → BoxBuilder[source]

Register an already instantiated box builder with the project.

Parameters:
builder: BoxBuilder

The box builder to register.

Returns:

The added builder.

arrange(layout: Node, origin: tuple[float, float, float] | None = None) → Arrangement[source]

Position boxes from a declarative layout tree (T186).

The alternative to hand-typed coordinates for densely packed inserts, where the packer cannot help: describe the structure with columns/rows/stack and let the sizes decide the positions.

A box placed here is placed, so it is neither expanded nor rotated by the packer — the arrangement’s arithmetic assumed the size it was given (FR-013c).

Parameters:
layout: Node

A pyboxbuilder.layout group, or a single box label.

origin: tuple[float, float, float] | None = None

Where the arrangement’s minimum corner goes. Defaults to (0.0, 0.0, board_thickness) when board_on_bottom=True, or (0.0, 0.0, 0.0) otherwise.

Returns:

The Arrangement, so a caller can inspect the resolved extent.

Raises:
  • LayoutError – If the tree names an unknown box or places one twice.

  • ValueError – If a named box has no explicit size, or the arrangement does not fit the game box.

Examples

An arrangement written down instead of measured:

project = Project("BigGame", game_box_size=(300, 200, 80))
project.box(BoxType.SLIDING, "CardBox", size=(110, 75, 50))
project.box(BoxType.CAP, "TokenBox", size=(60, 50, 30))
project.box(BoxType.CAP, "DiceBox", size=(60, 50, 30))
project.box(BoxType.FILAMENT_HINGE, "BitBox", size=(80, 60, 40))
project.arrange(columns(
    "CardBox",
    stack("TokenBox", "DiceBox"),
    "BitBox",
))
project.show()
Loading 3-D preview…

⬇ Download STL mesh

board(label: str, *, size: tuple[float, float, float], position: tuple[float, float, float], count: int = 1, notes: str = '', component: str | GameComponent | None = None, allocates: Mapping[str, int] | Sequence[tuple[str, int]] | None = None) → GameBoard[source]

Register a non-printed game board, rulebook, screen, or playmat region.

Auto-packed boxes and auto-generated spacers avoid this 3-D region, no STL is generated for it, and both the packing guide PDF and Sphinx box summary render and count it explicitly.

box(box_type: BoxType, label: str, *, size: tuple[float, float, float] | None = None, **kwargs: Any) → BoxBuilder[source]

Add a sub-box to the project.

Parameters:
box_type: BoxType

Which lid mechanism the box uses. Selects the builder class, so the type-specific keywords available here follow from it.

label: str

The box’s name; used for file naming and by arrange().

size: tuple[float, float, float] | None = None

(width, length, height) in mm. None derives it from the compartments.

**kwargs: Any

Any field of the box’s builder. Anything not given falls back to box_defaults, then to the field’s own default.

Returns:

The type-specific BoxBuilder, already registered on the project, so compartments and finger holes can be added to it.

Raises:
  • KeyError – If box_type has no registered builder.

  • TypeError – If a keyword is not a field of that builder.

Examples

Add a sliding card box, then preview it on its own:

p = Project("Cards", game_box_size=(300, 300, 80))
p.box(BoxType.SLIDING, "Cards", size=(120, 70, 50))
p.show(only="Cards")
Loading 3-D preview…

⬇ Download STL mesh

build() → Build[source]

Resolve the layout and describe every piece of this project.

The one build path. show() renders what this returns and export() writes it, so a previewed part and a printed part are the same solid — there is no second assembly of the geometry for one of them to fall behind in.

Resolving the layout is eager, because every piece’s size and position depend on every other’s. The geometry is built per piece on first use (Piece.solid), so a caller that only needs some of it — an export skipping the boxes whose description has not changed, a preview of one box — pays for what it asks for.

Returns:

A Build carrying every body, lid and spacer, each with the position it occupies in the game box.

Raises:
  • ValueError – If a box can be sized neither explicitly nor from its compartments, if its compartments overflow its interior, or if its compartment ratios overflow.

  • PackingError – If the boxes cannot be packed into the game box.

card_box(label: str, *, card_size: CardSize | tuple[float, float], count: int | None = None, sleeve: SleeveType = SleeveType.UNSLEEVED, box_type: BoxType = BoxType.SLIDING, cut: Cut | FingerCut | None = FingerCut.THROUGH_FLOOR, **kwargs: Any) → BoxBuilder[source]

Add a box pre-configured for a deck of cards.

component(name: str, count: int, *, category: str = '', notes: str = '', location: str = '', kind: str = 'piece', size: tuple[float, float] | tuple[float, float, float] | None = None, diameter: float | None = None, thickness: float | None = None, svg: str | Path | None = None, bulk: bool = False) → GameComponent[source]

Declare a physical game component type in the project’s piece inventory.

define_cards(name: str, count: int, *, size: tuple[float, float], thickness: float = 0.6, category: str = 'Cards', notes: str = '', svg: str | Path | None = None) → GameComponent[source]

Declare a card deck in the game inventory with exact card count, size, and thickness.

define_inventory(items: Mapping[str, int] | Sequence[GameComponent]) → list[GameComponent][source]

Register the game’s full piece inventory from a {name: count} mapping or sequence.

define_loose(name: str, count: int, *, location: str, size: tuple[float, float] | tuple[float, float, float] | None = None, category: str = 'Loose', notes: str = '') → GameComponent[source]

Declare a loose game item stored outside a dedicated box (e.g. a draw bag in a spacer).

define_piece(name: str, count: int, *, size: tuple[float, float] | tuple[float, float, float] | None = None, diameter: float | None = None, thickness: float | None = None, svg: str | Path | None = None, bulk: bool = False, category: str = 'Pieces', notes: str = '') → GameComponent[source]

Declare a game piece or token type (with optional dimensions and SVG silhouette).

define_tile(name: str, count: int, *, size: tuple[float, float] | tuple[float, float, float] | None = None, diameter: float | None = None, thickness: float | None = None, svg: str | Path | None = None, bulk: bool = False, category: str = 'Tiles', notes: str = '') → GameComponent[source]

Declare a tile type (hex, square, or SVG silhouette) in the game inventory.

export(out_dir: str | Path, fn: int | None = None, fa: float | None = None, fs: float | None = None, only: str | Iterable[str] | None = None, force: bool = False) → ExportResult[source]

Write every piece of this project, and the layout PDF.

Writes exactly what show() renders — the same build() — so the only difference between previewing and exporting is that this one puts the result on disk.

A box whose description has not changed is not rebuilt. The digest that decides whether a file needs writing (FR-031) is known before any geometry is cut, so an unchanged box costs nothing at all rather than being built and then discarded. That is what makes a repeat export at print precision practical: it is the difference between minutes and a second.

Parameters:
out_dir: str | Path

Directory to write into; files land under {out_dir}/{project name}/mmu/ and .../single/.

fn: int | None = None

Fixed facets per circle for every curve in the exported geometry. None (the default) uses EXPORT_FN — an export is what gets printed, so it is built at full precision. Pass a smaller value for a quick throwaway build.

fa: float | None = None

Minimum angle per fragment, in degrees (default 12).

fs: float | None = None

Minimum fragment size, in mm (default 2).

only: str | Iterable[str] | None = None

Export just these box labels. Everything else is left alone on disk — not deleted, not rewritten.

force: bool = False

Rebuild and rewrite every piece, whether its description changed or not.

Returns:

An ExportResult listing the files written and skipped.

Raises:
  • ValueError – If a box cannot be sized, a precision setting is out of range, or only names a box this project does not have.

  • PackingError – If the boxes cannot be packed into the game box.

hex_box(label: str, apothem: float, height: float, *, box_type: BoxType = BoxType.PATH, interlock_type: InterlockType | None = None, interlock_clearance: float = 0.15, interlock_sides: tuple[int | str, ...] | None = None, **kwargs: Any) → BoxBuilder[source]

Add a regular hexagonal box (6 sides) with optional interlocking (FR-102).

hex_tile_box(label: str, *, tile_width: float, count: int, tile_thickness: float = 2.0, box_type: BoxType = BoxType.SLIDING, cut: Cut | FingerCut | None = FingerCut.THROUGH_FLOOR, **kwargs: Any) → BoxBuilder[source]

Add a box with a compartment for a stack of hexagonal tiles.

inventory(*, spacer_count: int | None = None) → ProjectInventory[source]

Return the extracted printed-part, board, and stored-piece inventory.

pack_compartments_across_bins(compartments: list[tuple[str, float, float, float]], bin_sizes: list[tuple[float, float]], wall_spacing: float = 2.0) → list[list[tuple[str, float, float, float]]] | None[source]

Partitions compartments across multiple bin interior footprints using backtracking shelf packing.

polygon_grid(base_label: str, rows: int, cols: int, sides: int, apothem: float, height: float, *, spacing: float = 0.0, box_type: BoxType = BoxType.PATH, interlock_type: InterlockType | None = None, interlock_clearance: float = 0.15, origin: tuple[float, float] = (0.0, 0.0), **kwargs: Any) → list[BoxBuilder][source]

Generate a tessellated 2D grid of regular polygon boxes (FR-102).

Parameters:
base_label: str

Prefix for each box label (e.g. ‘Hex_0_0’).

rows: int

Number of grid rows.

cols: int

Number of grid columns.

sides: int

Number of sides (e.g. 3, 4, 6).

apothem: float

Inscribed radius in mm.

height: float

Total box height in mm.

spacing: float = 0.0

Clearance/spacing between adjacent box faces in mm (0.0 for direct contact).

box_type: BoxType = BoxType.PATH

Box type (defaults to BoxType.PATH).

interlock_type: InterlockType | None = None

Interlock joint mechanism.

interlock_clearance: float = 0.15

Clearance for interlock joints in mm.

origin: tuple[float, float] = (0.0, 0.0)

(X, Y) origin offset in mm.

**kwargs: Any

Extra arguments forwarded to each box builder.

Returns:

List of generated BoxBuilder instances.

preview_pieces(show_lids: bool = False, remove_layers: int = 0, only: str | Iterable[str] | None = None, lids_only: bool = False) → list[PreviewPiece][source]

Build the list of separately-coloured solids show() renders.

Public because it is the cheap way to exercise the geometry: it packs the layout and builds every body, lid and spacer, but writes nothing and needs no render binary. A CI pass wants exactly that — the build path without the printable output — where export() would spend its time tessellating 3MFs no one is going to print.

Parameters:
show_lids: bool = False

Include each box’s lid, lightened and semi-transparent.

remove_layers: int = 0

Number of top layers to omit.

only: str | Iterable[str] | None = None

Restrict to these box labels.

lids_only: bool = False

Leave the bodies out; implies show_lids.

Returns:

A list of pyboxbuilder.preview.PreviewPiece, one per body, lid and spacer — never unioned together.

Raises:

ValueError – If remove_layers is negative, or only names a box this project does not have.

regular_polygon_box(label: str, sides: int, apothem: float, height: float, *, box_type: BoxType = BoxType.PATH, interlock_type: InterlockType | None = None, interlock_clearance: float = 0.15, interlock_sides: tuple[int | str, ...] | None = None, **kwargs: Any) → BoxBuilder[source]

Add a regular polygon footprint box with optional perimeter interlocking (FR-102).

Parameters:
label: str

Identifier for the box.

sides: int

Number of polygon sides (N >= 3).

apothem: float

Inscribed radius in mm (half the flat-to-flat span).

height: float

Total box height in mm.

box_type: BoxType = BoxType.PATH

Box closure type (defaults to BoxType.PATH).

interlock_type: InterlockType | None = None

Perimeter interlocking mechanism (DOVETAIL, MAGNET, CLIP, etc.).

interlock_clearance: float = 0.15

Clearance between mating interlock joints in mm.

interlock_sides: tuple[int | str, ...] | None = None

Specific face indices to equip with interlocks (defaults to all).

**kwargs: Any

Extra fields passed to the box builder.

Returns:

The configured BoxBuilder.

share_compartments(boxes: list[str], compartments: list[tuple[str, float, float, float]]) → None[source]

Register a group of compartments to be dynamically partitioned across the given box labels.

show(show_lids: bool = False, remove_layers: int = 0, only: str | Iterable[str] | None = None, lids_only: bool = False, fn: int | None = None, fa: float | None = None, fs: float | None = None) → None[source]

Preview the packed box layout interactively.

Renders exactly what export() writes — same build, same geometry — as separate solids at their packed positions. Each box is shown as its own solid, because a union carries one colour and would fuse touching boxes into an indivisible blob, hiding the seams a packing preview exists to show.

Writes no files, and generates no layout PDF.

Parameters:
show_lids: bool = False

Place each lid in its seated position as well. Off by default because lids cover the compartments and their neighbours. A shown lid carries its decoration and is drawn semi-transparent in a lighter shade of its box’s colour so it reads as a separate piece.

remove_layers: int = 0

Omit the top N vertical layers of the packed layout, revealing what sits underneath — the live equivalent of the exploded PDF view. A box is removed when its top surface rises above the cut.

only: str | Iterable[str] | None = None

Show just these boxes, by label. One box on its own is the usual way to look at a box you are working on, and it is also the cheap one: nothing else is built.

lids_only: bool = False

Show the lids without their bodies — for looking at a label or a lid pattern, which the body would otherwise sit under. Implies show_lids.

fn: int | None = None

Fixed facets per circle for every curve in the preview. None (the default) defers to fa/fs, which sizes facets by how large each curve actually is — that is what keeps a preview responsive. Unlike export(), this does not jump to export precision.

fa: float | None = None

Minimum angle per fragment, in degrees (default 12).

fs: float | None = None

Minimum fragment size, in mm (default 2).

Raises:

ValueError – If remove_layers is negative, only names a box this project does not have, or a precision setting is out of range.

stack_order(*boxes: BoxBuilder | str, mode: StackableMode = StackableMode.PYRAMIDS, configs: collections.abc.Sequence[int | tuple[int, ...]] | None = None) → list[BoxBuilder][source]

Configure a bottom-to-top sequence of boxes with keyed pyramid configurations.

Ensures the boxes can only be stacked in the specified bottom-to-top order: the bottom box has a flat floor (stackable_bottom=False), each interface between box i’s top lid and box i + 1’s bottom floor receives a distinct pyramid configuration (e.g. 2, 3, (2, 3, 3, 2), (3, 2, 2, 3)), and the top box has a flat lid (stackable_top=False).

Parameters:
*boxes: BoxBuilder | str

Two or more BoxBuilder instances or box label strings, ordered from bottom to top.

mode: StackableMode = StackableMode.PYRAMIDS

Stacking mode to set on each box (defaults to StackableMode.PYRAMIDS).

configs: collections.abc.Sequence[int | tuple[int, ...]] | None = None

Optional explicit sequence of pyramid configurations for each interface.

Returns:

The resolved list of BoxBuilder objects in bottom-to-top order.

token_tray(label: str, *, rows: int = 1, cols: int = 1, scoop_side: ScoopSide = ScoopSide.FRONT, box_type: BoxType = BoxType.FILAMENT_HINGE, **kwargs: Any) → BoxBuilder[source]

Add a tray subdivided into a grid of compartments for tokens, with finger scoops.

verify_inventory(*, strict: bool = True, check_fit: bool = True) → InventoryVerification[source]

Verify that all declared components are accounted for with matching SVGs and physical fit.

base_chamfer : float | bool | None = None

Bottom chamfer in mm, or True for 3.0mm; None defaults to rounded base.

base_rounding : float | None = None

Edge radius for every box’s base/bottom edges.

None derives it per box as wall_thickness. 0 leaves the base edge square.

board_on_bottom : bool = False

Whether the reserved board_thickness space sits at the bottom (z = 0..board_thickness).

board_thickness : float = 0.0

Thickness of the game board (mm).

Reserved at the TOP of the box by default (or at the BOTTOM when board_on_bottom is True), so this region is not filled with auto-generated spacers.

property boards : list[GameBoard]

Registered non-printed game boards, screens, or playmats.

box_defaults : dict[str, Any] | None = None

Defaults applied to every box() call that does not say otherwise.

Every keyword box() accepts may be given here once instead of on each box — wall_thickness, no_rotate, color and the rest. An insert whose boxes all share a wall thickness or all decline rotation says so once (FR-000b):

Project("Earth", ..., box_defaults={"wall_thickness": 3.0})

A value passed to box() always wins over the default.

property boxes : list[BoxBuilder]

Registered sub-box builders.

clearance_slack : float | None = None

Clearance slack on each side of the game box in the X/Y directions (mm).

If None (the default), it auto-scales from 1.0mm to 2.5mm based on the game box size.

property compiler : LayoutCompiler

The underlying LayoutCompiler.

property components : list[GameComponent]

Declared physical game component inventory.

property effective_game_box_size : tuple[float, float, float] | None

Dimensions available for sub-boxes, accounting for board thickness.

floor_thickness : float = 1.6

Default floor thickness.

game_box_size : tuple[float, float, float] | None = None

Outer game box dimensions [W, L, H] in mm. None = standalone boxes (no game box).

gap_threshold : float = 10.0

Gaps <= this are absorbed by adjacent boxes.

generate_spacers : bool = True

Whether to automatically generate spacer boxes/trays to fill layout gaps.

inner_rounding : float | None = None

Edge radius where a partial lid grips the body (FR-044b).

Applies to a cap’s band and skirt cavity, and a slipover’s body and sleeve cavity — both halves of the grip, so they nest. None derives it as half the outer radius.

lid_thickness : float = 2.0

Default lid thickness.

property manifest : ProjectManifest

The underlying ProjectManifest catalog.

max_height_absorb : float = 10.0

Maximum vertical gap (mm) absorbed by growing a top-exposed box instead of adding a small spacer.

min_spacer_dim : float = 15.0

Minimum spacer width/length before absorption.

min_spacer_height : float = 10.0

A spacer tray shorter than this in Z is dropped rather than printed as a thin wafer (FR-014).

name : str

Game name; becomes the output subdirectory.

piece_bounds : tuple[PieceBounds, ...]

Bounding box of every exported piece, populated by export() (FR-027).

property pipeline : GeometryPipeline

The underlying GeometryPipeline.

property resolved_clearance_slack : float

Return the resolved clearance slack, scaling with game box size if None.

ribbon_channels : bool = False

Cut bottom groove for lifting ribbon on all sub-boxes by default.

rounding : float | None = None

Edge radius for every box’s exposed edges (FR-043/FR-044).

None derives it per box as wall_thickness / 2. 0 leaves every edge square.

wall_thickness : float = 2.0

Default wall thickness for all sub-boxes.