On This Page (6)
Examples Showcase / schematic_svg_themes_and_dnp
Schematic Plotter IR Themes (Color, Dark Blueprint, B&W & DNP)
Lower a DNP schematic once to Plotter IR and render default KiCad color, dark blueprint, print-ready black-and-white, and custom high-contrast DNP review SVGs with IR record statistics.
Output Previews
Lower dnp.kicad_sch once into Plotter IR via schematic_to_ir() and render multiple themed SVGs through render_ir_to_svg(): default KiCad color theme, dark blueprint theme, print-ready black-and-white (SCHEMATIC_SVG_BLACK_AND_WHITE_ROLE_COLORS), and a custom high-contrast DNP review palette — plus Plotter IR primitive statistics.
What It Shows
- Loading a schematic with Do-Not-Populate (
dnp) symbols viaKiCadSchematic.from_file() - Lowering once to
KiCadPlotterDocumentwithschematic_to_ir()and counting IR records by kind - Rendering themed SVGs via
render_ir_to_svg()andKiCadSvgRenderOptions - Customizing semantic color roles with
SCHEMATIC_SVG_ROLE_COLORSandSCHEMATIC_SVG_BLACK_AND_WHITE_ROLE_COLORS
Input
examples/assets/projects/dnp_schematic/dnp.kicad_schRun
From the repository root:
uv run python examples/schematic_svg_themes_and_dnp/schematic_svg_themes_and_dnp.pyOutput
examples/schematic_svg_themes_and_dnp/output/dnp_default_color.svg
examples/schematic_svg_themes_and_dnp/output/dnp_default_color_dark.svg
examples/schematic_svg_themes_and_dnp/output/dnp_black_and_white.svg
examples/schematic_svg_themes_and_dnp/output/dnp_custom_review.svg
examples/schematic_svg_themes_and_dnp/output/schematic_ir_stats.jsonSource Code
"""Render a DNP schematic through Plotter IR across KiCad Color, Monochrome B&W, and Blueprint themes."""
from __future__ import annotations
import json
from collections import Counter
from pathlib import Path
from kicad_monkey import (
SCHEMATIC_SVG_BLACK_AND_WHITE_ROLE_COLORS,
SCHEMATIC_SVG_ROLE_COLORS,
KiCadSchematic,
KiCadSvgRenderOptions,
render_ir_to_svg,
schematic_to_ir,
)
HERE = Path(__file__).resolve().parent
INPUT_SCH = HERE.parent / "assets" / "projects" / "dnp_schematic" / "dnp.kicad_sch"
OUT_DIR = HERE / "output"
def main() -> None:
OUT_DIR.mkdir(parents=True, exist_ok=True)
# 1. Load the DNP schematic and lower once to Plotter IR
sch = KiCadSchematic.from_file(INPUT_SCH)
ir_doc = schematic_to_ir(sch, source_path=str(INPUT_SCH))
# 2. Render default KiCad color theme (Paper)
color_svg = render_ir_to_svg(
ir_doc,
options=KiCadSvgRenderOptions(
background_color="#FFFFFF",
schematic_role_colors=dict(SCHEMATIC_SVG_ROLE_COLORS),
),
)
(OUT_DIR / "dnp_default_color.svg").write_text(color_svg, encoding="utf-8")
# 3. Render dark blueprint theme paired with dnp_default_color.svg
blueprint_roles = {
**SCHEMATIC_SVG_ROLE_COLORS,
"background": "#0F172A",
"foreground": "#E2E8F0",
"wire": "#38BDF8",
"bus": "#60A5FA",
"junction": "#38BDF8",
"component_outline": "#F8FAFC",
"component_body": "#1E293B",
"pin": "#94A3B8",
"pin_name": "#CBD5E1",
"pin_number": "#94A3B8",
"reference": "#FDE047",
"value": "#93C5FD",
"fields": "#FDE047",
"label_local": "#34D399",
"label_global": "#FB923C",
"dnp_marker": "#FB7185",
"worksheet": "#475569",
}
blueprint_svg = render_ir_to_svg(
ir_doc,
options=KiCadSvgRenderOptions(
background_color="#0F172A",
schematic_role_colors=blueprint_roles,
),
)
(OUT_DIR / "dnp_default_color_dark.svg").write_text(blueprint_svg, encoding="utf-8")
# 4. Render print-ready Black-and-White schematic theme
bw_svg = render_ir_to_svg(
ir_doc,
options=KiCadSvgRenderOptions(
black_and_white=True,
background_color="#FFFFFF",
schematic_role_colors=dict(SCHEMATIC_SVG_BLACK_AND_WHITE_ROLE_COLORS),
),
)
(OUT_DIR / "dnp_black_and_white.svg").write_text(bw_svg, encoding="utf-8")
# 5. Render custom high-contrast amber/crimson DNP review theme
review_roles = {
**SCHEMATIC_SVG_ROLE_COLORS,
"wire": "#1D4ED8",
"component_outline": "#0F172A",
"component_body": "#FEF3C7",
"dnp_marker": "#DC2626",
}
review_svg = render_ir_to_svg(
ir_doc,
options=KiCadSvgRenderOptions(
background_color="#FFFDF7",
schematic_role_colors=review_roles,
),
)
(OUT_DIR / "dnp_custom_review.svg").write_text(review_svg, encoding="utf-8")
# 6. Collect Plotter IR record statistics
op_counts = Counter(str(rec.kind) for rec in ir_doc.records)
dnp_refs = [
sym.get_property("Reference") or "?"
for sym in sch.symbols
if getattr(sym, "dnp", False)
]
stats = {
"schematic": INPUT_SCH.name,
"symbol_count": len(sch.symbols),
"dnp_symbols": dnp_refs,
"ir_record_total": len(ir_doc.records),
"ir_records_by_kind": dict(sorted(op_counts.items())),
}
(OUT_DIR / "schematic_ir_stats.json").write_text(json.dumps(stats, indent=2) + "\n", encoding="utf-8")
print(
f"Rendered 4 themed SVGs from {INPUT_SCH.name}: {len(sch.symbols)} symbols "
f"(DNP: {dnp_refs}), {len(ir_doc.records)} Plotter IR records"
)
if __name__ == "__main__":
main()