altium monkey v2026.11.26 · gobblerito
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.

schdocmutationschdocmutationnoteblank-template

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:

  1. load an existing SchDoc
  2. describe note bounds with public coordinate helpers
  3. call make_sch_note(...)
  4. insert the object with AltiumSchDoc.add_object(...)
  5. persist the change with AltiumSchDoc.save(...)

What It Shows

  1. describing note bounds with SchPointMils and SchRectMils
  2. creating a detached note with make_sch_note(...)
  3. inserting the note with add_object(...)
  4. resolving a note font from SchFontSpec at add_object(...) time
  5. using SchHorizontalAlign instead of raw alignment integers
  6. using ColorValue helpers instead of raw Win32 color integers
  7. using save() as the canonical public write path
  8. reopening the written file and checking the inserted note

Run

From the project root:

powershell
uv run python examples\schdoc_add_note\schdoc_add_note.py

Input

This sample uses:

text
examples/schdoc_add_note/input/blank.SchDoc

Output

The script writes:

text
examples/schdoc_add_note/output/blank_with_note.SchDoc

Expected Result

The output file should contain one visible note with these characteristics:

  1. text: a note from altium-monkey
  2. author: altium-monkey
  3. font: Arial 10
  4. border color: #000000
  5. fill color: #CCFFFF
  6. text color: #000000
  7. 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

examples/schdoc_add_note/schdoc_add_note.py
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()
altium-monkey v2026.11.26 · gobblerito·Docs updated 2026.11.29 17:55 UTC (0665053)