pyboxbuilder.project.piece.Piece

class pyboxbuilder.project.piece.Piece(label: str, kind: str, size: tuple[float, float, float], position: tuple[float, float, float], _build: collections.abc.Callable[[], Any | None], builder: BoxBuilder | None = None, _build_inserts: collections.abc.Callable[[], list[tuple[Any, Any]]] | None = None, rotation: bool = False)[source]

Bases: object

One printable piece of a project.

Both show() and export() consume these, so a piece previewed and the same piece printed are the same solid.

The geometry is built on demand. Everything that identifies a piece — its label, its size, where it sits, and the description it would be built from — is known without building it, and that is what decides whether an export needs to write it at all (FR-031). Building eagerly meant a re-export with nothing changed still paid for every box: 15 of Emberleaf’s 21 seconds at draft precision, and minutes at the 256 facets an export actually uses, all spent on geometry the fingerprint was about to discard.

builder : BoxBuilder | None = None

The box builder this piece came from; None for a spacer tray.

property inserts : list[tuple[Any, Any]]

The piece’s coloured positive inserts, in its own local frame.

A lid’s label and frame are inserts; a body can carry icons at the bottom of its wells. Each entry is (solid, colour). Empty when the piece has none.

property is_spacer : bool

True when this piece is an auto-generated spacer tray.

kind : str

One of "body", "lid" or "spacer".

label : str

The box label this piece belongs to; a lid keeps its body’s label.

property packed_size : tuple[float, float, float]

Dimensions occupied inside the container frame after any 90° Z rotation.

position : tuple[float, float, float]

Where the piece sits inside the game box, in mm.

rotation : bool = False

True when the packer rotated this piece 90° around Z in the container frame.

size : tuple[float, float, float]

The piece’s declared (width, length, height) in mm.

property solid : Any | None

The built geometry, in the piece’s own local frame.

Built on first use and kept, so asking twice costs once. None when the geometry backend was unavailable.

Typed loosely because pybosl2 ships no py.typed, so a solid is untyped from here on however it is declared.