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

Examples Showcase / schdoc_add_wire_and_net_label

Add wires and net labels to an existing SchDoc

Load a blank schematic, create one detached wire path plus one matching detached net label, add them to the document, and save the modified SchDoc.

schdocmutationschdocmutationwirenet-labelconnectivity

Open a blank schematic, add one wire plus one matching net label, and save the modified .SchDoc.

This example keeps the related connectivity objects together because net labels are normally attached to wires:

  1. load an existing SchDoc
  2. describe the wire path with SchPointMils
  3. call make_sch_wire(...)
  4. call make_sch_net_label(...)
  5. insert every object with AltiumSchDoc.add_object(...)
  6. persist the change with AltiumSchDoc.save(...)

What It Shows

  1. creating a detached wire path with make_sch_wire(...)
  2. creating a detached net label with make_sch_net_label(...)
  3. using SchPointMils for all public connectivity coordinates
  4. using LineWidth for wire thickness
  5. using SchFontSpec, TextOrientation, and TextJustification for label formatting
  6. using ColorValue helpers instead of raw Win32 color integers
  7. reopening the written file and inspecting the created objects

Run

From the project root:

powershell
uv run python examples\schdoc_add_wire_and_net_label\schdoc_add_wire_and_net_label.py

Input

This sample uses:

text
examples/schdoc_add_wire_and_net_label/input/blank.SchDoc

Output

The script writes:

text
examples/schdoc_add_wire_and_net_label/output/blank_with_wires_and_net_labels.SchDoc

Expected Result

The output file should contain:

  1. one visible horizontal wire named CLK_MAIN
  2. one visible net label using TextJustification.BOTTOM_LEFT
  3. the common horizontal, non-mirrored net-label orientation pattern

The script also prints the reopened wire point list plus the net label's text, orientation, justification, and location so the example is easy to sanity-check without inspecting the binary file directly.

Source Code

examples/schdoc_add_wire_and_net_label/schdoc_add_wire_and_net_label.py
from __future__ import annotations

from pathlib import Path

from altium_monkey import (
    AltiumSchDoc,
    ColorValue,
    LineWidth,
    SchFontSpec,
    SchPointMils,
    TextJustification,
    TextOrientation,
    make_sch_net_label,
    make_sch_wire,
)


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


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

    schdoc = AltiumSchDoc(INPUT_SCHDOC)
    schdoc.add_object(
        make_sch_wire(
            points_mils=[
                SchPointMils.from_mils(1500, 6500),
                SchPointMils.from_mils(3600, 6500),
            ],
            color=ColorValue.from_hex("#000080"),
            line_width=LineWidth.SMALL,
        )
    )
    schdoc.add_object(
        make_sch_net_label(
            location_mils=SchPointMils.from_mils(2550, 6500),
            text="CLK_MAIN",
            font=SchFontSpec(name="Arial", size=10),
            color=ColorValue.from_hex("#000080"),
            orientation=TextOrientation.DEGREES_0,
            justification=TextJustification.BOTTOM_LEFT,
            mirrored=False,
        )
    )

    schdoc.save(OUTPUT_SCHDOC)

    reopened = AltiumSchDoc(OUTPUT_SCHDOC)
    print(f"Loaded: {INPUT_SCHDOC.name}")
    print(f"Wires written: {len(reopened.wires)}")
    print(f"Net labels written: {len(reopened.net_labels)}")

    for index, wire in enumerate(reopened.wires, start=1):
        points_text = ", ".join(
            f"({point.x_mils:.0f}, {point.y_mils:.0f})" for point in wire.points_mils
        )
        print(f"Wire {index}: width={wire.line_width.name}, points={points_text}")

    for index, label in enumerate(reopened.net_labels, start=1):
        font = label.font
        font_text = "unresolved"
        if font is not None:
            font_text = f"{font.name} {font.size}"
        print(
            f"Net label {index}: {label.text!r}, "
            f"{label.orientation.name}, "
            f"{label.justification.name}, "
            f"mirrored={label.is_mirrored}, "
            f"font={font_text}, "
            f"location=({label.location_mils.x_mils:.0f}, {label.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)