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.
Output Previews
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
- Creating a fresh
KiCadSchematicand populatingTitleBlockmetadata - Adding schematic connectivity primitives (
SchWire,SchJunction,SchLabel) - Placing formatted sheet notes with
SchText,Effects, andFont - Saving a native
.kicad_schfile withKiCadSchematic.save() - Lowering to Plotter IR via
schematic_to_ir()and rendering SVG withrender_ir_to_svg()
Run
From the repository root:
uv run python examples/hello_schematic/hello_schematic.pyOutput
examples/hello_schematic/output/hello_schematic.kicad_sch
examples/hello_schematic/output/hello_schematic.svgSource Code
"""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()