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

Examples Showcase / schdoc_add_bus_and_bus_entry

Add a bus and bus entries to an existing SchDoc

Load a blank schematic, create one detached bus plus several detached bus entries, add them to the document, and save the modified SchDoc.

schdocmutationschdocmutationbusbus-entryconnectivity

Open a blank schematic, add one bus and several bus entries, and save the modified .SchDoc.

This example keeps the related connectivity objects together because bus entries are normally used with a bus:

  1. load an existing SchDoc
  2. describe the bus path with SchPointMils
  3. call make_sch_bus(...)
  4. call make_sch_bus_entry(...) for each entry segment
  5. insert every object with AltiumSchDoc.add_object(...)
  6. persist the change with AltiumSchDoc.save(...)

What It Shows

  1. creating a detached bus path with make_sch_bus(...)
  2. creating detached bus entries with make_sch_bus_entry(...)
  3. using SchPointMils for all public connectivity coordinates
  4. using LineWidth for bus and bus-entry thickness
  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_bus_and_bus_entry\schdoc_add_bus_and_bus_entry.py

Input

This sample uses:

text
examples/schdoc_add_bus_and_bus_entry/input/blank.SchDoc

Output

The script writes:

text
examples/schdoc_add_bus_and_bus_entry/output/blank_with_bus_and_entries.SchDoc

Expected Result

The output file should contain:

  1. one visible bus with a three-point path and LineWidth.LARGE
  2. three visible 100 mil by 100 mil bus entries connected to that bus
  3. all connectivity objects colored #000000

The script also prints the reopened bus point list and the start/end points for each bus entry so the example is easy to sanity-check without inspecting the binary file directly.

Source Code

examples/schdoc_add_bus_and_bus_entry/schdoc_add_bus_and_bus_entry.py
from __future__ import annotations

from pathlib import Path

from altium_monkey import (
    AltiumSchDoc,
    ColorValue,
    LineWidth,
    SchPointMils,
    make_sch_bus,
    make_sch_bus_entry,
)


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


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

    schdoc = AltiumSchDoc(INPUT_SCHDOC)
    schdoc.add_object(
        make_sch_bus(
            points_mils=[
                SchPointMils.from_mils(2600, 1800),
                SchPointMils.from_mils(2600, 6200),
                SchPointMils.from_mils(3200, 6200),
            ],
            color=ColorValue.from_hex("#000000"),
            line_width=LineWidth.LARGE,
        )
    )

    for start, end in (
        (
            SchPointMils.from_mils(2600, 2600),
            SchPointMils.from_mils(2700, 2700),
        ),
        (
            SchPointMils.from_mils(2600, 3600),
            SchPointMils.from_mils(2700, 3700),
        ),
        (
            SchPointMils.from_mils(2600, 4600),
            SchPointMils.from_mils(2700, 4700),
        ),
    ):
        schdoc.add_object(
            make_sch_bus_entry(
                start_mils=start,
                end_mils=end,
                color=ColorValue.from_hex("#000000"),
                line_width=LineWidth.SMALL,
            )
        )

    schdoc.save(OUTPUT_SCHDOC)

    reopened = AltiumSchDoc(OUTPUT_SCHDOC)
    print(f"Loaded: {INPUT_SCHDOC.name}")
    print(f"Buses written: {len(reopened.buses)}")
    print(f"Bus entries written: {len(reopened.bus_entries)}")
    if reopened.buses:
        bus = reopened.buses[0]
        points_text = ", ".join(
            f"({point.x_mils:.0f}, {point.y_mils:.0f})" for point in bus.points_mils
        )
        print(f"Bus line width: {bus.line_width.name}")
        print(f"Bus points mils: {points_text}")
    for index, entry in enumerate(reopened.bus_entries, start=1):
        print(
            f"Entry {index}: "
            f"start=({entry.location_mils.x_mils:.0f}, {entry.location_mils.y_mils:.0f}), "
            f"end=({entry.corner_mils.x_mils:.0f}, {entry.corner_mils.y_mils:.0f}), "
            f"width={entry.line_width.name}"
        )
    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)