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

Examples Showcase / schdoc_add_generic_no_erc

Add generic No ERC directives to an existing SchDoc

Load a blank schematic, create detached generic No ERC directives with different native symbols and orientations, add them to the document, and save the modified SchDoc.

schdocmutationschdocmutationdirectiveno-ercorientation

Open a blank schematic, add several detached generic No ERC directives, and save the modified .SchDoc.

This example keeps the public mutation pattern the same as the earlier schematic primitive samples:

  1. load an existing SchDoc
  2. describe each directive location with SchPointMils
  3. call make_sch_no_erc(...)
  4. insert every detached directive with AltiumSchDoc.add_object(...)
  5. persist the change with AltiumSchDoc.save(...)

What It Shows

  1. creating detached generic No ERC directives with make_sch_no_erc(...)
  2. using SchPointMils for public directive coordinates
  3. using the native NoErcSymbol enum instead of raw integers
  4. using the native Rotation90 enum for directive orientation
  5. using ColorValue helpers instead of raw Win32 color integers
  6. carrying the advanced partial-suppression strings through the public factory when suppress_all=False
  7. reopening the written file and inspecting the created directives

Run

From the project root:

powershell
uv run python examples\schdoc_add_generic_no_erc\schdoc_add_generic_no_erc.py

Input

This sample uses:

text
examples/schdoc_add_generic_no_erc/input/blank.SchDoc

Output

The script writes:

text
examples/schdoc_add_generic_no_erc/output/blank_with_no_ercs.SchDoc

Expected Result

The output file should contain:

  1. a top row showing the native No ERC symbol family
  2. a second row showing the same symbol at several Rotation90 orientations
  3. one inactive marker example
  4. one partial-suppression example with suppress_all=False
  5. all directives colored in Altium's native directive red

The script also prints the reopened directive locations, symbols, orientations, and suppression flags so the example is easy to sanity-check without decoding the binary file directly.

Source Code

examples/schdoc_add_generic_no_erc/schdoc_add_generic_no_erc.py
from __future__ import annotations

from pathlib import Path

from altium_monkey import (
    AltiumSchDoc,
    ColorValue,
    NoErcSymbol,
    Rotation90,
    SchPointMils,
    make_sch_no_erc,
)


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


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

    schdoc = AltiumSchDoc(INPUT_SCHDOC)

    # Row 1: native symbol gallery.
    for x_mils, symbol in (
        (1100, NoErcSymbol.CROSS_THIN),
        (2500, NoErcSymbol.CROSS),
        (3900, NoErcSymbol.CROSS_SMALL),
        (5300, NoErcSymbol.CHECKBOX),
        (6700, NoErcSymbol.TRIANGLE),
    ):
        schdoc.add_object(
            make_sch_no_erc(
                location_mils=SchPointMils.from_mils(x_mils, 5600),
                symbol=symbol,
                orientation=Rotation90.DEG_90,
                color=ColorValue.from_hex("#FF0000"),
            )
        )

    # Row 2: orientation gallery with the same native symbol.
    for x_mils, orientation in (
        (1500, Rotation90.DEG_0),
        (3000, Rotation90.DEG_90),
        (4500, Rotation90.DEG_180),
        (6000, Rotation90.DEG_270),
    ):
        schdoc.add_object(
            make_sch_no_erc(
                location_mils=SchPointMils.from_mils(x_mils, 3600),
                symbol=NoErcSymbol.TRIANGLE,
                orientation=orientation,
                color=ColorValue.from_hex("#FF0000"),
            )
        )

    # Row 3: active-state and partial-suppression examples.
    schdoc.add_object(
        make_sch_no_erc(
            location_mils=SchPointMils.from_mils(2200, 1800),
            symbol=NoErcSymbol.CHECKBOX,
            orientation=Rotation90.DEG_180,
            color=ColorValue.from_hex("#FF0000"),
            is_active=False,
        )
    )
    schdoc.add_object(
        make_sch_no_erc(
            location_mils=SchPointMils.from_mils(4600, 1800),
            symbol=NoErcSymbol.CROSS,
            orientation=Rotation90.DEG_90,
            color=ColorValue.from_hex("#FF0000"),
            suppress_all=False,
            error_kind_set_to_suppress="1,2",
            connection_pairs_to_suppress="0,1",
        )
    )

    schdoc.save(OUTPUT_SCHDOC)

    reopened = AltiumSchDoc(OUTPUT_SCHDOC)
    print(f"Loaded: {INPUT_SCHDOC.name}")
    print(f"No ERC directives written: {len(reopened.no_ercs)}")
    for index, marker in enumerate(reopened.no_ercs, start=1):
        point = marker.location_mils
        print(
            "No ERC "
            f"{index}: "
            f"location=({point.x_mils:.0f}, {point.y_mils:.0f}), "
            f"symbol={marker.symbol.name}, "
            f"orientation={marker.orientation.name}, "
            f"is_active={marker.is_active}, "
            f"suppress_all={marker.suppress_all}"
        )
    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)