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

Examples Showcase / schdoc_add_off_sheet_connector

Add an off-sheet connector to an existing SchDoc

Load a blank schematic, create detached left and right off-sheet connectors, add them to the document, and save the modified SchDoc.

schdocmutationschdocmutationoff-sheet-connectorconnectivity

Open a blank schematic, add left and right off-sheet connectors, and save the modified .SchDoc.

This example uses the common built-in off-sheet connector pattern:

  1. load an existing SchDoc
  2. describe connector locations with SchPointMils
  3. call make_sch_off_sheet_connector(...) with OffSheetConnectorStyle.LEFT and OffSheetConnectorStyle.RIGHT
  4. insert the objects with AltiumSchDoc.add_object(...)
  5. persist the change with AltiumSchDoc.save(...)

What It Shows

  1. creating detached off-sheet connectors with make_sch_off_sheet_connector(...)
  2. using SchPointMils for the public placement coordinate
  3. using OffSheetConnectorStyle for the native left/right connector direction
  4. using SchFontSpec and TextOrientation for the visible connector name
  5. using ColorValue helpers instead of raw Win32 color integers
  6. reopening the written file and inspecting the created objects

Run

From the project root:

powershell
uv run python examples\schdoc_add_off_sheet_connector\schdoc_add_off_sheet_connector.py

Input

This sample uses:

text
examples/schdoc_add_off_sheet_connector/input/blank.SchDoc

Output

The script writes:

text
examples/schdoc_add_off_sheet_connector/output/blank_with_off_sheet_connector.SchDoc

Expected Result

The output file should contain:

  1. one visible left-style off-sheet connector named OFF_LEFT
  2. one visible right-style off-sheet connector named OFF_RIGHT
  3. the common horizontal connector orientation
  4. visible text using Arial 10

The script also prints the reopened connector text, style, orientation, font, and location so the example is easy to sanity-check without inspecting the binary file directly.

Source Code

examples/schdoc_add_off_sheet_connector/schdoc_add_off_sheet_connector.py
from __future__ import annotations

from pathlib import Path

from altium_monkey import (
    AltiumSchDoc,
    ColorValue,
    OffSheetConnectorStyle,
    SchFontSpec,
    SchPointMils,
    TextOrientation,
    make_sch_off_sheet_connector,
)


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


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

    schdoc = AltiumSchDoc(INPUT_SCHDOC)
    schdoc.add_object(
        make_sch_off_sheet_connector(
            location_mils=SchPointMils.from_mils(2400, 6200),
            text="OFF_LEFT",
            style=OffSheetConnectorStyle.LEFT,
            font=SchFontSpec(name="Arial", size=10),
            color=ColorValue.from_hex("#800000"),
            orientation=TextOrientation.DEGREES_0,
            show_net_name=True,
        )
    )
    schdoc.add_object(
        make_sch_off_sheet_connector(
            location_mils=SchPointMils.from_mils(2400, 5600),
            text="OFF_RIGHT",
            style=OffSheetConnectorStyle.RIGHT,
            font=SchFontSpec(name="Arial", size=10),
            color=ColorValue.from_hex("#003366"),
            orientation=TextOrientation.DEGREES_0,
            show_net_name=True,
        )
    )

    schdoc.save(OUTPUT_SCHDOC)

    reopened = AltiumSchDoc(OUTPUT_SCHDOC)
    print(f"Loaded: {INPUT_SCHDOC.name}")
    print(f"Off-sheet connectors written: {len(reopened.cross_sheet_connectors)}")
    for index, connector in enumerate(reopened.cross_sheet_connectors, start=1):
        font = connector.font
        font_text = "unresolved"
        if font is not None:
            font_text = f"{font.name} {font.size}"
        style = getattr(connector, "style", None)
        style_text = style.name if hasattr(style, "name") else str(style)
        print(
            f"Connector {index}: {connector.text!r}, "
            f"style={style_text}, "
            f"{connector.orientation.name}, "
            f"show_net_name={connector.show_net_name}, "
            f"font={font_text}, "
            f"location=({connector.location_mils.x_mils:.0f}, {connector.location_mils.y_mils:.0f})"
        )
    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)