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.
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
- loading an existing
SchDoc - reading note bounds through
note.bounds_mils - creating a new absolute
SchRectMils - assigning that rectangle back through
note.bounds_mils - saving with
AltiumSchDoc.save(...) - reopening and checking the moved bounds
Run
From the project root:
uv run python examples\schdoc_move_note\schdoc_move_note.pyInput
This sample uses:
examples/schdoc_move_note/input/note_move_input.SchDocOutput
The script writes:
examples/schdoc_move_note/output/note_move_output.SchDocExpected Result
The input note starts at:
(1000, 3000) -> (3000, 4000)mil
The sample sets the note to:
(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
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()