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.
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:
- load an existing
.SchDocwithAltiumSchDoc(...) - inspect the current template with
AltiumSchDoc.get_template() - remove the template with
AltiumSchDoc.clear_template() - save the modified schematic with
AltiumSchDoc.save(...)
What It Shows
- removing the
AltiumSchTemplaterecord - removing template-owned graphics, text, and embedded images
- clearing sheet metadata such as
ShowTemplateGraphicsandTemplateFileName - preserving normal schematic content that is not owned by the template
- using a project asset as the input schematic
Run
From the repo root:
uv run python examples\schdoc_clear_template\schdoc_clear_template.pyInput
This sample uses:
examples/assets/projects/bunny_brain/bunny_brain_D.SchDocOutput
The script writes:
examples/schdoc_clear_template/output/bunny_brain_D_without_template.SchDocExpected 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
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()