On This Page (6)
Examples Showcase / schdoc_add_note
Add a note to an existing SchDoc
Load an existing schematic, create one detached note, add it to the document, and save the modified SchDoc.
Open a blank schematic, append one top-level note, and save the modified .SchDoc.
This is the smallest existing-document mutation example for schematic notes. It is intended to show the canonical public create-then-insert path:
- load an existing
SchDoc - describe note bounds with public coordinate helpers
- call
make_sch_note(...) - insert the object with
AltiumSchDoc.add_object(...) - persist the change with
AltiumSchDoc.save(...)
What It Shows
- describing note bounds with
SchPointMilsandSchRectMils - creating a detached note with
make_sch_note(...) - inserting the note with
add_object(...) - resolving a note font from
SchFontSpecatadd_object(...)time - using
SchHorizontalAligninstead of raw alignment integers - using
ColorValuehelpers instead of raw Win32 color integers - using
save()as the canonical public write path - reopening the written file and checking the inserted note
Run
From the project root:
uv run python examples\schdoc_add_note\schdoc_add_note.pyInput
This sample uses:
examples/schdoc_add_note/input/blank.SchDocOutput
The script writes:
examples/schdoc_add_note/output/blank_with_note.SchDocExpected Result
The output file should contain one visible note with these characteristics:
- text:
a note from altium-monkey - author:
altium-monkey - font:
Arial 10 - border color:
#000000 - fill color:
#CCFFFF - text color:
#000000 - bounds:
(1000, 3000) -> (3000, 4000)mil
The script also prints the public bounds helper, reopened note bounds, font, and IndexInSheet so the example is easy to sanity-check without digging into the binary file.
This example intentionally spells out the current public make_sch_note(...) surface. Font styling is expressed through SchFontSpec instead of raw font_id or direct font-table access. Alignment is expressed as SchHorizontalAlign.LEFT, colors are passed through ColorValue helpers, and the note bounds are built through SchPointMils / SchRectMils instead of anonymous coordinate tuples.
Altium schematic notes do not preserve configurable border thickness on reopen. The native V5 importer forces notes back to the smallest border size, so make_sch_note(...) does not expose a line_width parameter even though the underlying record type inherits rectangle-style fields.
Source Code
from __future__ import annotations
from pathlib import Path
from altium_monkey import (
AltiumSchDoc,
ColorValue,
SchFontSpec,
SchHorizontalAlign,
SchPointMils,
SchRectMils,
make_sch_note,
)
SAMPLE_DIR = Path(__file__).resolve().parent
INPUT_SCHDOC = SAMPLE_DIR / "input" / "blank.SchDoc"
OUTPUT_DIR = SAMPLE_DIR / "output"
OUTPUT_SCHDOC = OUTPUT_DIR / "blank_with_note.SchDoc"
def main() -> None:
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
schdoc = AltiumSchDoc(INPUT_SCHDOC)
note_before = len(schdoc.notes)
note_bounds = SchRectMils.from_points(
SchPointMils.from_mils(1000, 3000),
SchPointMils.from_mils(3000, 4000),
)
note = make_sch_note(
bounds_mils=note_bounds,
text="a note from altium-monkey",
author="altium-monkey",
font=SchFontSpec(name="Arial", size=10),
border_color=ColorValue.from_hex("#000000"),
fill_color=ColorValue.from_hex("#CCFFFF"),
text_color=ColorValue.from_rgb(0, 0, 0),
alignment=SchHorizontalAlign.LEFT,
word_wrap=True,
clip_to_rect=True,
text_margin_mils=5,
collapsed=False,
)
schdoc.add_object(note)
schdoc.save(OUTPUT_SCHDOC)
updated = AltiumSchDoc(OUTPUT_SCHDOC)
inserted_note = updated.notes[-1]
font_info = updated.font_manager.get_font_info(inserted_note.font_id)
print(f"Loaded: {INPUT_SCHDOC.name}")
print(f"Notes before: {note_before}")
print(f"Notes after: {len(updated.notes)}")
print(f"Note author: {inserted_note.author}")
print(f"Note font: {font_info['name']} {font_info['size']}")
print(
"Public bounds helper mils: "
f"({note_bounds.x1_mils:.0f}, {note_bounds.y1_mils:.0f})"
f" -> ({note_bounds.x2_mils:.0f}, {note_bounds.y2_mils:.0f})"
)
print(
"Note bounds mils: "
f"({inserted_note.location.x_mils:.0f}, {inserted_note.location.y_mils:.0f})"
f" -> ({inserted_note.corner.x_mils:.0f}, {inserted_note.corner.y_mils:.0f})"
)
print(f"Note border color: {ColorValue.from_win32(inserted_note.color or 0).hex}")
print(
f"Note fill color: {ColorValue.from_win32(inserted_note.area_color or 0).hex}"
)
print(
f"Note text color: {ColorValue.from_win32(inserted_note.text_color or 0).hex}"
)
print(f"Note IndexInSheet: {inserted_note.index_in_sheet}")
print(f"Wrote: {OUTPUT_SCHDOC.relative_to(SAMPLE_DIR)}")
if __name__ == "__main__":
main()