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

Examples Showcase / schdoc_move_note

Move an existing note in a SchDoc

Open a schematic with one note, move it through the public bounds helper, and save the modified SchDoc.

schdocmutationschdocmutationnotegeometrymove

Open an existing schematic that already contains one note, set that note to a new absolute rectangle, and save the modified .SchDoc.

This example is a focused geometry-mutation probe. It shows how to set an existing object's absolute position without touching internal Altium coordinate units.

What It Shows

  1. loading an existing SchDoc
  2. reading note bounds through note.bounds_mils
  3. creating a new absolute SchRectMils
  4. assigning that rectangle back through note.bounds_mils
  5. saving with AltiumSchDoc.save(...)
  6. reopening and checking the moved bounds

Run

From the project root:

powershell
uv run python examples\schdoc_move_note\schdoc_move_note.py

Input

This sample uses:

text
examples/schdoc_move_note/input/note_move_input.SchDoc

Output

The script writes:

text
examples/schdoc_move_note/output/note_move_output.SchDoc

Expected Result

The input note starts at:

  1. (1000, 3000) -> (3000, 4000) mil

The sample sets the note to:

  1. (2500, 2500) -> (4500, 3500) mil

This example uses the public structured geometry helpers instead of raw internal 10-mil document units. location_mils exists for single-point placement, while bounds_mils is the more natural fit for note/text-frame style records.

Source Code

examples/schdoc_move_note/schdoc_move_note.py
from __future__ import annotations

from pathlib import Path

from altium_monkey import AltiumSchDoc, SchRectMils


SAMPLE_DIR = Path(__file__).resolve().parent
INPUT_SCHDOC = SAMPLE_DIR / "input" / "note_move_input.SchDoc"
OUTPUT_DIR = SAMPLE_DIR / "output"
OUTPUT_SCHDOC = OUTPUT_DIR / "note_move_output.SchDoc"

TARGET_BOUNDS_MILS = SchRectMils.from_corners_mils(2500, 2500, 4500, 3500)


def _format_bounds(bounds) -> str:
    return (
        f"({bounds.x1_mils:.0f}, {bounds.y1_mils:.0f})"
        f" -> ({bounds.x2_mils:.0f}, {bounds.y2_mils:.0f})"
    )


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

    schdoc = AltiumSchDoc(INPUT_SCHDOC)
    if len(schdoc.notes) != 1:
        raise RuntimeError(
            f"Expected exactly one input note, found {len(schdoc.notes)}"
        )

    note = schdoc.notes[0]
    before_bounds = note.bounds_mils
    note.bounds_mils = TARGET_BOUNDS_MILS

    schdoc.save(OUTPUT_SCHDOC)

    reopened = AltiumSchDoc(OUTPUT_SCHDOC)
    moved_note = reopened.notes[0]

    print(f"Loaded: {INPUT_SCHDOC.name}")
    print(f"Bounds before: {_format_bounds(before_bounds)}")
    print(f"Bounds target: {_format_bounds(TARGET_BOUNDS_MILS)}")
    print(f"Bounds after: {_format_bounds(moved_note.bounds_mils)}")
    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)