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

Examples Showcase / hello_pcbdoc

Create a PcbDoc hello example

Generate a PcbDoc programmatically, create a rectangular board outline from explicit polygon vertices, place top silkscreen text, and save the board.

pcbdochello-worldgenerationboard-outlinepolygonsilkscreenpcb

Create a PCB document from scratch, place silkscreen text, and author a rectangular board outline from explicit polygon vertices.

This example is intentionally small. It is meant to show the public PcbDoc API, not internal stream assembly.

What It Shows

  1. Creating a rectangular board outline as explicit polygon vertices
  2. AltiumBoardOutline and BoardOutlineVertex
  3. AltiumPcbDoc.set_board_outline(...)
  4. AltiumPcbDoc.set_origin_to_outline_lower_left(...)
  5. AltiumPcbDoc.add_text(..., layer=PcbLayer.TOP_OVERLAY)
  6. AltiumPcbDoc.save(...)

Run

From the repository root:

powershell
uv run python examples\hello_pcbdoc\hello_pcbdoc.py

Output

The script writes:

text
examples/hello_pcbdoc/output/hello_pcbdoc.PcbDoc

Source Code

examples/hello_pcbdoc/hello_pcbdoc.py
from pathlib import Path

from altium_monkey import AltiumBoardOutline, AltiumPcbDoc, BoardOutlineVertex, PcbLayer

SAMPLE_DIR = Path(__file__).resolve().parent
OUTPUT_PATH = SAMPLE_DIR / "output" / "hello_pcbdoc.PcbDoc"

BOARD_WIDTH_MILS = 4000.0
BOARD_HEIGHT_MILS = 2500.0


def make_rectangular_outline_mils(
    width_mils: float,
    height_mils: float,
) -> AltiumBoardOutline:
    """
    Create board-outline vertices with the origin at the lower left.
    """
    return AltiumBoardOutline(
        vertices=[
            BoardOutlineVertex.line(0.0, 0.0),
            BoardOutlineVertex.line(width_mils, 0.0),
            BoardOutlineVertex.line(width_mils, height_mils),
            BoardOutlineVertex.line(0.0, height_mils),
        ]
    )


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

    pcbdoc = AltiumPcbDoc()
    board_outline = make_rectangular_outline_mils(BOARD_WIDTH_MILS, BOARD_HEIGHT_MILS)
    pcbdoc.set_board_outline(board_outline)
    pcbdoc.set_origin_to_outline_lower_left()
    pcbdoc.add_text(
        text="altium-monkey wuz here",
        position_mils=(250.0, 2250.0),
        height_mils=150.0,
        stroke_width_mils=18.0,
        layer=PcbLayer.TOP_OVERLAY,
    )
    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)