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

Examples Showcase / pcbdoc_create_rigid_flex_split_lines

Create a Rigid-Flex 1.0 split-line PcbDoc

Recreate a fixture-derived Rigid-Flex 1.0 PcbDoc with split-line board regions, write PcbDoc/.stackup/.stackupx outputs, and verify region/bend topology after PcbDoc readback.

pcbdocpcbdoclayer-stackgenerationrigid-flexsplit-lines

Create a fixture-backed Rigid-Flex 1.0 PcbDoc that uses split-line board regions.

This sample writes a recreated AD-style Rigid-Flex 1.0 PcbDoc with one rigid substack, one flex substack, two flex board regions, one rigid board region, split-line evidence, coverlay polygons, and bend lines. It also emits exact AD-exported .stackup and .stackupx reference files, then reads the PcbDoc back with AltiumLayerStackDocument and verifies the authored topology.

What It Shows

  1. Building an AltiumLayerStackDocument for the older Rigid-Flex 1.0 flow
  2. Assigning split-line board regions to rigid and flex substacks
  3. Writing native stack data through PcbDocBuilder.set_layer_stack_document(...)
  4. Replaying coverlay polygon and region evidence into a generated PcbDoc
  5. Re-reading the generated PcbDoc through AltiumPcbDoc
  6. Verifying regions, bends, split-line topology, native geometry, and exact stackup exports

Run

From the repository root:

powershell
uv run python examples\pcbdoc_create_rigid_flex_split_lines\pcbdoc_create_rigid_flex_split_lines.py

Output

text
examples/pcbdoc_create_rigid_flex_split_lines/output/pcbdoc_create_rigid_flex_split_lines.PcbDoc
examples/pcbdoc_create_rigid_flex_split_lines/output/pcbdoc_create_rigid_flex_split_lines.stackup
examples/pcbdoc_create_rigid_flex_split_lines/output/pcbdoc_create_rigid_flex_split_lines.stackupx
examples/pcbdoc_create_rigid_flex_split_lines/output/rigid_flex_split_lines_manifest.json

Source Code

examples/pcbdoc_create_rigid_flex_split_lines/pcbdoc_create_rigid_flex_split_lines.py
from __future__ import annotations

import json
from pathlib import Path
import sys

SAMPLE_DIR = Path(__file__).resolve().parent
EXAMPLES_ROOT = SAMPLE_DIR.parent
sys.path.insert(0, str(EXAMPLES_ROOT))

from _helpers._pcbdoc_rigid_flex_authoring import (  # noqa: E402
    add_recreation_primitives,
    build_recreation_document,
    recreation_board_outline_mils,
    recreation_reference_stackup_path,
    recreation_reference_stackupx_path,
    write_case_outputs,
)

SPEC_NAME = "rigid_flex_split_lines"
OUTPUT_DIR = SAMPLE_DIR / "output"
OUTPUT_PCBDOC = OUTPUT_DIR / "pcbdoc_create_rigid_flex_split_lines.PcbDoc"
OUTPUT_STACKUP = OUTPUT_DIR / "pcbdoc_create_rigid_flex_split_lines.stackup"
OUTPUT_STACKUPX = OUTPUT_DIR / "pcbdoc_create_rigid_flex_split_lines.stackupx"
OUTPUT_MANIFEST = OUTPUT_DIR / "rigid_flex_split_lines_manifest.json"


def build_outputs() -> tuple[Path, Path, Path, Path]:
    outputs = write_case_outputs(
        build_recreation_document(SPEC_NAME),
        pcbdoc_path=OUTPUT_PCBDOC,
        stackup_path=OUTPUT_STACKUP,
        stackupx_path=OUTPUT_STACKUPX,
        manifest_path=OUTPUT_MANIFEST,
        board_outline_mils=recreation_board_outline_mils(SPEC_NAME),
        examples_root=EXAMPLES_ROOT,
        add_primitives=lambda builder: add_recreation_primitives(builder, SPEC_NAME),
        reference_stackup_path=recreation_reference_stackup_path(SPEC_NAME),
        reference_stackupx_path=recreation_reference_stackupx_path(SPEC_NAME),
    )
    return (
        outputs.pcbdoc_path,
        outputs.stackup_path,
        outputs.stackupx_path,
        outputs.manifest_path,
    )


def main() -> None:
    pcbdoc_path, stackup_path, stackupx_path, manifest_path = build_outputs()
    manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
    readback = manifest["pcbdoc_readback"]
    print(f"Wrote {pcbdoc_path}")
    print(f"Wrote {stackup_path}")
    print(f"Wrote {stackupx_path}")
    print(f"Wrote {manifest_path}")
    print(f"Semantic match: {manifest['semantic_match']}")
    print(f"Mode: {readback['rigid_flex_mode']}")
    print(f"Substacks: {len(readback['substacks'])}")
    print(f"Board regions: {len(readback['regions'])}")
    print(f"Branches: {len(readback['branches'])}")
    print(
        "Bend radii: "
        + ", ".join(
            str(radius)
            for region in readback["regions"]
            for radius in region["bend_radii_mils"]
        )
    )


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