On This Page (5)
Examples Showcase / hello_footprint
Hello World: Author an 8-Pin SOIC-8 Footprint & Render SVGs
Author an 8-pin SMD SOIC-8 KiCadFootprint with rounded rectangular pads, silkscreen, courtyard, and fab graphics, save .kicad_mod, and render Paper and Dark SVG previews.
Output Previews
Author a clean 8-pin SMD SOIC-8 KiCadFootprint from scratch with rounded rectangular pads, fabrication outline, courtyard, silkscreen Pin-1 bar, and properties, then save .kicad_mod and render Paper + Dark SVG previews.
What It Shows
- Creating a
KiCadFootprintwithPropertyfields (Reference,Value) - Authoring SMD
Padprimitives withPadType.SMD,PadShape.ROUNDRECT, androundrect_rratio - Adding
F.Fab,F.CrtYd, andF.SilkSgeometry viaFpLineandStroke - Saving
.kicad_modwithKiCadFootprint.save()and rendering Paper + Dark SVGs viaKiCadFootprint.to_svg()
Run
From the repository root:
uv run python examples/hello_footprint/hello_footprint.pyOutput
examples/hello_footprint/output/hello_soic8.kicad_mod
examples/hello_footprint/output/hello_soic8.svg
examples/hello_footprint/output/hello_soic8_dark.svgSource Code
"""Hello World: author an 8-pin SOIC-8 KiCad 10 footprint and render Paper + Dark SVGs."""
from __future__ import annotations
from pathlib import Path
from kicad_monkey import (
Effects,
Font,
FpLine,
KiCadFootprint,
KiCadSvgRenderOptions,
Pad,
Stroke,
)
from kicad_monkey.kicad_pad import PadShape, PadType
from kicad_monkey.kicad_property import Property
HERE = Path(__file__).resolve().parent
OUT_DIR = HERE / "output"
def _rect_lines(x1: float, y1: float, x2: float, y2: float, layer: str, width: float) -> list[FpLine]:
stroke = Stroke(width=width)
edges = [(x1, y1, x2, y1), (x2, y1, x2, y2), (x2, y2, x1, y2), (x1, y2, x1, y1)]
return [FpLine(ax, ay, bx, by, layer=layer, stroke=stroke) for ax, ay, bx, by in edges]
def main() -> None:
OUT_DIR.mkdir(parents=True, exist_ok=True)
# 1. Create an 8-pin SMD SOIC-8 footprint (1.27 mm pitch)
fp = KiCadFootprint()
fp.name = "Hello_SOIC-8_3.9x4.9mm_P1.27mm"
fp.layer = "F.Cu"
fp.descr = "Programmatically authored SOIC-8 example footprint"
fp.tags = "SOIC-8 SMD hello-world"
fp.attr = ["smd"]
fp.properties = [
Property("Reference", "U**", at_x=0.0, at_y=-3.5, layer="F.SilkS", effects=Effects(font=Font(size_x=1.0, size_y=1.0, thickness=0.15))),
Property("Value", "Hello_SOIC-8", at_x=0.0, at_y=3.5, layer="F.Fab", effects=Effects(font=Font(size_x=1.0, size_y=1.0, thickness=0.15))),
]
# 2. Place pads 1..4 on the left, 5..8 on the right
pitch = 1.27
for idx in range(4):
y = -1.5 * pitch + idx * pitch
fp.pads.append(
Pad(
number=str(idx + 1),
pad_type=PadType.SMD,
shape=PadShape.ROUNDRECT,
at_x=-2.475,
at_y=y,
size_x=1.95,
size_y=0.60,
roundrect_rratio=0.25,
layers=["F.Cu", "F.Paste", "F.Mask"],
)
)
for idx in range(4):
y = 1.5 * pitch - idx * pitch
fp.pads.append(
Pad(
number=str(idx + 5),
pad_type=PadType.SMD,
shape=PadShape.ROUNDRECT,
at_x=2.475,
at_y=y,
size_x=1.95,
size_y=0.60,
roundrect_rratio=0.25,
layers=["F.Cu", "F.Paste", "F.Mask"],
)
)
# 3. Add Fab outline, Silkscreen with Pin-1 chamfer/bar, and Courtyard
fp.fp_lines.extend(_rect_lines(-1.95, -2.45, 1.95, 2.45, "F.Fab", 0.10))
fp.fp_lines.extend(_rect_lines(-3.70, -2.75, 3.70, 2.75, "F.CrtYd", 0.05))
fp.fp_lines.extend([
FpLine(-1.30, -2.60, 1.30, -2.60, layer="F.SilkS", stroke=Stroke(width=0.12)),
FpLine(-1.30, 2.60, 1.30, 2.60, layer="F.SilkS", stroke=Stroke(width=0.12)),
# Pin 1 indicator notch on top-left silkscreen
FpLine(-3.45, -2.60, -1.30, -2.60, layer="F.SilkS", stroke=Stroke(width=0.18)),
])
# 4. Save .kicad_mod and render Paper + Dark SVG previews
mod_path = OUT_DIR / "hello_soic8.kicad_mod"
fp.save(mod_path)
paper_svg = fp.to_svg(
black_and_white=False,
options=KiCadSvgRenderOptions(background_color="#FFFFFF"),
)
(OUT_DIR / "hello_soic8.svg").write_text(paper_svg, encoding="utf-8")
dark_svg = fp.to_svg(
fill="#E2E8F0",
stroke="#E2E8F0",
black_and_white=False,
options=KiCadSvgRenderOptions(
background_color="#11161D",
color_overrides={"F.SilkS": "#F8FAFC", "F.Fab": "#94A3B8", "F.CrtYd": "#38BDF8"},
),
)
(OUT_DIR / "hello_soic8_dark.svg").write_text(dark_svg, encoding="utf-8")
print(f"Saved {mod_path.name}: {len(fp.pads)} SMD pads, {len(fp.fp_lines)} graphic lines")
if __name__ == "__main__":
main()