On This Page (15)
- Usage
- Native Rust CLI Equivalent (k3)
- Positional Arguments
- Options
- How It Works
- Input & Config Discovery
- Overlay Rules & Configuration (pcb.svg.config)
- Component Selector & Style Precedence Ladders
- 1. Assembly Part Rules (Auto-Generated components Entries)
- 2. components Key Matching & Merge Order
- 3. Designator Style Cascade (Highest Wins)
- 4. Projection Mode Precedence (Highest Wins)
- Precedence, Traps & Runtime Guards
- Quick Examples
- Related
kcr pcb-svg
Generate configured A0 KiCad PCB SVG design views and optional layer outputs from .kicad_pcb or .kicad_pro files. The command uses <stem>.pcb.svg.config JSON/JSONC configs and supports geometer-backed assembly HLR overlays.
| Command | Aliases | Category | Runtime | Config | Guide |
|---|---|---|---|---|---|
kcr pcb-svg | — | PCB Visualization & Design Review | Python kcr + Native Rust k3 | <stem>.pcb.svg.config or pcb.svg.config (kicad_cruncher.pcb_svg.config.a0, auto-created with generated components; inherits sibling fab.jsonc in Python kcr) | Rendering & Design Review: kcr pcb-svg |
Usage
kcr pcb-svg [-h] [-o OUTPUT] [--config CONFIG]
[--doc PCBDOC] [--views PCB_VIEWS]
[--layers PCB_LAYERS] [--scale PCB_SVG_SCALE]
[--size-unit PCB_SVG_SIZE_UNIT] [--clean-output]
[--embedded-only] [--cache-dir CACHE_DIR |
--no-cache] [--workers WORKERS] [--no-color]
[file]Native Rust CLI Equivalent (k3)
Implemented natively in k3 on top of kicad-monkey-fab (FabViewData). Both Python kcr pcb-svg and Rust k3 pcb-svg resolve embedded kicad-embed:// STEP models first and fall back to external STEP libraries unless --embedded-only or KCR_EMBEDDED_MODELS_ONLY=1 is set.
k3 pcb-svg [-o OUTPUT] [--config PATH] [--doc BOARD] [--views NAMES] [--layers LAYERS] [--scale SCALE] [--size-unit UNIT] [--clean-output] [--embedded-only] [--workers N] [--cache-dir PATH | --no-cache] [file]Positional Arguments
| Argument | Description |
|---|---|
file | KiCad PCB or project file; optional when one .kicad_pro/.kicad_pcb is in CWD |
Options
| Flag | Description |
|---|---|
-o, --output OUTPUT | Output directory (default: ./output/pcb-svg) |
--config CONFIG | Path to kicad_cruncher.pcb_svg.config.a0 JSON/JSONC config. If omitted, pcb-svg uses <stem>.pcb.svg.config beside each input (the .kicad_pro's stem, or a lone board's own), else the folder's pcb.svg.config, writing <stem>.pcb.svg.config with the board's components when neither exists. |
--doc, --pcbdoc PCBDOC | With .kicad_pro input, select a specific .kicad_pcb by filename, stem, or path |
--views, --pcb-views PCB_VIEWS | Comma-separated view names plus layers, all, or none |
--layers, --pcb-layers PCB_LAYERS | Comma-separated physical PCB layers when layer outputs are enabled |
--scale, --pcb-svg-scale PCB_SVG_SCALE | SVG display scale for A0 outputs (default: config or 10.0) |
--size-unit, --pcb-svg-size-unit PCB_SVG_SIZE_UNIT | SVG width/height unit suffix for A0 outputs |
--clean-output | Request clean output behavior in the resolved config |
--embedded-only | Resolve only kicad-embed:// STEP models; skip external KiCad library paths |
--cache-dir CACHE_DIR | Persistent cache directory (default: .kcr/cache beside the project or board). Mutually exclusive with --no-cache. |
--no-cache | Disable the persistent cache; reuse within this run remains. Mutually exclusive with --cache-dir. |
--workers WORKERS | Geometer worker processes for model HLR projections, 1 to 64 (default: 4); workers start only for projections missing from the cache |
--no-color | Disable ANSI colors and animated spinners |
How It Works
kcr pcb-svg is a declarative PCB SVG compositor that renders physical KiCad layers, board domain layers, Geometer 3D STEP HLR outlines, and translucent 3D illustrations in exact draw order. It also composes all 17 canonical FabView virtual layers (VIRTUAL_CUTOUTS, PIN1_*, DIODES_*, CAPACITORS_*, INDUCTORS_*, RESISTORS_*, ASSEMBLY_OUTLINES_*, ASSEMBLY_DESIGNATORS_*, PAD_LABELS_*) alongside BOARD_SUBSTRATE, SOLDERMASK_FILM_*, BOARD_OUTLINE, BOARD_CUTOUTS, DRILLS, and SLOTS.
Outputs are staged into a temporary sibling directory and published atomically into -o <dir> (default ./output/pcb-svg), with a persistent disk cache (.kcr/cache beside the input) reused across runs and variants.
Input & Config Discovery
- Input resolution:
- Accepts
.kicad_pcbor.kicad_pro(use--doc <board>to pick a board inside a multi-board project). - If omitted, auto-detects a single
*.kicad_proin CWD, falling back to a single*.kicad_pcb.
- Accepts
pcb.svg.configdiscovery order (auto-creates with board-derivedcomponents!):- Explicit
--config <path>— if missing, auto-creates a full commented JSONC config pre-populated with generatedcomponentsentries derived from the board's assembly part rules, then runs with it. <input_dir>/<stem>.pcb.svg.config— per-board/per-project config (so two boards in the same folder keep separate configs).<input_dir>/pcb.svg.config— shared folder fallback.- If neither exists, auto-creates
<input_dir>/<stem>.pcb.svg.configpopulated with the board's generatedcomponentsblock.
- Explicit
- Read-only sibling
fab.jsoncvirtual_layersinheritance (Pythonkcr):- If
<pcb_dir>/fab.jsoncexists, Pythonkcr pcb-svgloads and schema-validates it (kicad_cruncher.fab_config.a0), inherits its"virtual_layers"policy underneath any"virtual_layers"block inpcb.svg.config, and strips Gerber-only family*.enabledtoggles so disabling a Gerber film never blanks an explicitly requested SVG view (per-componentoverrides.<REF>.enabledare preserved). - Native Rust
k3 pcb-svgdoes not inherit siblingfab.jsonc.
- If
Overlay Rules & Configuration (pcb.svg.config)
Schema contract: kicad_cruncher.pcb_svg.config.a0. User configs are overlaid onto the built-in default template (resources/pcb.svg.default.jsonc) with three important merge rules:
- Objects merge key-by-key, while arrays replace completely — defining
"views": [...]in your config replaces the entire 4-view default list (top_assy_view,bottom_assy_view,top_diode_view,bottom_diode_view). stroke_width_mmvsstroke_width_pctoverlay rule: settingstroke_width_mmwithoutstroke_width_pctin an overlay object automatically drops an inheritedstroke_width_pctfrom the base layer. If both are set in the same scope,stroke_width_pctwins.- Python-side schema extensions: the optional top-level
"virtual_layers"block and"pin1.label_orientation"are Python-side extensions honored bykcr pcb-svgbeyond the core TypeSpecpcb_svg.config.a0schema.
{
"schema": "kicad_cruncher.pcb_svg.config.a0",
"global": {
"canvas": {
"bounds": "board_outline", // "board_outline" | "all_geometry"
"margin_mm": 1.0
},
"include_metadata": true, // Emit data-* attributes on SVG elements
"show_empty_layers": false,
"clip_to_outline": true,
"clip_holes_from_copper": true,
"mirror_bottom_view": true, // Mirror bottom views for front-reading orientation
"svg_scale": 10.0,
"svg_size_unit": "", // "" | "mm" | "in" | "mil" | "px"
"clean_output": false,
"styles": {
"board_substrate": { "enabled": true, "color": "#B6A26B", "opacity": 1.0 },
"board_outline": { "enabled": true, "color": "#000000", "line_width_mm": 0.1 },
"board_cutouts": { "enabled": true, "color": "#880000EE", "hatch": true, "outline_style": "dashed" },
"drills": { "enabled": true, "plated_color": "#D0D0D0", "non_plated_color": "#ADD8E6" },
"slots": { "enabled": true, "plated_color": "#D0D0D0", "non_plated_color": "#ADD8E6" },
"soldermask_film": { "enabled": true, "color": "auto", "opacity": 0.75 },
"silkscreen_designators": { "enabled": true, "color": "#000000" },
"pin1_marker": { "enabled": true, "color": "#FF0000BB", "dot_diameter_mm": 0.35 },
"assembly_designators": {
"enabled": true,
"color": "#0094FFA0",
"font_family": "Consolas, 'Liberation Mono', 'Courier New', monospace",
"font_weight": "700",
"box_fill_ratio": 0.8,
"max_font_size_mm": 5.0
},
"assembly_hlr": {
"enabled": true,
"color": "#009EFF",
"line_width_mm": 0.08,
"projection_algorithm": "fast", // "fast" | "poly" | "exact"
"outline_algorithm": "fast-mesh-shadow" // "fast-mesh-shadow" | "mesh-shadow" | "hlr"
},
"illustration": { "enabled": true, "opacity": 0.25, "outline_width_mm": 0.025 }
}
},
"assembly": {
"default_projection": "pad_bounds", // "detail"|"outline"|"bounding_box"|"model_bounds"|"pad_bounds"|"pad_shape"|"none"
"dnp_projection": "bounding_box",
"designator_color": "#0094FFA0",
"dnp_designator_color": "#FF0000"
},
"pin1": {
"exclude_designators": ["R", "C", "L", "F", "FB", "FU", "SW"],
"exclude_single_pin": true
},
// Per-component overrides (auto-populated on first run from assembly part rules)
"components": {
"TP*": { "projection": "pad_shape", "show_designator": true },
"U5-U15": { "projection": "detail" },
"J1": { "projection": "outline", "assembly_designators": { "color": "#CC0000" } }
},
// Standalone per-layer SVG outputs (disabled by default; enable here OR via --views layers)
"layer_outputs": {
"enabled": false,
"layers": "auto",
"include_special_layers": ["BOARD_OUTLINE", "BOARD_CUTOUTS", "DRILLS", "SLOTS"],
"output_dir": "layers"
},
"views": [
{
"name": "top_assy_view",
"enabled": true,
"output_svg": "views/{board}__top_assy_view.svg",
"layers": [
"BOARD_OUTLINE", "BOARD_CUTOUTS", "F.Cu", "DRILLS", "SLOTS",
"F.SilkS", "ASSEMBLY_HLR_TOP", "ILLUSTRATION_TOP",
"ASSEMBLY_DESIGNATORS_TOP", "PIN1_TOP"
],
"assembly_hlr_mode": "outline",
"mirror": false,
"styles": { "silkscreen_designators": { "enabled": false } }
}
]
}Component Selector & Style Precedence Ladders
1. Assembly Part Rules (Auto-Generated components Entries)
When kcr pcb-svg auto-creates a new config, each footprint with a Reference designator is classified by the first matching rule (repeated designators take the first footprint in board file order):
- Has a visible (non-hidden) 3D model -> no entry (projected via Geometer).
- No visible model + draws on
Edge.Cuts->projection: "none", show_designator: false. board_onlyattribute ->projection: "none", show_designator: false.- No pads at all ->
projection: "none", show_designator: false. - Exactly one distinct copper pad number, or NPTH holes only ->
projection: "pad_shape". - Otherwise (multiple copper pad numbers) ->
projection: "pad_bounds".
2. components Key Matching & Merge Order
Keys in "components" fall into two strict categories:
- Exact board designator (case-sensitive): if a key matches any Reference designator present on the board (e.g.
"U1","J1"), it matches only that part and never acts as a prefix wildcard. - Selector (case-insensitive): any other key is parsed as either a prefix (
"TP*"or letters-only"TP") or a numeric range ("U5-U15","U$1-U$9"). A key such as"U99"that does not exist on the board and is not a valid prefix or range selector simply matches nothing and is safely ignored.
Merge order (highest wins):
- Matching selectors in file order (a later matching selector overrides an earlier one).
- Exact board designator key (
components.<REF>).
3. Designator Style Cascade (Highest Wins)
- Component override
components.<REF>.assembly_designators. - Per-view
views[i].styles.assembly_designators. - Global
global.styles.assembly_designators. assembly.designator_color(orassembly.dnp_designator_colorfor DNP parts).
4. Projection Mode Precedence (Highest Wins)
- Fixed-mode layer tokens in
views[i].layers(ASSEMBLY_HLR_*_OUTLINE,ASSEMBLY_HLR_*_DETAIL,ASSEMBLY_BOUNDS_*_MODEL,ASSEMBLY_BOUNDS_*_PADS) — these force that specific projection regardless of view defaults. - Per-component
components.<REF>.projection(resolved via the selector + exact-designator ladder above). - View
views[i].assembly_hlr_mode(for composedASSEMBLY_HLR_TOP/BOTTOMviews) orassembly.default_projection(for standalonelayer_outputs).
Precedence, Traps & Runtime Guards
- The
--viewsvs--layerstrap:- Passing
--layers F.Cu,DIODES_TOPupdateslayer_outputs.layers, but does NOT turnlayer_outputs.enabledon! Becauselayer_outputs.enableddefaults tofalse, you must also pass--views layers(or--views top_assy_view,layers, or setlayer_outputs.enabled: truein config) for per-layer SVGs to be emitted. --views nonedisables all composed views andlayer_outputs;--views allleaves the config's enabled flags untouched.
- Passing
- 3D STEP model resolution (
--embedded-only&KCR_EMBEDDED_MODELS_ONLY=1):- Embedded
kicad-embed://STEP payloads are preferred, with automatic fallback to external STEP libraries; pass--embedded-onlyor setKCR_EMBEDDED_MODELS_ONLY=1for strict self-contained CI builds. See Embedding 3D STEP Models.
- Embedded
- Worker & cache containment guards:
--workers Nis strictly bounded to1..64(default4).--cache-dirand--no-cacheare mutually exclusive. Output and cache paths are checked for unsafe containment so a run never deletes or overwrites its own board, project, config, or cache tree.
Quick Examples
# Render configured top/bottom assembly views
kcr pcb-svg board.kicad_pcb -o output/pcb-svg# Render selected layers including FabView virtual layers (note: --views layers enables layer_outputs)
kcr pcb-svg board.kicad_pcb --layers F.Cu,DIODES_TOP,PAD_LABELS_TOP --views layers -o output/pcb-svg# Enforce strict embedded-only 3D models (portable CI mode)
kcr pcb-svg board.kicad_pcb --embedded-only -o output/pcb-svg# Native Rust binary invocation
k3 pcb-svg board.kicad_pcb -o output/pcb-svg