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

Examples Showcase / schdoc_clear_template

Clear template graphics from an existing SchDoc

Open a schematic with embedded template graphics, remove the template record and template-owned objects, clear sheet template metadata, and save the modified SchDoc.

schdocmutationtemplateschdocmutationtemplatetitle-block

Open an existing schematic that has embedded template graphics, remove the template, and save the cleared schematic.

This example shows the canonical public path for stripping title-block and border content that came from a schematic template:

  1. load an existing .SchDoc with AltiumSchDoc(...)
  2. inspect the current template with AltiumSchDoc.get_template()
  3. remove the template with AltiumSchDoc.clear_template()
  4. save the modified schematic with AltiumSchDoc.save(...)

What It Shows

  1. removing the AltiumSchTemplate record
  2. removing template-owned graphics, text, and embedded images
  3. clearing sheet metadata such as ShowTemplateGraphics and TemplateFileName
  4. preserving normal schematic content that is not owned by the template
  5. using a project asset as the input schematic

Run

From the repo root:

powershell
uv run python examples\schdoc_clear_template\schdoc_clear_template.py

Input

This sample uses:

text
examples/assets/projects/bunny_brain/bunny_brain_D.SchDoc

Output

The script writes:

text
examples/schdoc_clear_template/output/bunny_brain_D_without_template.SchDoc

Expected Result

The output schematic should open without the original template title-block, border, logo, and other template-owned drawing objects. The schematic objects that belong to the design remain in the document.

Source Code

examples/schdoc_clear_template/schdoc_clear_template.py
from pathlib import Path

from altium_monkey import AltiumSchDoc


SAMPLE_DIR = Path(__file__).resolve().parent
EXAMPLES_DIR = SAMPLE_DIR.parent
ASSETS_DIR = EXAMPLES_DIR / "assets"
INPUT_SCHDOC = ASSETS_DIR / "projects" / "bunny_brain" / "bunny_brain_D.SchDoc"
OUTPUT_DIR = SAMPLE_DIR / "output"
OUTPUT_SCHDOC = OUTPUT_DIR / "bunny_brain_D_without_template.SchDoc"


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

    schdoc = AltiumSchDoc(INPUT_SCHDOC)
    template_before = schdoc.get_template()
    removed_count = schdoc.clear_template()
    template_after = schdoc.get_template()

    schdoc.save(OUTPUT_SCHDOC)

    print(
        f"Input template: {template_before.filename if template_before else '<none>'}"
    )
    print(f"Removed template records: {removed_count}")
    print(f"Has template after clear: {template_after is not None}")
    print(f"Show template graphics: {schdoc.sheet.show_template_graphics}")
    print(f"Template file name: {schdoc.sheet.template_filename!r}")
    print(f"Wrote SchDoc: {OUTPUT_SCHDOC.relative_to(SAMPLE_DIR)}")


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