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

Examples Showcase / pcbdoc_create_rigid_flex_multibranch

Create a multi-branch rigid-flex PcbDoc

Recreate a fixture-derived nested multi-branch rigid-flex PcbDoc, write PcbDoc/.stackup/.stackupx outputs, and verify branch parent linkage after PcbDoc readback.

pcbdocpcbdoclayer-stackgenerationrigid-flexbranch

Create a fixture-derived rigid-flex PcbDoc with multiple branch records.

The generated board recreates a known nested topology with east, west, and west-extension branches. The sample builds the typed AltiumLayerStackDocument from a public JSON spec asset, adds native region, polygon, and track evidence for the extension areas, writes a PcbDoc plus exact AD-exported .stackup and .stackupx reference files, then reads the PcbDoc back and verifies all substacks, board regions, bend lines, parent branches, and branch sections.

What It Shows

  1. Building several rigid and flex substacks from a portable spec
  2. Creating multiple branch records with parent-branch linkage
  3. Assigning bend lines to separate flex regions
  4. Replaying region, polygon, and track evidence for the extension areas
  5. Writing native PcbDoc stack data and embedded StackupX branch data
  6. Re-reading the generated PcbDoc with AltiumLayerStackDocument
  7. Verifying exact .stackup and .stackupx reference output

Run

From the repository root:

powershell
uv run python examples\pcbdoc_create_rigid_flex_multibranch\pcbdoc_create_rigid_flex_multibranch.py

Output

text
examples/pcbdoc_create_rigid_flex_multibranch/output/pcbdoc_create_rigid_flex_multibranch.PcbDoc
examples/pcbdoc_create_rigid_flex_multibranch/output/pcbdoc_create_rigid_flex_multibranch.stackup
examples/pcbdoc_create_rigid_flex_multibranch/output/pcbdoc_create_rigid_flex_multibranch.stackupx
examples/pcbdoc_create_rigid_flex_multibranch/output/rigid_flex_multibranch_manifest.json

Source Code

examples/pcbdoc_create_rigid_flex_multibranch/pcbdoc_create_rigid_flex_multibranch.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_rigid_flex_multibranch_primitives,
    build_rigid_flex_multibranch_document,
    rigid_flex_multibranch_board_outline_mils,
    rigid_flex_multibranch_reference_stackup_path,
    rigid_flex_multibranch_reference_stackupx_path,
    write_case_outputs,
)

OUTPUT_DIR = SAMPLE_DIR / "output"
OUTPUT_PCBDOC = OUTPUT_DIR / "pcbdoc_create_rigid_flex_multibranch.PcbDoc"
OUTPUT_STACKUP = OUTPUT_DIR / "pcbdoc_create_rigid_flex_multibranch.stackup"
OUTPUT_STACKUPX = OUTPUT_DIR / "pcbdoc_create_rigid_flex_multibranch.stackupx"
OUTPUT_MANIFEST = OUTPUT_DIR / "rigid_flex_multibranch_manifest.json"


def build_outputs() -> tuple[Path, Path, Path, Path]:
    outputs = write_case_outputs(
        build_rigid_flex_multibranch_document(),
        pcbdoc_path=OUTPUT_PCBDOC,
        stackup_path=OUTPUT_STACKUP,
        stackupx_path=OUTPUT_STACKUPX,
        manifest_path=OUTPUT_MANIFEST,
        board_outline_mils=rigid_flex_multibranch_board_outline_mils(),
        examples_root=EXAMPLES_ROOT,
        add_primitives=add_rigid_flex_multibranch_primitives,
        reference_stackup_path=rigid_flex_multibranch_reference_stackup_path(),
        reference_stackupx_path=rigid_flex_multibranch_reference_stackupx_path(),
    )
    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"Substacks: {len(readback['substacks'])}")
    print(f"Board regions: {len(readback['regions'])}")
    print(f"Branches: {len(readback['branches'])}")
    print(
        "Branch names: " + ", ".join(branch["name"] for branch in readback["branches"])
    )


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