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.
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:
uv run python examples\schdoc_extract_template\schdoc_extract_template.pyThe example uses:
examples/assets/projects/m2_emmc/m2_emmc.SchDoc
The outputs are written to:
examples/schdoc_extract_template/output/m2_emmc_extracted_template.SchDotThe important extraction API call is:
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
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()