pyboxbuilder.export.exporter.BoxExporter

class pyboxbuilder.export.exporter.BoxExporter(out_dir: str | Path, game: str)[source]

Bases: object

Writes the 3MF tree for one project.

Parameters:
out_dir: str | Path

Root output directory.

game: str

Project name; becomes the subdirectory under out_dir.

delete_stale(prefix: str, keep_labels: set[str]) → list[str][source]

Delete {prefix}* files whose label is no longer generated (T126).

is_current(label: str, part: str, mode: str, fingerprint: str) → bool[source]

Return True when the file on disk was built from this exact description.

Asked before the geometry is built, so an unchanged box costs nothing: the digest covers everything that shapes the piece, and none of it needs the mesh (FR-031).

Parameters:
label: str

Box label.

part: str

“body” or “lid”.

mode: str

“mmu” or “single”.

fingerprint: str

Digest of the description the piece would be built from. Empty always reports stale.

Returns:

Whether the write can be skipped.

note_unchanged(label: str, part: str, mode: str, size: tuple[float, float, float] | None = None) → None[source]

Record a piece that was skipped without being built.

Its bounding box is the declared size rather than a measured one, since measuring would mean building the thing this skipped (FR-027).

Parameters:
label: str

Box label.

part: str

“body” or “lid”.

mode: str

“mmu” or “single”.

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

The piece’s declared size, recorded as its bounds.

path_for(label: str, part: str, mode: str) → Path[source]

Path of one piece. part is “body” or “lid”.

recorded(label: str, part: str, mode: str) → bool[source]

Return True when this piece has some recorded fingerprint.

A piece whose description changed must be rewritten; a piece that has simply never been exported here before (a fresh clone) may fall back to comparing geometry instead.

relative(path: Path) → str[source]

Path as recorded in ExportResult, relative to the output root.

write_box(label: str, body: Bosl2Solid | None = None, lid: Bosl2Solid | None = None, body_inserts: list[Bosl2Solid] | None = None, lid_inserts: list[Bosl2Solid] | None = None, size: tuple[float, float, float] | None = None, has_lid: bool = True) → list[str][source]

Export a box’s body and (optionally) lid in both colour modes.

write_piece(label: str, part: str, mode: str, solid: Bosl2Solid | None = None, inserts: list[Bosl2Solid] | None = None, size: tuple[float, float, float] | None = None, fingerprint: str = '', force: bool = False, geometry_check: bool = True) → str | None[source]

Export one piece, skipping the write when nothing about it changed.

Parameters:
label: str

Box label.

part: str

“body” or “lid”.

mode: str

“mmu” or “single”.

solid: Bosl2Solid | None = None

The main geometry. There must be some: see Raises.

inserts: list[Bosl2Solid] | None = None

Positive coloured inserts. Kept as separate objects in mmu mode and unioned into solid in single mode (T068a).

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

Bounding box to record when it cannot be measured from solid.

fingerprint: str = ''

Digest of the description this piece was built from, recorded beside the file for the next run to compare against.

force: bool = False

Rewrite even when the geometry on disk already matches.

geometry_check: bool = True

Compare the shape (bounding box + volume) against the file already on disk and skip when they agree. Defaults to True so metadata or description changes with invariant geometry do not rewrite 3MF files.

Returns:

The relative path if written, None if skipped.

Raises:
  • RuntimeError – If the piece has no geometry to write, or if the backend accepts it and produces no file.

  • MissingDependencyError – If the geometry backend is not installed.

Note

Whether a write is needed is is_current()’s decision, taken before the geometry is built. This writes what it is given — but it also re-measures the geometry on disk first, so a piece whose bytes changed without its shape changing is not rewritten.