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

Examples Showcase / pcbdoc_create_rigid_flex_two_branch

Create a two-branch rigid-flex PcbDoc

Recreate a fixture-derived advanced rigid-flex PcbDoc with east and west branch roots, write PcbDoc/.stackup/.stackupx outputs, and verify branch topology after PcbDoc readback.

pcbdocpcbdoclayer-stackgenerationrigid-flexbranch

Create a fixture-backed advanced rigid-flex PcbDoc with east and west branch extensions.

This sample uses a neutral public spec derived from an AD-authored two-branch fixture. It writes a recreated PcbDoc with one main rigid stack, east and west flex extensions, east and west rigid end stacks, two branch roots, one board region carrying two bend lines, split-plane polygons, and mechanical split-line evidence. 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 with multiple branch roots
  2. Preserving parent branch linkage and branch-section-stack metadata
  3. Writing native stack data through PcbDocBuilder.set_layer_stack_document(...)
  4. Replaying split-plane polygons and mechanical split-line evidence
  5. Re-reading the generated PcbDoc through AltiumPcbDoc
  6. Verifying branch topology, bend ownership, native geometry, and exact stackup exports

Run

From the repository root:

powershell
uv run python examples\pcbdoc_create_rigid_flex_two_branch\pcbdoc_create_rigid_flex_two_branch.py

Output

text
examples/pcbdoc_create_rigid_flex_two_branch/output/pcbdoc_create_rigid_flex_two_branch.PcbDoc
examples/pcbdoc_create_rigid_flex_two_branch/output/pcbdoc_create_rigid_flex_two_branch.stackup
examples/pcbdoc_create_rigid_flex_two_branch/output/pcbdoc_create_rigid_flex_two_branch.stackupx
examples/pcbdoc_create_rigid_flex_two_branch/output/rigid_flex_two_branch_manifest.json

Source Code

examples/pcbdoc_create_rigid_flex_two_branch/pcbdoc_create_rigid_flex_two_branch.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_two_branch_extensions"
OUTPUT_DIR = SAMPLE_DIR / "output"
OUTPUT_PCBDOC = OUTPUT_DIR / "pcbdoc_create_rigid_flex_two_branch.PcbDoc"
OUTPUT_STACKUP = OUTPUT_DIR / "pcbdoc_create_rigid_flex_two_branch.stackup"
OUTPUT_STACKUPX = OUTPUT_DIR / "pcbdoc_create_rigid_flex_two_branch.stackupx"
OUTPUT_MANIFEST = OUTPUT_DIR / "rigid_flex_two_branch_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("Branches: " + ", ".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)