kicad monkey v2026.11.30
On This Page (26)

Virtual Fab Layers (All 17 Layers)

Board-derived virtual layers synthesize fabrication and assembly review artwork on demand from a normalized KiCadFabView — board cutouts, Pin 1 and polarity markers, diode polarity glyphs, passive component symbols (capacitors, inductors, resistors), assembly outlines with optional DNP crossout, fitted assembly designators, and fitted pad designator labels — without mutating your source .kicad_pcb unless you explicitly bake them with vdoc.

Because every virtual layer is computed once from KiCadFabView answers (profile(), components(), holes(), and outer copper layers), the exact same geometry is shared consistently across:

virtual_composite.svg
Open SVG
Composite virtual fab layers rendered on the 34-component KiCad 10 showcase board

Composite kcr pcb-svg view of the real virtual_fab_layers.kicad_pcb KiCad 10 showcase board (92.71 × 56.39 mm, 34 footprints, 24 embedded 3D STEP models, 7 interior cutouts) combining BOARD_OUTLINE, VIRTUAL_CUTOUTS, F.Cu, DRILLS, SLOTS, F.SilkS, ASSEMBLY_HLR_TOP (3D STEP HLR), ILLUSTRATION_TOP (translucent 3D models), ASSEMBLY_DESIGNATORS_TOP, PIN1_TOP, DIODES_TOP, CAPACITORS_TOP, INDUCTORS_TOP, and RESISTORS_TOP. Use Paper (pcb-svg palette) or Dark (karashi-yellow designators) on any card, or click to pan, zoom, and copy.

Supported Virtual Layer Keys

All 17 canonical virtual layer keys — plus convenience aliases POLARITY_TOP / POLARITY_BOTTOM and PIN_1_TOP / PIN_1_BOTTOM for PIN1_TOP / PIN1_BOTTOM — are case-insensitive everywhere:

Virtual Layer KeyDisplay NameRoleSideGerber ExtDefault vdoc LayerSVG Colour
CUTOUTSBoard Cutoutscutoutsboard.GCUUser.1#D71920
PIN1_TOPTop Pin 1 Markerspin1top.GP1TUser.2#1479CC
PIN1_BOTTOMBottom Pin 1 Markerspin1bottom.GP1BUser.3#1479CC
DIODES_TOPTop Diode Orientationdiodestop.GDTUser.4#E67E22
DIODES_BOTTOMBottom Diode Orientationdiodesbottom.GDBUser.5#E67E22
CAPACITORS_TOPTop Capacitorscapacitorstop.GCTUser.4#0D9488
CAPACITORS_BOTTOMBottom Capacitorscapacitorsbottom.GCBUser.5#0D9488
INDUCTORS_TOPTop Inductorsinductorstop.GLTUser.4#7C3AED
INDUCTORS_BOTTOMBottom Inductorsinductorsbottom.GLBUser.5#7C3AED
RESISTORS_TOPTop Resistorsresistorstop.GRTUser.4#059669
RESISTORS_BOTTOMBottom Resistorsresistorsbottom.GRBUser.5#059669
ASSEMBLY_OUTLINES_TOPTop Component Outlinesassembly_drawingtop.GATF.Fab (User.6 in user_only)#1F2937
ASSEMBLY_OUTLINES_BOTTOMBottom Component Outlinesassembly_drawingbottom.GABB.Fab (User.7 in user_only)#1F2937
ASSEMBLY_DESIGNATORS_TOPTop Component Designatorsassembly_drawingtop.GADTF.Fab (User.6/User.8 in fab_outlines/user_only)#111827
ASSEMBLY_DESIGNATORS_BOTTOMBottom Component Designatorsassembly_drawingbottom.GADBB.Fab (User.7/User.9 in fab_outlines/user_only)#111827
PAD_LABELS_TOPTop Pad Labelspad_labelstop.GPLTEco1.User#C2410C
PAD_LABELS_BOTTOMBottom Pad Labelspad_labelsbottom.GPLBEco2.User#C2410C

Cross-Format Lowering Behavior

Quick Start Across Outputs

python
from kicad_monkey import KiCadPcb
from kicad_monkey.fab import (
    AssemblyDesignatorLayerOptions,
    AssemblyOutlineLayerOptions,
    CapacitorLayerOptions,
    ComponentVisibilityPolicy,
    CutoutLayerOptions,
    DiodeLayerOptions,
    InductorLayerOptions,
    PadLabelLayerOptions,
    Pin1LayerOptions,
    ResistorLayerOptions,
    VirtualLayerOptions,
)

pcb = KiCadPcb.from_file("virtual_fab_layers.kicad_pcb")
fab = pcb.fab()

virtual_opts = VirtualLayerOptions(
    font_mode="stroke",
    stroke_font="sans_serif",
    dnp_mode="crossout",
    visibility=ComponentVisibilityPolicy(
        exclude_kinds=("graphical", "net_tie"),
    ),
    cutouts=CutoutLayerOptions(scope="interior", hatch=True, hatch_pitch_mm=1.0),
    pin1=Pin1LayerOptions(
        style="dot",
        knockout=False,
        exclude_designator_prefixes=("R", "C", "L", "F", "FB", "FU", "SW"),
        diode_ak_labels=True,
        cap_polarity_labels=True,
        inductor_polarity_markers=True,
    ),
    diodes=DiodeLayerOptions(color_mode="shaded"),
    capacitors=CapacitorLayerOptions(visibility_mode="polarized_only", color_mode="shaded"),
    inductors=InductorLayerOptions(visibility_mode="polarized_only", color_mode="shaded"),
    resistors=ResistorLayerOptions(style="zigzag", color_mode="shaded"),
    assembly_outlines=AssemblyOutlineLayerOptions(detail="simple"),
    assembly_designators=AssemblyDesignatorLayerOptions(
        min_font_size_mm=0.08,
        max_font_size_mm=2.40,
        fill_ratio=0.78,
    ),
    pad_labels=PadLabelLayerOptions(orientation="pad", knockout=False),
)

# 1. Gerber X2 + virtual layers + hatched cutout callouts on .GM1
gerbers = fab.to_gerbers(
    virtual_layers=(
        "CUTOUTS",
        "POLARITY_TOP",  # alias for PIN1_TOP
        "DIODES_TOP",
        "CAPACITORS_TOP",
        "INDUCTORS_TOP",
        "RESISTORS_TOP",
        "ASSEMBLY_OUTLINES_TOP",
        "ASSEMBLY_DESIGNATORS_TOP",
        "PAD_LABELS_TOP",
    ),
    profile_cutouts=True,
    virtual_options=virtual_opts,
)

# 2. IPC-2581B with virtual DOCUMENT / ASSEMBLY layers
ipc = fab.to_ipc2581(
    virtual_layers=("CUTOUTS", "PIN1_TOP", "DIODES_TOP", "ASSEMBLY_OUTLINES_TOP"),
    virtual_options=virtual_opts,
)

# 3. Composite SVG with shaded virtual overlays
svg = fab.to_svg(
    layers=(
        "PROFILE",
        "TOP",
        "DRILLS",
        "ASSEMBLY_OUTLINES_TOP",
        "ASSEMBLY_DESIGNATORS_TOP",
        "PIN1_TOP",
        "DIODES_TOP",
        "CAPACITORS_TOP",
        "INDUCTORS_TOP",
        "RESISTORS_TOP",
        "CUTOUTS",
    ),
    virtual_options=virtual_opts,
)

VirtualLayerOptions Reference

All virtual-layer option, override, visibility, style, and baking types are exported directly from kicad_monkey.fab:

python
from kicad_monkey.fab import (
    AssemblyDesignatorLayerOptions,
    AssemblyHlrCache,
    AssemblyOutlineLayerOptions,
    AssemblyOutlineOverride,
    BakeLayerReport,
    BakeVirtualLayersOptions,
    BakeVirtualLayersReport,
    CapacitorLayerOptions,
    CapacitorOverride,
    ComponentVisibilityOverride,
    ComponentVisibilityPolicy,
    CutoutLayerOptions,
    DiodeLayerOptions,
    DiodeOverride,
    InductorLayerOptions,
    InductorOverride,
    PadLabelLayerOptions,
    Pin1LayerOptions,
    Pin1Override,
    ResistorLayerOptions,
    ResistorOverride,
    UserLayerCollision,
    VirtualItemStyle,
    VirtualLayerOptions,
    VirtualLayerResult,
    bake_virtual_layers_to_pcb,
    clear_baked_virtual_layers,
    detect_user_layer_collisions,
)

Top-Level VirtualLayerOptions

FieldTypeDefaultMeaning
font_mode"stroke" | "truetype""stroke"Vector text renderer shared by cutout labels, Pin 1 / polarity pad labels, assembly designators, and pad labels. "stroke" uses built-in vector stroke glyphs; "truetype" outlines TrueType glyphs as filled polygons (falling back to "stroke" if the font face is unavailable).
stroke_font"sans_serif" | "serif" | "default""sans_serif"Vector stroke font family when font_mode="stroke".
font_familystr"Arial"TrueType font family when font_mode="truetype".
font_boldboolTrueBold weight flag when font_mode="truetype".
dnp_mode"omit" | "crossout""omit"How DNP / unfitted components ((attr ... dnp) or variant-excluded) render across component-scoped virtual layers. "omit" hides DNP parts on all 8 component-scoped families. "crossout" draws DNP parts on ASSEMBLY_OUTLINES_* as a dimmed dashed outline with a muted-red diagonal X and a dimmed label on ASSEMBLY_DESIGNATORS_*, while keeping them omitted from PIN1_*, DIODES_*, CAPACITORS_*, INDUCTORS_*, RESISTORS_*, and PAD_LABELS_*.
visibilityComponentVisibilityPolicy(defaults)Unified inclusion/exclusion rules across all 8 component-scoped families.
cutoutsCutoutLayerOptions(defaults)Board cutout scope, hatching, label text, and .GM1 profile overlay toggle.
pin1Pin1LayerOptions(defaults)Pin 1 & polarity marker style (dot/square/pad/pin_label), geometric knockout, exclude_single_pin, exclude_two_pin_prefixes, diode A/K, capacitor +/-, inductor polarity dots, and overrides.
diodesDiodeLayerOptions(defaults)Diode polarity parameters, heuristics, visibility_mode, SVG shading mode, and overrides.
capacitorsCapacitorLayerOptions(defaults)Capacitor polarity parameters, visibility_mode, + sign, SVG shading mode, and overrides.
inductorsInductorLayerOptions(defaults)Inductor polarity parameters, visibility_mode, SVG shading mode, and overrides.
resistorsResistorLayerOptions(defaults)Resistor glyph style ("zigzag" or "box"), visibility_mode, SVG shading mode, and overrides.
assembly_outlinesAssemblyOutlineLayerOptions(defaults)Assembly outline detail level ("simple", "detail", "bounding_box"), stroke widths, DNP crossout width, and overrides.
assembly_designatorsAssemblyDesignatorLayerOptions(defaults)Fitted assembly designator sizing (min_font_size_mm, max_font_size_mm, fill_ratio) and overrides.
pad_labelsPadLabelLayerOptions(defaults)Fitted pad designator labels (PAD_LABELS_TOP / PAD_LABELS_BOTTOM) with orientation policy, geometric knockout, mechanical/THT filters, and overrides.
hlr_cacheAssemblyHlrCache | NoneNoneOptional persistent cache hook for 3D STEP HLR projections.
progressCallable[[str], None] | NoneNoneOptional progress callback for long-running 3D projections.

Component Visibility Policy (ComponentVisibilityPolicy) & Resolution Precedence

Every component-scoped virtual layer family — all 8 families (assembly_outlines, assembly_designators, pin1, pad_labels, diodes, capacitors, inductors, resistors) — separates Semantics (what a part is and how it draws) from Visibility (whether to draw its symbol) through one uniform, strictly one-way pipeline:

FieldTypeDefaultMeaning
exclude_kindstuple[str, ...]("graphical", "net_tie")Component kinds excluded by default.
exclude_designator_prefixestuple[str, ...]()Alphabetic reference prefixes excluded across all 8 families (case-insensitive).
outline_parameterstr"ASSEMBLY_OUTLINE"Footprint property controlling ASSEMBLY_OUTLINES_* (boolean tokens or "simple"/"detail"/"bounding_box").
designator_parameterstr"ASSEMBLY_DESIGNATOR"Footprint property controlling ASSEMBLY_DESIGNATORS_*.
pin1_parameterstr"PIN1_MARKER"Footprint property controlling PIN1_*.
pad_labels_parameterstr"PAD_LABELS"Footprint property controlling PAD_LABELS_*.
diode_parameterstr"DIODE_SYMBOL"Footprint property controlling DIODES_*.
capacitor_parameterstr"CAPACITOR_SYMBOL"Footprint property controlling CAPACITORS_*.
inductor_parameterstr"INDUCTOR_SYMBOL"Footprint property controlling INDUCTORS_*.
resistor_parameterstr"RESISTOR_SYMBOL"Footprint property controlling RESISTORS_*.
overridesMapping[str, ComponentVisibilityOverride]{}Shared per-component visibility matrix keyed by reference designator.
excluded_designatorsfrozenset[str]frozenset()Variant/DNP designators suppressed unconditionally at Gate 1.

Uniform resolution order (highest → lowest):

  1. Gate 0 — Layer active: Layer enabled for the current export/command.
  2. Gate 1 — Fitted / DNP (always wins): Unfitted/DNP footprints (not comp.fitted or in excluded_designators) are hidden across all 8 families when dnp_mode="omit"; when dnp_mode="crossout", they appear only on ASSEMBLY_OUTLINES_* (dimmed dashed outline + red X) and ASSEMBLY_DESIGNATORS_* (dimmed text).
  3. P1 — Family config override: virtual_layers.<family>.overrides.<REF>.enabled (true / false).
  4. P2 — Shared visibility matrix override: virtual_layers.visibility.overrides.<REF>.<family> (true / false).
  5. P3 — Dedicated KiCad footprint property: ASSEMBLY_OUTLINE, ASSEMBLY_DESIGNATOR, PIN1_MARKER, PAD_LABELS, DIODE_SYMBOL, CAPACITOR_SYMBOL, INDUCTOR_SYMBOL, or RESISTOR_SYMBOL. Recognized true tokens: 1, true, yes, on, show, include, enable, enabled. Recognized false tokens: 0, false, no, off, none, hide, exclude, disable, disabled. A recognized property bypasses P4 exclusions and P5 visibility_mode (for example, setting CAPACITOR_SYMBOL="true" on a ceramic MLCC draws it even under "polarized_only").
  6. P4 — Global exclusions: exclude_kinds and exclude_designator_prefixes.
  7. P5 — Family visibility_mode policy:
    • Polarity-capable families (capacitors, inductors): "polarized_only" (default), "all", or "explicit". Legacy include_non_polarized remains accepted when visibility_mode is None.
    • All other 6 families: "all" (default) or "explicit".

Shared fab.jsonc Inheritance Across CLI Commands

Define "virtual_layers" once in fab.jsonc beside your board or project:

jsonc
{
  "schema": "kicad_cruncher.fab_config.a0",
  "virtual_layers": {
    "font": { "mode": "stroke", "stroke_font": "sans_serif" },
    "dnp": { "mode": "crossout" },
    "visibility": {
      "exclude_kinds": ["graphical", "net_tie"],
      "overrides": {
        "J4": { "assembly_outline": false, "assembly_designator": false }
      }
    },
    "capacitors": { "visibility_mode": "polarized_only" },
    "resistors": {
      "visibility_mode": "all",
      "overrides": { "R2": { "style": "box" } }
    },
    "pad_labels": { "orientation": "pad", "knockout": false }
  }
}

Sibling Python kcr vdoc (vdoc.jsonc), kcr pcb-svg, and kcr toon automatically inherit fab.jsonc's "virtual_layers" block read-only and merge any tool-local overrides cleanly on top. (See Python vs Native Rust Parity and Python API vs fab.jsonc Defaults below.)


Board Cutouts (CUTOUTS, CutoutLayerOptions & profile_cutouts)

Renders interior (or all) Edge.Cuts board cutouts with arc-preserving outlines, automatic boolean unioning of overlapping or crossing cutouts (so intersecting slots never produce doubled borders or overlapping hatches), clipped parallel vector hatch lines, and an automatically fitted "CUTOUT" label with a cleared hatch window. Supports rectangles, circles, concave L/T/U/C shapes, and narrow slots.

virtual_cutouts.svg
Open SVG
Board Cutouts virtual layer on the KiCad showcase board

CUTOUTS on virtual_fab_layers.kicad_pcb: 7 real interior Edge.Cuts cutouts — rectangular opening, composite opening with circular feature, and narrow vertical/horizontal slots including intersecting slots automatically boolean-unioned into one seamless + cutout — with 45° clipped hatching and cleared "CUTOUT" callout windows.

FieldTypeDefaultMeaning
scope"interior" | "all""interior""interior" selects cutouts strictly inside the outer board boundary; "all" includes every cutout in view.profile().cutouts.
hatchboolTrueDraw clipped parallel vector hatch lines across each cutout.
hatch_angle_degfloat45.0Hatch angle in degrees.
hatch_pitch_mmfloat1.0Spacing between adjacent hatch lines in mm (clamped to >= 0.1 mm).
labelstr"CUTOUT"Text fitted inside each cutout ("" omits label and hatch window).
on_profileboolFalseWhen True (or to_gerbers(profile_cutouts=True)), draws hatched cutout callouts directly onto the .GM1 profile Gerber.
outline_width_mmfloat0.10Cutout outline stroke width in mm.
hatch_line_width_mmfloat0.075Hatch line stroke width in mm.
label_max_font_size_mmfloat4.0Maximum fitted height in mm for cutout labels.
label_fill_ratiofloat0.72Fraction of available cutout span filled by the fitted label.
label_rotation_min_gainfloat0.25Minimum height gain before rotating the label along a slot's principal axis.
color_mode"shaded" | "monochrome""shaded"SVG rendering mode.

Pin 1 & Polarity Markers (PIN1_TOP / PIN1_BOTTOM, Aliases POLARITY_TOP / POLARITY_BOTTOM)

Marks Pin 1 and terminal polarity across all fitted components on a board side, unifying IC/connector Pin 1 markers, diode A/K labels, polarized capacitor +/- labels, explicit POSITIVE_PAD/NEGATIVE_PAD callouts, and polarized inductor markers onto one consistent layer.

virtual_pin1.svg
Open SVG
Pin 1 and polarity virtual layer rendered on the KiCad showcase board

PIN1_TOP (style="dot") on virtual_fab_layers.kicad_pcb: SOT-23 U1, 45°-rotated LQFP-64 U2, 64-ball BGA U3 (A1 grid pad fill), USB-C/SMA/header/Tag-Connect connectors J1–J7, polarized inductor L2, polarized capacitors C1/C2 (+/-), and diodes/LEDs D1, D2, D4, D5, D7–D11 (A/K), while non-polarized MLCC C3, resistor R1, fiducials FID1–FID4, and single-pin test points TP1–TP3 stay cleanly unmarked.

Four Pin 1 Styles & Pure Geometric knockout=True

virtual_pin1_style_dot.svg
Open SVG
Pin 1 style="dot" close-up on 45-degree LQFP-64 U2

style="dot" (default) — auto-scaled circular Pin 1 dot on 45°-rotated LQFP-64 U2.

virtual_pin1_style_square.svg
Open SVG
Pin 1 style="square" close-up on 45-degree LQFP-64 U2

style="square" — pad-rotated square marker aligned to the 45° Pin 1 lead on U2.

virtual_pin1_style_pad.svg
Open SVG
Pin 1 style="pad" close-up on 45-degree LQFP-64 U2

style="pad" — fills the exact copper Pin 1 pad geometry on U2.

virtual_pin1_style_pin_label.svg
Open SVG
Pin 1 style="pin_label" close-up on 45-degree LQFP-64 U2

style="pin_label" — fits vector pin number (1) inside the rotated Pin 1 pad on U2.

virtual_pin1_knockout.svg
Open SVG
Pin 1 pure geometric knockout=True close-up on 45-degree TVS D8 and diodes D10, D11, D9

style="pin_label", knockout=True — pure boolean subtraction on 45°-rotated TVS D8 and diodes D10–D9 (A/K), preserving interior counter islands inside A.

FieldTypeDefaultMeaning
style"dot" | "square" | "pad" | "pin_label""dot"Default Pin 1 marker style.
knockoutboolFalsePunch glyphs out of the copper pad polygon as pure negative GeomPlanarRegion geometry.
grid_pad_fillboolTrueFill the full pad land for BGA/LGA grid pads (A1, …) in "dot" / "square" modes.
dot_diameter_mmfloat | NoneNoneExplicit dot diameter in mm; None auto-scales to 0.70 × min_pad_dim clamped to [min_dot_diameter_mm, max_dot_diameter_mm].
min_dot_diameter_mmfloat0.40Lower clamp for auto-scaled dot diameter in mm.
max_dot_diameter_mmfloat0.90Upper clamp for auto-scaled dot diameter in mm.
pad_parameterstr"PIN1_PAD"Footprint property naming the Pin 1 pad (or "NONE"/"FALSE" to suppress).
positive_parameterstr"POSITIVE_PAD"Footprint property naming explicit + pad(s).
negative_parameterstr"NEGATIVE_PAD"Footprint property naming explicit - pad(s).
exclude_designator_prefixestuple[str, ...]("R", "C", "L", "F", "FB", "FU", "SW")Prefixes skipped by generic Pin 1 auto-detection (bypassed by explicit properties or polarized passives).
exclude_single_pinboolTrueSkip 1-pad components (such as fiducials, test points, and mounting holes) during generic Pin 1 auto-detection unless explicitly opted in.
exclude_two_pin_prefixestuple[str, ...]("X", "Y")Prefixes skipped when the component has exactly 2 copper pads (keeps 2-pin crystals clean while still marking 4-pin oscillators).
diode_ak_labelsboolTrueDraw A/K inside anode and cathode pads for detected diodes.
cap_polarity_labelsboolTrueDraw +/- inside positive and negative pads for polarized capacitors.
inductor_polarity_markersboolTrueDraw Pin 1 marker on winding-start pad of polarized inductors.
label_orientation"pad" | "orthogonal" | "upright""pad"Orientation for A/K, +/-, pin_label, and custom symbol labels ("pad" aligns oblique components/pads along their upright angle in (-90°, +90] while keeping 0°/90° parts upright; "orthogonal" and "upright" keep polarity labels horizontal).
visibility_mode"all" | "explicit""all"Auto-detect eligible parts or draw P1–P3 opt-ins only.
color_mode"shaded" | "monochrome""shaded"SVG rendering mode.
overridesMapping[str, Pin1Override]{}Per-component Pin1Override(enabled, pad, style, knockout, symbol, positive_pad, negative_pad).

Diode Orientation (DIODES_TOP / DIODES_BOTTOM)

Draws graphical-only polarity glyphs strictly inside the clear gap between anode and cathode pads: axis shaft, filled triangle pointing anode → cathode, subtype-specific cathode bar (straight for normal/LED, slim opened S-bar for Schottky, angled Z-bar for Zener and unidirectional TVS), and LED emission rays. Multi-pin parts without explicit CATHODE_PAD/ANODE_PAD (like multi-pad RGB LEDs D3 and D6) are never given a misleading 2-pin diode glyph, while explicit POSITIVE_PAD properties still render + on PIN1_TOP.

virtual_diodes.svg
Open SVG
Diode Orientation virtual layer rendered on the KiCad showcase board

DIODES_TOP paired with PIN1_TOP: colour-coded 0603 LEDs (D1 yellow, D2 red, D4 blue, D5 green), 45°-rotated SMB TVS D8 (SMBJ100A), Schottky D10 (1N5819HW-7-F), Zener D11 (BZT52C5V6-7-F), standard rectifier D9 (1N4148W-13-F), and 3-pin SOT-23 D7 (BAL99-7 via DiodeOverride(anode_pad="1", cathode_pad="3")), while multi-pad RGB LED D6 stays free of misleading 2-pin diode glyphs.

FieldTypeDefaultMeaning
cathode_parameterstr"CATHODE_PAD"Footprint property naming cathode pad(s) (comma-separated supported); "none"/"false" suppresses.
anode_parameterstr"ANODE_PAD"Optional property naming anode pad(s).
type_parameterstr"DIODE_TYPE"Optional subtype: "normal", "led", "schottky", "zener", or "tvs".
color_parameterstr"DIODE_COLOR"Optional colour (#RRGGBB or named colour) for shaded SVG output.
default_cathode_padstr"2"Fallback cathode pad for 2-pin diodes with numeric pads "1"/"2".
cathode_pad_namestuple[str, ...]("K", "C", "CATHODE", "CAT", "-")Pad names recognized automatically as cathodes.
designator_prefixestuple[str, ...]("D", "LED")Reference prefixes matched during 2-terminal auto-detection.
keywordstuple[str, ...]("diode", "led", "schottky", "tvs", "zener", "1n")Word-boundary keywords scanned across value, description, footprint, and properties.
visibility_mode"all" | "explicit""all"Auto-detect or P1–P3 opt-ins only.
color_mode"shaded" | "monochrome""shaded"SVG paint mode (subtype/LED fills with contrast halo).
overridesMapping[str, DiodeOverride]{}Per-component DiodeOverride(enabled, cathode_pad, anode_pad, diode_type, color).

Passive Component Layers (CAPACITORS_*, INDUCTORS_*, RESISTORS_*)

Three dedicated passive virtual layers render schematic-grade symbols scaled cleanly from pad center to pad center:

virtual_passives.svg
Open SVG
Capacitors, Inductors, and Resistors virtual layers on the KiCad showcase board

CAPACITORS_TOP, INDUCTORS_TOP, and RESISTORS_TOP (visibility_mode="all"): polarized tantalum C1 (10µF) and aluminum electrolytic C2 (100µF, flat positive plate, curved negative plate, + sign), MLCC ceramic C3 (1µF, parallel plates), power inductors L1 (non-polarized) and L2 (polarized 4-lobe coil with pin 1 start dot), and 45°-rotated IEEE zig-zag resistor R1 (10kΩ).

virtual_resistors_box.svg
Open SVG
IEC rectangular box resistor style on 45-degree R1

RESISTORS_TOP configured with style="box" (IEC rectangular resistor glyph aligned along 45°-rotated R1).

CapacitorLayerOptions (CAPACITORS_TOP / CAPACITORS_BOTTOM, .GCT / .GCB)

FieldTypeDefaultMeaning
positive_parameterstr"POSITIVE_PAD"Footprint property naming the positive pad.
negative_parameterstr"NEGATIVE_PAD"Footprint property naming the negative pad.
type_parameterstr"CAPACITOR_TYPE"Optional type ("polarized", "tantalum", "electrolytic", "non_polarized", "mlcc", "none").
color_parameterstr"CAPACITOR_COLOR"Optional SVG accent colour.
default_positive_padstr"1"Fallback positive pad for numeric "1"/"2" polarized caps.
visibility_mode"all" | "polarized_only" | "explicit" | NoneNone (effective "polarized_only")Visibility policy ("polarized_only" default, "all" draws MLCC/film too, "explicit" draws P1–P3 opt-ins only).
include_non_polarizedboolFalseLegacy bridge when visibility_mode is None.
show_plus_signboolTrueDraw + on the positive side of polarized capacitors.
color_mode"shaded" | "monochrome""shaded"SVG paint mode (default teal #0D9488).
designator_prefixestuple[str, ...]("C",)Reference prefixes for auto-detection.
keywordstuple[str, ...]("capacitor", "tantalum", "tant", "electrolytic", "elec", "supercap", "polymer")Polarity/type keywords.
overridesMapping[str, CapacitorOverride]{}Per-component CapacitorOverride(enabled, positive_pad, negative_pad, polarized, color).

InductorLayerOptions (INDUCTORS_TOP / INDUCTORS_BOTTOM, .GLT / .GLB)

FieldTypeDefaultMeaning
polarity_parameterstr"INDUCTOR_POLARITY_PAD"Primary property naming the winding-start pad.
pin1_fallback_parameterstr"PIN1_PAD"Secondary fallback property when INDUCTOR_POLARITY_PAD is absent.
type_parameterstr"INDUCTOR_TYPE"Optional type ("polarized", "coupled", "dot", "start", "non_polarized", "none").
color_parameterstr"INDUCTOR_COLOR"Optional SVG accent colour.
visibility_mode"all" | "polarized_only" | "explicit" | NoneNone (effective "polarized_only")Visibility policy ("polarized_only" default).
include_non_polarizedboolFalseLegacy bridge when visibility_mode is None.
color_mode"shaded" | "monochrome""shaded"SVG paint mode (default violet #7C3AED).
designator_prefixestuple[str, ...]("L", "FB", "IND")Reference prefixes for auto-detection.
keywordstuple[str, ...]("inductor", "choke", "ferrite", "coil")Keywords scanned during auto-detection.
overridesMapping[str, InductorOverride]{}Per-component InductorOverride(enabled, polarity_pad, polarized, color).

ResistorLayerOptions (RESISTORS_TOP / RESISTORS_BOTTOM, .GRT / .GRB)

FieldTypeDefaultMeaning
style"zigzag" | "box""zigzag"Default glyph style ("zigzag" IEEE 6-peak or "box" IEC rectangle).
style_parameterstr"RESISTOR_STYLE"Per-component footprint property overriding "zigzag" vs "box".
color_parameterstr"RESISTOR_COLOR"Optional SVG accent colour (default emerald #059669).
color_mode"shaded" | "monochrome""shaded"SVG paint mode.
designator_prefixestuple[str, ...]("R",)Reference prefixes for auto-detection.
keywordstuple[str, ...]("resistor", "shunt", "thermistor", "ntc", "ptc", "varistor")Keywords scanned during auto-detection.
visibility_mode"all" | "explicit""all"Auto-detect or P1–P3 opt-ins only.
overridesMapping[str, ResistorOverride]{}Per-component ResistorOverride(enabled, style, color).

Assembly Outlines & Designators (ASSEMBLY_OUTLINES_* & ASSEMBLY_DESIGNATORS_*)

Synthesizes crisp assembly drawings from each footprint's 3D STEP HLR projection (supporting bottom-side mirroring and non-unit scale), falling back cleanly to single-pad outlines (for fiducials and test points) or pad envelopes (and F.Fab/B.Fab in Rust kicad-monkey-fab), then fits each component's reference designator cleanly inside its outline using cutout-aware multi-center placement (preferring horizontal 0° on ties and upright +90° top / -90° bottom on vertical parts; oblique component angles such as 45° keep square-ish parts horizontal at 0° unless their aspect ratio long / short meets oblique_min_aspect_ratio, default 1.2).

important

3D STEP Model Resolution & Portable Embedding (kicad-embed://) kcr toon, kcr pcb-svg, kcr fab, kcr vdoc, and Python KiCadFabView prefer embedded kicad-embed://... STEP/STP payloads first and automatically fall back to external .step/.stp files (plus .wrl → .step/.stp siblings) resolved via KiCad kicad_common.json path variables and process environment variables. Footprints without a resolved STEP model fall back cleanly to single-pad or pad-envelope outlines.

  • Inspect preferences: kcr kicad prefs lists resolved ${KICAD*_3DMODEL_DIR} and user 3D model paths.
  • Strict CI / portable mode: pass --embedded-only (or set KCR_EMBEDDED_MODELS_ONLY=1) to ignore external libraries, and run kcr health project.kicad_pro --require-embedded --fail-on-issues to audit portability.
  • Embed models natively (KiCad 10.0.8 format): run kcr pcb embed-models board.kicad_pcb --apply --backup (with optional --refs / --update-project-library), or use EmbeddedFile.from_kicad_bytes(...) in Python — see Embedding 3D STEP Models.
virtual_assembly.svg
Open SVG
Assembly Outlines and Assembly Designators rendered from 24 embedded 3D STEP models

ASSEMBLY_OUTLINES_TOP and ASSEMBLY_DESIGNATORS_TOP on virtual_fab_layers.kicad_pcb: 24 embedded kicad-embed:// 3D STEP models projected via Geometer HLR (USB-C J2–J4, right-angle SMA J5, 45°-rotated LQFP-64 U2 with horizontal 0° designator, 64-ball BGA U3, 45° TVS D8 and R1 with rotated designators) plus clean single-pad outlines on FID1–FID4 and TP2–TP3 and pad-envelope outlines on J6–J7.

AssemblyOutlineLayerOptions

FieldTypeDefaultMeaning
detail"simple" | "detail" | "bounding_box""simple"Default outline detail level ("simple" outer silhouette, "detail" internal creases/features, "bounding_box" instant pad extent).
stroke_width_mmfloat0.12Stroke width in mm for simple and bounding_box outlines.
detail_stroke_width_mmfloat0.08Stroke width in mm for detail internal linework.
dnp_crossout_stroke_width_mmfloat | NoneNoneStroke width in mm for DNP X lines (None auto-scales to body size).
visibility_mode"all" | "explicit""all"Auto-draw or P1–P3 opt-ins only.
overridesMapping[str, AssemblyOutlineOverride]{}Per-component AssemblyOutlineOverride(enabled, detail).

AssemblyDesignatorLayerOptions

FieldTypeDefaultMeaning
min_font_size_mmfloat0.08Minimum fitted height in mm; smaller labels are omitted.
max_font_size_mmfloat2.40Maximum fitted height in mm.
fill_ratiofloat0.78Fraction of available outline box filled by the designator.
oblique_min_aspect_ratiofloat1.2Minimum component body aspect ratio (long / short) required before an oblique component (e.g. 45°) rotates its designator off horizontal/orthogonal (1.0 always rotates along the component axis).
visibility_mode"all" | "explicit""all"Auto-draw or P1–P3 opt-ins only.
overridesMapping[str, bool]{}Per-component visibility overrides (True/False).

Pad Designator Labels (PAD_LABELS_TOP / PAD_LABELS_BOTTOM, .GPLT / .GPLB)

Fits each copper pad's pin number/name (1, A1, +, K, …) inside its pad land using either vector stroke glyphs or outlined TrueType glyphs, with optional pure geometric knockout=True (boolean subtraction preserving counter islands inside A, B, D, 0, 6, 8) and three orientation policies.

virtual_pad_labels.svg
Open SVG
Pad Designator Labels full-board overview on the KiCad showcase board

Full-board overview — PAD_LABELS_TOP (font_mode="stroke", orientation="pad").

virtual_pad_labels_knockout.svg
Open SVG
Pad Designator Labels knockout=True close-up on 64-ball BGA U3

Close-up — knockout=True across 64-ball BGA U3, punching A1..H8 out of the copper pads as pure planar polygons while preserving interior counter islands inside A, B, D, 0, 6, 8.

Pad Label Orientation Modes (pad vs orthogonal vs upright)

virtual_pad_labels_orient_pad.svg
Open SVG
Pad Label orientation="pad" on 45-degree LQFP-64 U2

orientation="pad" (default) — aligns each label along its pad's exact long axis (±45° on rotated LQFP-64 U2 leads).

virtual_pad_labels_orient_orthogonal.svg
Open SVG
Pad Label orientation="orthogonal" on 45-degree LQFP-64 U2

orientation="orthogonal" — snaps elongated pad labels strictly to 0° or 90°.

virtual_pad_labels_orient_upright.svg
Open SVG
Pad Label orientation="upright" on 45-degree LQFP-64 U2

orientation="upright" — keeps every label strictly horizontal (0°), scaling to fit both pad width and height.

FieldTypeDefaultMeaning
font_mode"stroke" | "truetype""stroke"Text renderer override for pad labels.
stroke_font"sans_serif" | "serif" | "default""sans_serif"Stroke font when font_mode="stroke".
font_familystr"Arial"TrueType font family when font_mode="truetype".
font_boldboolTrueBold weight flag when font_mode="truetype".
orientation"pad" | "orthogonal" | "upright""pad"Label orientation policy.
knockoutboolFalsePunch pad labels out of copper pad polygons via boolean difference.
fill_ratiofloat0.70Fraction of available pad extent filled by the label.
min_height_nmfloat60_000.0 (0.06 mm)Minimum fitted height in nm (min_height_mm in JSONC configs).
max_height_nmfloat2_000_000.0 (2.0 mm)Maximum fitted height in nm (max_height_mm in JSONC configs).
stroke_width_ratiofloat0.14Stroke thickness as a fraction of label height in "stroke" mode.
skip_empty_designatorsboolTrueSkip pads with empty pin numbers.
skip_mechanical_padsboolFalseSkip mechanical/shield pads (MH*, MP*, MTG*, SH*, TAB*, etc.).
include_through_holeboolTrueInclude through-hole pads as well as SMD pads.
visibilityComponentVisibilityPolicy | NoneNoneOptional per-layer visibility policy overriding top-level VirtualLayerOptions.visibility.
visibility_mode"all" | "explicit""all"Auto-label or P1–P3 opt-ins only.
color_mode"shaded" | "monochrome""shaded"SVG rendering mode (default #C2410C).
overridesMapping[str, bool]{}Per-component visibility overrides (True/False).

Placement, Sizing & Orientation Algorithms

Every virtual layer in Python kicad_monkey.fab computes its geometry deterministically in the canonical FabView coordinate space (whole nanometres, +Y up; KiCad board coordinates convert via y_kicad = -y_fab / 1e6) so Gerber X2/X1, IPC-2581B, kcr vdoc, kcr pcb-svg, and kcr toon share one placement truth. Bottom-side text layers (ASSEMBLY_DESIGNATORS_BOTTOM, PAD_LABELS_BOTTOM, and PIN1_BOTTOM pad labels) emit horizontally mirrored strokes (mirror_x=True) so labels read left-to-right when viewed from the bottom of the board.

1. Assembly Outlines (ASSEMBLY_OUTLINES_*) & DNP Crossout

2. Assembly Designator Placement (ASSEMBLY_DESIGNATORS_*)

  1. Annotation region derivation:
    • Polygonizes straight HLR outline strokes and unions them; if disconnected polygons result, selects the largest-area polygon (falling back to the convex hull of outline vertices if strokes are open or arc-only).
    • When no STEP/body outline exists, uses the single-pad shape (1-pad parts) or the oriented convex hull of the component's copper pads (pad_envelope), preserving true aspect ratio on rotated footprints.
    • Cutout subtraction: Interior board cutouts from view.profile() are subtracted (taking the largest surviving polygon) so designators never sit over routed holes or slots.
    • Wall inset: Insets the region by min(0.06 mm, 8% × min_dim) so text strokes never collide with the outline perimeter.
  2. Multi-center candidate search & binary sizing:
    • Evaluates a deterministic candidate set inside the inset region: region centroid, pole of inaccessibility (polylabel), interior representative point, bounding-box center, per-part centers (if insetting splits the region into multiple parts), and an interior 3 × 3 grid.
    • For each candidate center and allowed angle, runs a 14-step binary search for the largest inscribed text rectangle matching the string's measured glyph aspect ratio (measure_text_aspect), multiplies by fill_ratio (default 0.78), and clamps to [min_font_size_mm, max_font_size_mm] (default [0.08, 2.40] mm).
  3. Orientation & oblique (45°) rotation rule:
    • Orthogonal components (0°, 90°, 180°, 270°): Evaluates horizontal (0°) and vertical (+90° on top side; -90° on bottom side so bottom-side labels also read bottom-to-top after bottom-view X mirroring). When heights tie within 1 µm (e.g. square QFNs or large ICs capped at max_font_size_mm), 0° horizontal wins.
    • Oblique components (e.g. 45°, 135°, 30°): Projects the annotation region onto the component's local axes to measure aspect_ratio = long_side / short_side.
      • If aspect_ratio < oblique_min_aspect_ratio (default 1.2), the part is treated as square-ish and fitted using orthogonal candidates (0° / ±90°), keeping square QFPs/QFNs/BGAs (such as a 45°-rotated TQFP) upright at 0°.
      • If aspect_ratio >= oblique_min_aspect_ratio (e.g. 2520 crystals at 1.25, 0805 at 1.6, 0402/0603/1206 at 2.0), the designator rotates along the component's long axis (±45°).
      • Setting oblique_min_aspect_ratio: 1.0 disables the square-ish override and always aligns oblique parts to their component axes.

3. Cutout Callouts (CUTOUTS & profile_cutouts)

4. Pin 1 & Polarity Markers (PIN1_*)

5. Diode & Passive Component Symbols (DIODES_*, CAPACITORS_*, INDUCTORS_*, RESISTORS_*)

6. Pad Designator Labels (PAD_LABELS_*)


Python vs Native Rust (kicad-monkey-fab) Parity

Both pure Python (kicad-monkey) and pure Rust (kicad-monkey-fab / kicad-cruncher-cli) expose the 17 canonical virtual layer keys, with the following implementation differences:

AreaPython kicad-monkey / kcrNative Rust kicad-monkey-fab / k3
CUTOUTSBoolean-unioned cutouts, 45° vector hatch, cleared "CUTOUT" calloutsPlain 0.15 mm cutout outline strokes (no hatch/label)
ASSEMBLY_OUTLINES_*Geometer 3D STEP HLR (simple/detail), single_pad_shape, dnp_mode="crossout"Copies F.Fab/B.Fab (MECHANICAL1/2) or pad bounding boxes (no STEP HLR or DNP crossout)
ASSEMBLY_DESIGNATORS_*Cutout subtraction, 0.06 mm/8% wall inset, polylabel, 14-step binary search, measured glyph aspect, oblique_min_aspect_ratio=1.2Cutout subtraction, DesignatorFitSession (no wall inset/polylabel, 12-step search, 0.62 × chars aspect, oblique_min_aspect_ratio=1.2)
PIN1_*All 4 styles (dot/square/pad/pin_label), knockout=True, A/K, +/-, inductor markers, ("R","C","L","F","FB","FU","SW")dot (+ BGA full pad fill), A/K, +/-, inductor markers, ("R","C","L","F","FB","FU","SW") (no square/pad/knockout)
PAD_LABELS_*pad/orthogonal/upright orientation, knockout=True, configurable boundsHorizontal (0°) stroke labels sized clamp(0.45 × min_dim, 0.25, 0.90) mm
Aliases & vdoc defaultsIncludes POLARITY_TOP/BOTTOM; vdoc defaults to 15 layers; sibling fab.jsonc inheritance in vdoc/pcb-svg/toonPIN_1_*, BOARD_CUTOUTS, CAPS_*, ASSY_* (no POLARITY_*); vdoc defaults to 9 layers; no automatic sibling fab.jsonc inheritance

Python API vs fab.jsonc Defaults

A few fab.jsonc CLI defaults intentionally differ from the low-level Python dataclass defaults for turnkey manufacturing output:

Inspecting, Debugging & Tuning Placements

SymptomWhere to Inspect / Fix
Square 45° IC designator rotated diagonallyRaise assembly_designators.oblique_min_aspect_ratio (default 1.2; 1.0 forces oblique rotation on all parts)
Tiny 0201/0402 designator omittedLower assembly_designators.min_font_size_mm (default 0.08) or increase fill_ratio (default 0.78)
Footprint fell back to pad box instead of 3D outlineRun kcr kicad prefs and kcr health project.kicad_pro --require-embedded; run kcr pcb embed-models to embed external STEP models natively (see Embedding 3D STEP Models)
Wrong diode cathode or 3-pin SOT-23 diode skippedSet footprint properties (property "CATHODE_PAD" "3") / (property "ANODE_PAD" "1") or diodes.overrides.<REF>
Non-polarized MLCC capacitor missing from CAPACITORS_*Set (property "CAPACITOR_SYMBOL" "true") per part or capacitors.visibility_mode: "all"
Need internal STEP creases on one connectorSet (property "ASSEMBLY_OUTLINE" "detail") or assembly_outlines.overrides.<REF>.detail: "detail"
Preview any single virtual layer in isolationkcr pcb-svg board.kicad_pcb --layers F.Cu,PIN1_TOP,ASSEMBLY_DESIGNATORS_TOP --views layers or inspect view.virtual_layer(key, opts).placed / .owners

Baking Virtual Layers To Native KiCad F.Fab / B.Fab / User.* Layers (vdoc)

kicad_monkey.fab includes a collision-guarded native KiCad baking engine, also exposed through the turnkey kcr vdoc command (which shares its safe documentation-layer cleanup engine with kcr pcb clean):

Field (BakeVirtualLayersOptions)TypeDefaultMeaning
layerstuple[str, ...]15 core virtual layersOrdered virtual layer keys to bake (add "PAD_LABELS_TOP"/"PAD_LABELS_BOTTOM" as needed).
layer_mapMapping[str, str] | NoneDEFAULT_KICAD_VIRTUAL_LAYER_MAP (fab preset)Optional override mapping canonical virtual keys to KiCad layer names (F.Fab, B.Fab, User.1..User.9, Eco1.User, Eco2.User).
virtual_optionsVirtualLayerOptions | NoneNoneShared virtual-layer options.
clear_existingboolTrueRemove prior Virtual_<KEY> items before writing new geometry.
forceboolFalseWrite even if non-virtual artwork occupies a target layer.
rename_user_layersboolTrueEnsure target User.N layers exist in (layers ...) with readable display names from the baked virtual keys.
python
from kicad_monkey import KiCadPcb
from kicad_monkey.fab import (
    BakeVirtualLayersOptions,
    VirtualLayerOptions,
    clear_baked_virtual_layers,
    detect_user_layer_collisions,
)

pcb = KiCadPcb.from_file("virtual_fab_layers.kicad_pcb")
opts = BakeVirtualLayersOptions(
    layers=("CUTOUTS", "PIN1_TOP", "DIODES_TOP", "ASSEMBLY_OUTLINES_TOP", "PAD_LABELS_TOP"),
    layer_map={"PAD_LABELS_TOP": "Eco1.User"},
    virtual_options=VirtualLayerOptions(dnp_mode="crossout"),
)

collisions = detect_user_layer_collisions(pcb, opts.layers, opts.layer_map)
if collisions:
    for c in collisions:
        print(f"Collision on {c.kicad_layer}: {c.existing_count} non-virtual items")
else:
    report = pcb.bake_virtual_layers(opts)
    for layer_rep in report.layers:
        print(f"{layer_rep.virtual_key} -> {layer_rep.kicad_layer} ({layer_rep.items_written} items)")
    pcb.save("virtual_fab_layers_vdoc.kicad_pcb")

# Strip baked virtual layers cleanly later
removed = clear_baked_virtual_layers(pcb)

Footprint & .pretty Library Baking (bake_virtual_layers_to_footprint)

kcr vdoc and k3 vdoc also accept a standalone .kicad_mod footprint or an entire .pretty footprint library directory, backed by bake_virtual_layers_to_footprint(fp, options=BakeFootprintVirtualLayersOptions(...)) in kicad_monkey.fab:

Inspecting VirtualLayerResult Directly

python
from kicad_monkey import KiCadPcb
from kicad_monkey.fab import VirtualLayerOptions

pcb = KiCadPcb.from_file("virtual_fab_layers.kicad_pcb")
view = pcb.fab().view()

result = view.virtual_layer("PAD_LABELS_TOP", VirtualLayerOptions())
print(result.key, result.color_mode, len(result.placed), len(result.styles))

# Convert placed items into canonical FabLayerItems (whole nanometres, +Y up)
items = result.to_fab_layer_items()
print(
    f"strokes={len(items.strokes or ())}, "
    f"areas={len(items.areas or ())}, "
    f"lands={len(items.lands or ())}"
)

See Also

kicad-monkey v2026.11.30·Docs updated 2026.12.01 15:43 UTC (fd9b75b)