altium monkey v2026.11.26 · gobblerito
On This Page (4)

Examples Showcase / pcbdoc_add_free_3d_step

Add a free embedded STEP 3D body to a PcbDoc

Create a PcbDoc, embed a STEP model from disk, infer its projection, and add it as a free board-level 3D body.

pcbdoc3dpcbdoc3dcomponent-bodyembedded-modelstepgeneration

Open an existing blank PcbDoc, embed a STEP model from disk, and add it as a free board-level 3D body. The PcbDoc API mirrors the PcbLib embedded-model workflow.

What It Shows

  1. AltiumPcbDoc.add_embedded_model(...)
  2. Native checksum generation for the embedded STEP payload
  3. AltiumPcbDoc.add_embedded_3d_model(...)
  4. Automatic STEP projection and height inference through wn-geometer
  5. Saving the modified board through pcbdoc.save(...)

Run

From the repository root:

powershell
uv run python examples\pcbdoc_add_free_3d_step\pcbdoc_add_free_3d_step.py

Output

text
examples/pcbdoc_add_free_3d_step/output/pcbdoc_add_free_3d_step.PcbDoc

Source Code

examples/pcbdoc_add_free_3d_step/pcbdoc_add_free_3d_step.py
from pathlib import Path

from altium_monkey import AltiumPcbDoc, PcbBodyProjection, PcbLayer

SAMPLE_DIR = Path(__file__).resolve().parent
EXAMPLES_ROOT = SAMPLE_DIR.parent
INPUT_PCBDOC = EXAMPLES_ROOT / "assets" / "pcbdoc" / "blank.PcbDoc"
STEP_MODEL_PATH = EXAMPLES_ROOT / "assets" / "3d" / "RESC1608X06N.step"
OUTPUT_PATH = SAMPLE_DIR / "output" / "pcbdoc_add_free_3d_step.PcbDoc"


def build_pcbdoc(output_path: Path = OUTPUT_PATH) -> Path:
    output_path.parent.mkdir(parents=True, exist_ok=True)

    pcbdoc = AltiumPcbDoc.from_file(INPUT_PCBDOC)

    step_model = pcbdoc.add_embedded_model(
        name=STEP_MODEL_PATH.name,
        model_data=STEP_MODEL_PATH.read_bytes(),
    )
    pcbdoc.add_embedded_3d_model(
        step_model,
        layer=PcbLayer.MECHANICAL_13,
        side=PcbBodyProjection.TOP,
        location_mils=(4000.0, 3000.0),
        rotation_z_degrees=0.0,
        name="FREE_STEP_RESISTOR",
    )

    pcbdoc.save(output_path)
    return output_path


def main() -> None:
    output_path = build_pcbdoc()
    print(f"Wrote {output_path}")


if __name__ == "__main__":
    main()
altium-monkey v2026.11.26 · gobblerito·Docs updated 2026.11.29 17:55 UTC (0665053)