kicad monkey v2026.11.30
On This Page (5)

Examples Showcase / hello_schematic

Hello World: Author a KiCad 10 Schematic & Render SVG

Build a KiCad 10 schematic sheet from scratch with a title block, wires, net labels, junction, and banner note, then render an oracle-calibrated SVG through Plotter IR.

schematicsvghello-worldauthoringplotter-irsvg

Output Previews

hello_schematic.svg
Open SVG
Hello World: Author a KiCad 10 Schematic & Render SVG

Author a KiCad 10 .kicad_sch schematic sheet from scratch with a TitleBlock, wires, net labels, a junction dot, and banner text, then render an oracle-calibrated SVG through the Plotter IR pipeline (schematic_to_ir -> render_ir_to_svg).

What It Shows

  1. Creating a fresh KiCadSchematic and populating TitleBlock metadata
  2. Adding schematic connectivity primitives (SchWire, SchJunction, SchLabel)
  3. Placing formatted sheet notes with SchText, Effects, and Font
  4. Saving a native .kicad_sch file with KiCadSchematic.save()
  5. Lowering to Plotter IR via schematic_to_ir() and rendering SVG with render_ir_to_svg()

Run

From the repository root:

sh
uv run python examples/hello_schematic/hello_schematic.py

Output

text
examples/hello_schematic/output/hello_schematic.kicad_sch
examples/hello_schematic/output/hello_schematic.svg

Source Code

examples/hello_schematic/hello_schematic.py
"""Hello World: author a KiCad 10 schematic from scratch and render it to SVG."""

from __future__ import annotations

from pathlib import Path

from kicad_monkey import (
    Effects,
    Font,
    KiCadSchematic,
    SchJunction,
    SchLabel,
    SchWire,
    TitleBlock,
    render_ir_to_svg,
    schematic_to_ir,
)
from kicad_monkey.kicad_sch_text import SchText

HERE = Path(__file__).resolve().parent
OUT_DIR = HERE / "output"


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

    # 1. Create a fresh schematic sheet with title block metadata
    sch = KiCadSchematic()
    sch.title_block = TitleBlock(
        title="Hello KiCad Schematic",
        date="2026-12-01",
        rev="1.0",
        company="kicad-monkey",
    )

    # 2. Add a banner note
    sch.texts.append(
        SchText(
            text="Hello from kicad-monkey!",
            at_x=63.5,
            at_y=45.72,
            effects=Effects(font=Font(size_x=2.54, size_y=2.54, bold=True)),
        )
    )

    # 3. Draw a simple T-junction power & signal wire harness with net labels
    sch.wires.extend([
        SchWire(points=[(63.5, 63.5), (127.0, 63.5)]),
        SchWire(points=[(95.25, 63.5), (95.25, 83.82)]),
        SchWire(points=[(63.5, 96.52), (127.0, 96.52)]),
    ])
    sch.junctions.append(SchJunction(at_x=95.25, at_y=63.5))
    sch.labels.extend([
        SchLabel(text="VCC_3V3", at_x=68.58, at_y=63.5),
        SchLabel(text="MCU_VDD", at_x=114.3, at_y=63.5),
        SchLabel(text="ADC_VREF", at_x=95.25, at_y=83.82),
        SchLabel(text="GND", at_x=68.58, at_y=96.52),
    ])

    # 4. Save .kicad_sch and render through Plotter IR to SVG
    sch_path = OUT_DIR / "hello_schematic.kicad_sch"
    sch.save(sch_path)

    ir_doc = schematic_to_ir(sch, source_path=str(sch_path))
    svg_text = render_ir_to_svg(ir_doc)
    svg_path = OUT_DIR / "hello_schematic.svg"
    svg_path.write_text(svg_text, encoding="utf-8")

    print(
        f"Created {sch_path.name}: {len(sch.wires)} wires, {len(sch.labels)} labels, "
        f"{len(sch.junctions)} junction, {len(ir_doc.records)} Plotter IR records -> {svg_path.name}"
    )


if __name__ == "__main__":
    main()
kicad-monkey v2026.11.30·Docs updated 2026.12.01 15:43 UTC (fd9b75b)