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

Examples Showcase / schdoc_extract_template

Extract an embedded SchDoc template to SchDot

Open a schematic with an embedded template, extract the template graphics back to a standalone SchDot, and save the extracted template.

schdocmutationtemplateschdocmutationtemplateschdottitle-blockextract

This example opens an existing schematic with an embedded template, then extracts the template graphics back out to a standalone .SchDot file.

Run from the package root:

powershell
uv run python examples\schdoc_extract_template\schdoc_extract_template.py

The example uses:

The outputs are written to:

text
examples/schdoc_extract_template/output/m2_emmc_extracted_template.SchDot

The important extraction API call is:

python
schdoc = AltiumSchDoc(INPUT_SCHDOC)
schdoc.extract_template(OUTPUT_SCHDOT)

The extracted .SchDot is written as a plain schematic-template document. It does not contain an embedded Template record; the template graphics are top-level records in the .SchDot, which matches the normal file shape used by Altium schematic template files.

Source Code

examples/schdoc_extract_template/schdoc_extract_template.py
from pathlib import Path

from altium_monkey import AltiumSchDoc, AltiumSchParameter


SAMPLE_DIR = Path(__file__).resolve().parent
EXAMPLES_DIR = SAMPLE_DIR.parent
ASSETS_DIR = EXAMPLES_DIR / "assets"
INPUT_SCHDOC = ASSETS_DIR / "projects" / "m2_emmc" / "m2_emmc.SchDoc"
OUTPUT_DIR = SAMPLE_DIR / "output"
OUTPUT_SCHDOT = OUTPUT_DIR / "m2_emmc_extracted_template.SchDot"


def main() -> None:
    OUTPUT_DIR.mkdir(parents=True, exist_ok=True)

    schdoc = AltiumSchDoc(INPUT_SCHDOC)
    source_template = schdoc.get_template()
    extracted_count = schdoc.extract_template(OUTPUT_SCHDOT)

    extracted_template = AltiumSchDoc(OUTPUT_SCHDOT)
    visual_count = len(
        [
            obj
            for obj in extracted_template.all_objects
            if obj is not extracted_template.sheet
            and not isinstance(obj, AltiumSchParameter)
        ]
    )

    print(f"Source SchDoc: {INPUT_SCHDOC.relative_to(EXAMPLES_DIR)}")
    print(
        f"Source template: {source_template.filename if source_template else '<none>'}"
    )
    print(f"Extracted records: {extracted_count}")
    print(f"Extracted visual records: {visual_count}")
    print(
        f"Extracted has Template record: {extracted_template.get_template() is not None}"
    )
    print(f"Wrote SchDot: {OUTPUT_SCHDOT.relative_to(SAMPLE_DIR)}")


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