On This Page (26)
- Supported Virtual Layer Keys
- Cross-Format Lowering Behavior
- Quick Start Across Outputs
- VirtualLayerOptions Reference
- Top-Level VirtualLayerOptions
- Component Visibility Policy (ComponentVisibilityPolicy) & Resolution Precedence
- Board Cutouts (CUTOUTS, CutoutLayerOptions & profile_cutouts)
- Pin 1 & Polarity Markers (PIN1_TOP / PIN1_BOTTOM, Aliases POLARITY_TOP / POLARITY_BOTTOM)
- Diode Orientation (DIODES_TOP / DIODES_BOTTOM)
- Passive Component Layers (CAPACITORS_*, INDUCTORS_*, RESISTORS_*)
- Assembly Outlines & Designators (ASSEMBLY_OUTLINES_* & ASSEMBLY_DESIGNATORS_*)
- Pad Designator Labels (PAD_LABELS_TOP / PAD_LABELS_BOTTOM, .GPLT / .GPLB)
- Placement, Sizing & Orientation Algorithms
- 1. Assembly Outlines (ASSEMBLY_OUTLINES_*) & DNP Crossout
- 2. Assembly Designator Placement (ASSEMBLY_DESIGNATORS_*)
- 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
- Python API vs fab.jsonc Defaults
- Inspecting, Debugging & Tuning Placements
- Baking Virtual Layers To Native KiCad F.Fab / B.Fab / User.* Layers (vdoc)
- Footprint & .pretty Library Baking (bake_virtual_layers_to_footprint)
- Inspecting VirtualLayerResult Directly
- See Also
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:
- Gerber X2/X1 (
fab.to_gerbers(virtual_layers=..., virtual_options=...)) - IPC-2581 Rev B (
fab.to_ipc2581(virtual_layers=..., virtual_options=...)) - PCB SVG (
fab.to_svg(layers=(..., "DIODES_TOP", "PAD_LABELS_TOP"), virtual_options=...)andfab.to_layer_svgs(...)) - Pure-Python Micro-STEP (
fab.to_micro_step(..., options=FabMicroStepOptions(virtual_layers=...))) - CLI workflows (
kcr fab,kcr vdoc,kcr pcb-svg, andkcr toon) - Native KiCad
User.*baking (pcb.bake_virtual_layers(...)/bake_virtual_layers_to_pcb)
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 Key | Display Name | Role | Side | Gerber Ext | Default vdoc Layer | SVG Colour |
|---|---|---|---|---|---|---|
CUTOUTS | Board Cutouts | cutouts | board | .GCU | User.1 | #D71920 |
PIN1_TOP | Top Pin 1 Markers | pin1 | top | .GP1T | User.2 | #1479CC |
PIN1_BOTTOM | Bottom Pin 1 Markers | pin1 | bottom | .GP1B | User.3 | #1479CC |
DIODES_TOP | Top Diode Orientation | diodes | top | .GDT | User.4 | #E67E22 |
DIODES_BOTTOM | Bottom Diode Orientation | diodes | bottom | .GDB | User.5 | #E67E22 |
CAPACITORS_TOP | Top Capacitors | capacitors | top | .GCT | User.4 | #0D9488 |
CAPACITORS_BOTTOM | Bottom Capacitors | capacitors | bottom | .GCB | User.5 | #0D9488 |
INDUCTORS_TOP | Top Inductors | inductors | top | .GLT | User.4 | #7C3AED |
INDUCTORS_BOTTOM | Bottom Inductors | inductors | bottom | .GLB | User.5 | #7C3AED |
RESISTORS_TOP | Top Resistors | resistors | top | .GRT | User.4 | #059669 |
RESISTORS_BOTTOM | Bottom Resistors | resistors | bottom | .GRB | User.5 | #059669 |
ASSEMBLY_OUTLINES_TOP | Top Component Outlines | assembly_drawing | top | .GAT | F.Fab (User.6 in user_only) | #1F2937 |
ASSEMBLY_OUTLINES_BOTTOM | Bottom Component Outlines | assembly_drawing | bottom | .GAB | B.Fab (User.7 in user_only) | #1F2937 |
ASSEMBLY_DESIGNATORS_TOP | Top Component Designators | assembly_drawing | top | .GADT | F.Fab (User.6/User.8 in fab_outlines/user_only) | #111827 |
ASSEMBLY_DESIGNATORS_BOTTOM | Bottom Component Designators | assembly_drawing | bottom | .GADB | B.Fab (User.7/User.9 in fab_outlines/user_only) | #111827 |
PAD_LABELS_TOP | Top Pad Labels | pad_labels | top | .GPLT | Eco1.User | #C2410C |
PAD_LABELS_BOTTOM | Bottom Pad Labels | pad_labels | bottom | .GPLB | Eco2.User | #C2410C |
Cross-Format Lowering Behavior
- Gerber X2/X1: Every virtual layer lowers as pure monochrome positive Gerber geometry (
.FilePolarity=Positive,.FileFunction=OtherDrawing,<Display Name>). Custom extensions can be overridden into_gerbers(extensions=...)using either the canonical key ("CUTOUTS": "GCO") or default extension ("GCU": "GCO"). Cutout hatching and"CUTOUT"labels can also be drawn directly onto the.GM1board profile film viaprofile_cutouts=True. - IPC-2581 Rev B: Non-empty virtual layers are emitted as
<Layer>and<LayerFeature>records excluded from<StackupGroup>so the physical stackup stays untouched.CUTOUTSuseslayerFunction="DOCUMENT",side="ALL"; the sixteen sided layers uselayerFunction="ASSEMBLY",side="TOP"or"BOTTOM". - SVG: Supports both monochrome (single layer colour from
layer_colours[key]or default colour) and shaded mode (per-itemVirtualItemStylewith fill, darker stroke, contrast halo drawn underneath, optionaldash_array_nm, and optionalopacity) so polarity markers, LED colours, passive symbols, and cutout callouts stay legible over busy copper. - Native KiCad
User.*Baking (vdoc): Converts placed items back to KiCad board millimetres (+Ydown) asGrLine,GrArc,GrCircle, andGrPolyprimitives inside deterministicVirtual_<LAYER_KEY>groups. (Note: native KiCadgr_polyemits outer rings without interior polygon holes, soknockout=Truepreserves counter islands across Gerber, IPC-2581B, and SVG, whereas bakedvdocwrites outer polygon rings only.)
Quick Start Across Outputs
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:
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
| Field | Type | Default | Meaning |
|---|---|---|---|
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_family | str | "Arial" | TrueType font family when font_mode="truetype". |
font_bold | bool | True | Bold 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_*. |
visibility | ComponentVisibilityPolicy | (defaults) | Unified inclusion/exclusion rules across all 8 component-scoped families. |
cutouts | CutoutLayerOptions | (defaults) | Board cutout scope, hatching, label text, and .GM1 profile overlay toggle. |
pin1 | Pin1LayerOptions | (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. |
diodes | DiodeLayerOptions | (defaults) | Diode polarity parameters, heuristics, visibility_mode, SVG shading mode, and overrides. |
capacitors | CapacitorLayerOptions | (defaults) | Capacitor polarity parameters, visibility_mode, + sign, SVG shading mode, and overrides. |
inductors | InductorLayerOptions | (defaults) | Inductor polarity parameters, visibility_mode, SVG shading mode, and overrides. |
resistors | ResistorLayerOptions | (defaults) | Resistor glyph style ("zigzag" or "box"), visibility_mode, SVG shading mode, and overrides. |
assembly_outlines | AssemblyOutlineLayerOptions | (defaults) | Assembly outline detail level ("simple", "detail", "bounding_box"), stroke widths, DNP crossout width, and overrides. |
assembly_designators | AssemblyDesignatorLayerOptions | (defaults) | Fitted assembly designator sizing (min_font_size_mm, max_font_size_mm, fill_ratio) and overrides. |
pad_labels | PadLabelLayerOptions | (defaults) | Fitted pad designator labels (PAD_LABELS_TOP / PAD_LABELS_BOTTOM) with orientation policy, geometric knockout, mechanical/THT filters, and overrides. |
hlr_cache | AssemblyHlrCache | None | None | Optional persistent cache hook for 3D STEP HLR projections. |
progress | Callable[[str], None] | None | None | Optional 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:
- Every KiCad footprint
(property "KEY" "VAL")is surfaced automatically inFabComponent.parameters. - Hiding
DIODES_*,CAPACITORS_*, orINDUCTORS_*never removesA/K,+/-, or inductor polarity markers fromPIN1_*. - Semantic-only overrides (for example,
ResistorOverride(style="box")withenabled=None) change styling without forcing visibility on. - CLI tools (
kcr fab,kcr vdoc,kcr pcb-svg,kcr toon) read KiCad footprint properties at runtime and never auto-mutate.jsoncconfigs.
| Field | Type | Default | Meaning |
|---|---|---|---|
exclude_kinds | tuple[str, ...] | ("graphical", "net_tie") | Component kinds excluded by default. |
exclude_designator_prefixes | tuple[str, ...] | () | Alphabetic reference prefixes excluded across all 8 families (case-insensitive). |
outline_parameter | str | "ASSEMBLY_OUTLINE" | Footprint property controlling ASSEMBLY_OUTLINES_* (boolean tokens or "simple"/"detail"/"bounding_box"). |
designator_parameter | str | "ASSEMBLY_DESIGNATOR" | Footprint property controlling ASSEMBLY_DESIGNATORS_*. |
pin1_parameter | str | "PIN1_MARKER" | Footprint property controlling PIN1_*. |
pad_labels_parameter | str | "PAD_LABELS" | Footprint property controlling PAD_LABELS_*. |
diode_parameter | str | "DIODE_SYMBOL" | Footprint property controlling DIODES_*. |
capacitor_parameter | str | "CAPACITOR_SYMBOL" | Footprint property controlling CAPACITORS_*. |
inductor_parameter | str | "INDUCTOR_SYMBOL" | Footprint property controlling INDUCTORS_*. |
resistor_parameter | str | "RESISTOR_SYMBOL" | Footprint property controlling RESISTORS_*. |
overrides | Mapping[str, ComponentVisibilityOverride] | {} | Shared per-component visibility matrix keyed by reference designator. |
excluded_designators | frozenset[str] | frozenset() | Variant/DNP designators suppressed unconditionally at Gate 1. |
Uniform resolution order (highest → lowest):
- Gate 0 — Layer active: Layer enabled for the current export/command.
- Gate 1 — Fitted / DNP (always wins): Unfitted/DNP footprints (
not comp.fittedor inexcluded_designators) are hidden across all 8 families whendnp_mode="omit"; whendnp_mode="crossout", they appear only onASSEMBLY_OUTLINES_*(dimmed dashed outline + redX) andASSEMBLY_DESIGNATORS_*(dimmed text). - P1 — Family config override:
virtual_layers.<family>.overrides.<REF>.enabled(true/false). - P2 — Shared visibility matrix override:
virtual_layers.visibility.overrides.<REF>.<family>(true/false). - P3 — Dedicated KiCad footprint property:
ASSEMBLY_OUTLINE,ASSEMBLY_DESIGNATOR,PIN1_MARKER,PAD_LABELS,DIODE_SYMBOL,CAPACITOR_SYMBOL,INDUCTOR_SYMBOL, orRESISTOR_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 P5visibility_mode(for example, settingCAPACITOR_SYMBOL="true"on a ceramic MLCC draws it even under"polarized_only"). - P4 — Global exclusions:
exclude_kindsandexclude_designator_prefixes. - P5 — Family
visibility_modepolicy:- Polarity-capable families (
capacitors,inductors):"polarized_only"(default),"all", or"explicit". Legacyinclude_non_polarizedremains accepted whenvisibility_mode is None. - All other 6 families:
"all"(default) or"explicit".
- Polarity-capable families (
Shared fab.jsonc Inheritance Across CLI Commands
Define "virtual_layers" once in fab.jsonc beside your board or project:
{
"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.
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.
| Field | Type | Default | Meaning |
|---|---|---|---|
scope | "interior" | "all" | "interior" | "interior" selects cutouts strictly inside the outer board boundary; "all" includes every cutout in view.profile().cutouts. |
hatch | bool | True | Draw clipped parallel vector hatch lines across each cutout. |
hatch_angle_deg | float | 45.0 | Hatch angle in degrees. |
hatch_pitch_mm | float | 1.0 | Spacing between adjacent hatch lines in mm (clamped to >= 0.1 mm). |
label | str | "CUTOUT" | Text fitted inside each cutout ("" omits label and hatch window). |
on_profile | bool | False | When True (or to_gerbers(profile_cutouts=True)), draws hatched cutout callouts directly onto the .GM1 profile Gerber. |
outline_width_mm | float | 0.10 | Cutout outline stroke width in mm. |
hatch_line_width_mm | float | 0.075 | Hatch line stroke width in mm. |
label_max_font_size_mm | float | 4.0 | Maximum fitted height in mm for cutout labels. |
label_fill_ratio | float | 0.72 | Fraction of available cutout span filled by the fitted label. |
label_rotation_min_gain | float | 0.25 | Minimum 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.
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
"dot"(default): Filled circle centered on the Pin 1 pad (full pad fill for BGA/LGA grid pads whengrid_pad_fill=True)."square": Filled square centered on and rotated with the Pin 1 pad."pad": Exact copper Pin 1 pad land filled in marker paint."pin_label": Vector pin name (1,A1,2, …) fitted inside the pad.knockout=True: Punches the glyph (A,K,+,-,A1,1) out of the full pad polygon via planar boolean difference, preserving interior counter islands (like the triangle insideA). Because knockout is pure planar geometry rather than an SVG mask, it lowers identically to Gerber X2 regions, IPC-2581 contours, and SVG even-odd paths (native KiCadvdocgr_polyemits outer rings without holes).
style="dot" (default) — auto-scaled circular Pin 1 dot on 45°-rotated LQFP-64 U2.
style="square" — pad-rotated square marker aligned to the 45° Pin 1 lead on U2.
style="pad" — fills the exact copper Pin 1 pad geometry on U2.
style="pin_label" — fits vector pin number (1) inside the rotated Pin 1 pad on U2.
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.
| Field | Type | Default | Meaning |
|---|---|---|---|
style | "dot" | "square" | "pad" | "pin_label" | "dot" | Default Pin 1 marker style. |
knockout | bool | False | Punch glyphs out of the copper pad polygon as pure negative GeomPlanarRegion geometry. |
grid_pad_fill | bool | True | Fill the full pad land for BGA/LGA grid pads (A1, …) in "dot" / "square" modes. |
dot_diameter_mm | float | None | None | Explicit 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_mm | float | 0.40 | Lower clamp for auto-scaled dot diameter in mm. |
max_dot_diameter_mm | float | 0.90 | Upper clamp for auto-scaled dot diameter in mm. |
pad_parameter | str | "PIN1_PAD" | Footprint property naming the Pin 1 pad (or "NONE"/"FALSE" to suppress). |
positive_parameter | str | "POSITIVE_PAD" | Footprint property naming explicit + pad(s). |
negative_parameter | str | "NEGATIVE_PAD" | Footprint property naming explicit - pad(s). |
exclude_designator_prefixes | tuple[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_pin | bool | True | Skip 1-pad components (such as fiducials, test points, and mounting holes) during generic Pin 1 auto-detection unless explicitly opted in. |
exclude_two_pin_prefixes | tuple[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_labels | bool | True | Draw A/K inside anode and cathode pads for detected diodes. |
cap_polarity_labels | bool | True | Draw +/- inside positive and negative pads for polarized capacitors. |
inductor_polarity_markers | bool | True | Draw 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. |
overrides | Mapping[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.
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.
| Field | Type | Default | Meaning |
|---|---|---|---|
cathode_parameter | str | "CATHODE_PAD" | Footprint property naming cathode pad(s) (comma-separated supported); "none"/"false" suppresses. |
anode_parameter | str | "ANODE_PAD" | Optional property naming anode pad(s). |
type_parameter | str | "DIODE_TYPE" | Optional subtype: "normal", "led", "schottky", "zener", or "tvs". |
color_parameter | str | "DIODE_COLOR" | Optional colour (#RRGGBB or named colour) for shaded SVG output. |
default_cathode_pad | str | "2" | Fallback cathode pad for 2-pin diodes with numeric pads "1"/"2". |
cathode_pad_names | tuple[str, ...] | ("K", "C", "CATHODE", "CAT", "-") | Pad names recognized automatically as cathodes. |
designator_prefixes | tuple[str, ...] | ("D", "LED") | Reference prefixes matched during 2-terminal auto-detection. |
keywords | tuple[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). |
overrides | Mapping[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:
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Ω).
RESISTORS_TOP configured with style="box" (IEC rectangular resistor glyph aligned along 45°-rotated R1).
CapacitorLayerOptions (CAPACITORS_TOP / CAPACITORS_BOTTOM, .GCT / .GCB)
| Field | Type | Default | Meaning |
|---|---|---|---|
positive_parameter | str | "POSITIVE_PAD" | Footprint property naming the positive pad. |
negative_parameter | str | "NEGATIVE_PAD" | Footprint property naming the negative pad. |
type_parameter | str | "CAPACITOR_TYPE" | Optional type ("polarized", "tantalum", "electrolytic", "non_polarized", "mlcc", "none"). |
color_parameter | str | "CAPACITOR_COLOR" | Optional SVG accent colour. |
default_positive_pad | str | "1" | Fallback positive pad for numeric "1"/"2" polarized caps. |
visibility_mode | "all" | "polarized_only" | "explicit" | None | None (effective "polarized_only") | Visibility policy ("polarized_only" default, "all" draws MLCC/film too, "explicit" draws P1–P3 opt-ins only). |
include_non_polarized | bool | False | Legacy bridge when visibility_mode is None. |
show_plus_sign | bool | True | Draw + on the positive side of polarized capacitors. |
color_mode | "shaded" | "monochrome" | "shaded" | SVG paint mode (default teal #0D9488). |
designator_prefixes | tuple[str, ...] | ("C",) | Reference prefixes for auto-detection. |
keywords | tuple[str, ...] | ("capacitor", "tantalum", "tant", "electrolytic", "elec", "supercap", "polymer") | Polarity/type keywords. |
overrides | Mapping[str, CapacitorOverride] | {} | Per-component CapacitorOverride(enabled, positive_pad, negative_pad, polarized, color). |
InductorLayerOptions (INDUCTORS_TOP / INDUCTORS_BOTTOM, .GLT / .GLB)
| Field | Type | Default | Meaning |
|---|---|---|---|
polarity_parameter | str | "INDUCTOR_POLARITY_PAD" | Primary property naming the winding-start pad. |
pin1_fallback_parameter | str | "PIN1_PAD" | Secondary fallback property when INDUCTOR_POLARITY_PAD is absent. |
type_parameter | str | "INDUCTOR_TYPE" | Optional type ("polarized", "coupled", "dot", "start", "non_polarized", "none"). |
color_parameter | str | "INDUCTOR_COLOR" | Optional SVG accent colour. |
visibility_mode | "all" | "polarized_only" | "explicit" | None | None (effective "polarized_only") | Visibility policy ("polarized_only" default). |
include_non_polarized | bool | False | Legacy bridge when visibility_mode is None. |
color_mode | "shaded" | "monochrome" | "shaded" | SVG paint mode (default violet #7C3AED). |
designator_prefixes | tuple[str, ...] | ("L", "FB", "IND") | Reference prefixes for auto-detection. |
keywords | tuple[str, ...] | ("inductor", "choke", "ferrite", "coil") | Keywords scanned during auto-detection. |
overrides | Mapping[str, InductorOverride] | {} | Per-component InductorOverride(enabled, polarity_pad, polarized, color). |
ResistorLayerOptions (RESISTORS_TOP / RESISTORS_BOTTOM, .GRT / .GRB)
| Field | Type | Default | Meaning |
|---|---|---|---|
style | "zigzag" | "box" | "zigzag" | Default glyph style ("zigzag" IEEE 6-peak or "box" IEC rectangle). |
style_parameter | str | "RESISTOR_STYLE" | Per-component footprint property overriding "zigzag" vs "box". |
color_parameter | str | "RESISTOR_COLOR" | Optional SVG accent colour (default emerald #059669). |
color_mode | "shaded" | "monochrome" | "shaded" | SVG paint mode. |
designator_prefixes | tuple[str, ...] | ("R",) | Reference prefixes for auto-detection. |
keywords | tuple[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. |
overrides | Mapping[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).
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 prefslists resolved${KICAD*_3DMODEL_DIR}and user 3D model paths. - Strict CI / portable mode: pass
--embedded-only(or setKCR_EMBEDDED_MODELS_ONLY=1) to ignore external libraries, and runkcr health project.kicad_pro --require-embedded --fail-on-issuesto 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 useEmbeddedFile.from_kicad_bytes(...)in Python — see Embedding 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.
| Field | Type | Default | Meaning |
|---|---|---|---|
detail | "simple" | "detail" | "bounding_box" | "simple" | Default outline detail level ("simple" outer silhouette, "detail" internal creases/features, "bounding_box" instant pad extent). |
stroke_width_mm | float | 0.12 | Stroke width in mm for simple and bounding_box outlines. |
detail_stroke_width_mm | float | 0.08 | Stroke width in mm for detail internal linework. |
dnp_crossout_stroke_width_mm | float | None | None | Stroke 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. |
overrides | Mapping[str, AssemblyOutlineOverride] | {} | Per-component AssemblyOutlineOverride(enabled, detail). |
AssemblyDesignatorLayerOptions
| Field | Type | Default | Meaning |
|---|---|---|---|
min_font_size_mm | float | 0.08 | Minimum fitted height in mm; smaller labels are omitted. |
max_font_size_mm | float | 2.40 | Maximum fitted height in mm. |
fill_ratio | float | 0.78 | Fraction of available outline box filled by the designator. |
oblique_min_aspect_ratio | float | 1.2 | Minimum 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. |
overrides | Mapping[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.
Full-board overview — PAD_LABELS_TOP (font_mode="stroke", orientation="pad").
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)
orientation="pad" (default) — aligns each label along its pad's exact long axis (±45° on rotated LQFP-64 U2 leads).
orientation="orthogonal" — snaps elongated pad labels strictly to 0° or 90°.
orientation="upright" — keeps every label strictly horizontal (0°), scaling to fit both pad width and height.
| Field | Type | Default | Meaning |
|---|---|---|---|
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_family | str | "Arial" | TrueType font family when font_mode="truetype". |
font_bold | bool | True | Bold weight flag when font_mode="truetype". |
orientation | "pad" | "orthogonal" | "upright" | "pad" | Label orientation policy. |
knockout | bool | False | Punch pad labels out of copper pad polygons via boolean difference. |
fill_ratio | float | 0.70 | Fraction of available pad extent filled by the label. |
min_height_nm | float | 60_000.0 (0.06 mm) | Minimum fitted height in nm (min_height_mm in JSONC configs). |
max_height_nm | float | 2_000_000.0 (2.0 mm) | Maximum fitted height in nm (max_height_mm in JSONC configs). |
stroke_width_ratio | float | 0.14 | Stroke thickness as a fraction of label height in "stroke" mode. |
skip_empty_designators | bool | True | Skip pads with empty pin numbers. |
skip_mechanical_pads | bool | False | Skip mechanical/shield pads (MH*, MP*, MTG*, SH*, TAB*, etc.). |
include_through_hole | bool | True | Include through-hole pads as well as SMD pads. |
visibility | ComponentVisibilityPolicy | None | None | Optional 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). |
overrides | Mapping[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
- Outline fallback chain (Python
KiCadFabView):- When
detail != "bounding_box": projects each resolved 3D STEP model via Geometer HLR ("simple"outer silhouette vs"detail"internal creases, with bottom-side camera flipdir=-Z,up=+Y,ux=-lx, and arc handedness reversal). - If no STEP projection is available (or extruded
FabBody.outlineon custom views), single-pad components (fiducials, test points, mounting holes) draw their exact single-pad shape (assembly_pad_shape); multi-pad components draw an axis-aligned pad bounding box (clamped to>= 0.16 mmper axis). detail="bounding_box"skips STEP HLR and emits the pad bounding box directly.
- When
- DNP crossout (
dnp_mode="crossout"): Draws a diagonalXconnecting the opposite corners of the component annotation region'sminimum_rotated_rectangle(so rotated DNP parts get an orientedX), with auto-scaled stroke widthclamp(0.06 × min_dim, max(1.25 × outline_width, 0.15 mm), 0.35 mm)unlessdnp_crossout_stroke_width_mmis set explicitly.
2. Assembly Designator Placement (ASSEMBLY_DESIGNATORS_*)
- 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.
- 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 interior3 × 3grid. - 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 byfill_ratio(default0.78), and clamps to[min_font_size_mm, max_font_size_mm](default[0.08, 2.40] mm).
- Evaluates a deterministic candidate set inside the inset region: region centroid, pole of inaccessibility (
- 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 within1 µm(e.g. square QFNs or large ICs capped atmax_font_size_mm),0°horizontal wins. - Oblique components (e.g.
45°,135°,30°): Projects the annotation region onto the component's local axes to measureaspect_ratio = long_side / short_side.- If
aspect_ratio < oblique_min_aspect_ratio(default1.2), the part is treated as square-ish and fitted using orthogonal candidates (0°/±90°), keeping square QFPs/QFNs/BGAs (such as a45°-rotated TQFP) upright at0°. - If
aspect_ratio >= oblique_min_aspect_ratio(e.g.2520crystals at1.25,0805at1.6,0402/0603/1206at2.0), the designator rotates along the component's long axis (±45°). - Setting
oblique_min_aspect_ratio: 1.0disables the square-ish override and always aligns oblique parts to their component axes.
- If
- Orthogonal components (
3. Cutout Callouts (CUTOUTS & profile_cutouts)
scope="interior"keeps cutouts strictly inside the outer board boundary (> 100 nmclearance from the outer ring, excluding board-edge notches).- Overlapping or crossing
Edge.Cutscutouts are boolean-unioned first so intersecting routed slots become one seamless region. - Parallel vector hatch lines at
hatch_angle_deg(45°) andhatch_pitch_mm(1.0 mm) are clipped to each unified cutout polygon. - The callout label (
"CUTOUT") is inset0.15 mmfrom walls and fitted using a 15-slice horizontal/vertical medial-chord scanline, 4-step hill-climb, and arm recentering (so concave L/T/U/C shapes fit cleanly), with dominant diagonal-edge orientation detection (>= 35%of max edge length,>= 10°off-axis). Cutouts where fitted height falls below0.25 mmomit the label; otherwise a±22%padded rectangular hatch window is cleared around the text. Labels remain horizontal (0°) unless rotating along a narrow slot's axis improves fitted height by at leastlabel_rotation_min_gain(25%).
4. Pin 1 & Polarity Markers (PIN1_*)
- Target pad precedence (evaluated in exact order):
- Explicit
POSITIVE_PAD/NEGATIVE_PAD(per-component override or footprint property) - Explicit
PIN1_PAD(per-component override or footprint property;"NONE"/"FALSE"suppresses) - Polarized inductor winding-start pad (
inductor_polarity_markers) - Auto-detected diode
A/Kpads (diode_ak_labels) - Auto-detected polarized capacitor
+/-pads (cap_polarity_labels) - Generic Pin 1 auto-detection: exact pad
"1"first, then exact"A1", then (for non-connectors only, skippingM*rows unless>= 4other rows exist) column-first BGA/LGA grid pin. Parts without a matching Pin 1 pad emit no generic marker.
- Explicit
- Default exclusions: skips alphabetic prefixes
("R", "C", "L", "F", "FB", "FU", "SW"), 1-pin footprints (exclude_single_pin=True), and 2-pinX/Ycrystals (exclude_two_pin_prefixes=("X", "Y")) during generic Pin 1 auto-detection (explicit properties and polarized passives still draw; connectorsJ,JP,P,CN,CON,HDR,USBbypass BGA grid heuristics). - Marker geometry: centered on the target pad;
"dot"scales to0.70 × min_pad_dimclamped to[0.40, 0.90] mm(full pad fill on BGA/LGA grid pads whengrid_pad_fill=True). Whenknockout=True, glyphs (A,K,+,-,A1,1) are punched out of the copper pad polygon via planar boolean difference so counter islands are preserved across Gerber, IPC-2581B, and SVG.
5. Diode & Passive Component Symbols (DIODES_*, CAPACITORS_*, INDUCTORS_*, RESISTORS_*)
- Diodes (
DIODES_*): Resolves anode/cathode pad(s) (explicitCATHODE_PAD/ANODE_PAD, namedK/C/CATHODE/CAT/-, or 2-pad fallback; 3+ pin parts require explicit pad properties) and draws the triangle + subtype cathode bar + optional LED rays strictly inside the clear gap between pad inner edges so solder lands stay unobstructed. - Passives (
CAPACITORS_*,INDUCTORS_*,RESISTORS_*): Construct an orientedInterPadFramespanning pad center to pad center between the two terminal pads so parallel/curved capacitor plates, 4-lobe inductor coils, and IEEE zig-zag / IEC box resistors align cleanly along the component axis. Cross-family prefix guards prevent e.g. a resistor mentioning"LED"in its value/description from matchingDIODES_*.
6. Pad Designator Labels (PAD_LABELS_*)
- Iterates fitted components' copper pads (plus standalone/free pads) on the target side and fits each pin number (
1,A1,K, …;"?"whenskip_empty_designators=False) centered inside its pad land, inset by8%(12%forknockout=True, capped at0.12 mm), scaled byfill_ratio(0.70), and clamped to[min_height_nm, max_height_nm]([0.06, 2.0] mm). - Orientation modes:
"pad"aligns with the pad's long axis when pad elongation exceeds1.25:1(with a1.08×tie-breaker favoring0°),"orthogonal"snaps elongated pads to0°or90°, and"upright"keeps every label strictly horizontal (0°). - Knockout rim preservation (
knockout=True): Runs a shrink-retry loop (1.0 → 0.85 → 0.72scale factors) so boolean subtraction always leaves a clean copper rim around the punched glyph.
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:
| Area | Python kicad-monkey / kcr | Native Rust kicad-monkey-fab / k3 |
|---|---|---|
CUTOUTS | Boolean-unioned cutouts, 45° vector hatch, cleared "CUTOUT" callouts | Plain 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.2 | Cutout 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 bounds | Horizontal (0°) stroke labels sized clamp(0.45 × min_dim, 0.25, 0.90) mm |
Aliases & vdoc defaults | Includes POLARITY_TOP/BOTTOM; vdoc defaults to 15 layers; sibling fab.jsonc inheritance in vdoc/pcb-svg/toon | PIN_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:
cutouts.on_profile:False(Python API) vsTrue(fab.jsonc)cutouts.outline_width_mm/hatch_line_width_mm:0.10/0.075(Python API) vs0.15/0.08(fab.jsonc)diodes.cathode_pad_names:("K", "C", "CATHODE", "CAT", "-")(Python API) vs("K", "C", "CAT", "CATHODE", "NEG", "-")(fab.jsonc)pin1.exclude_single_pinandpad_labels.stroke_width_ratioare currently Python API fields (not separatefab.jsonckeys).
Inspecting, Debugging & Tuning Placements
| Symptom | Where to Inspect / Fix |
|---|---|
Square 45° IC designator rotated diagonally | Raise assembly_designators.oblique_min_aspect_ratio (default 1.2; 1.0 forces oblique rotation on all parts) |
Tiny 0201/0402 designator omitted | Lower 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 outline | Run 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 skipped | Set 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 connector | Set (property "ASSEMBLY_OUTLINE" "detail") or assembly_outlines.overrides.<REF>.detail: "detail" |
| Preview any single virtual layer in isolation | kcr 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):
- Three built-in layout presets (
resolve_vdoc_preset_layer_map(preset)/vdoc.jsonc"layer_preset"/--preset):fab(default):F.Fab/B.Fabcarry bothASSEMBLY_OUTLINES_*andASSEMBLY_DESIGNATORS_*;CUTOUTS,PIN1_*,DIODES_*go onUser.1..User.5.fab_outlines:F.Fab/B.FabcarryASSEMBLY_OUTLINES_*only;ASSEMBLY_DESIGNATORS_*move toUser.6/User.7.user_only: all virtual layers stay onUser.1..User.9(Eco1.User/Eco2.UserforPAD_LABELS_*).
detect_user_layer_collisions(pcb, layers, layer_map=None): Scans target layers for non-virtual artwork before mutating the board and returnstuple[UserLayerCollision, ...].bake_virtual_layers_to_pcb(pcb, view, options=None)(orpcb.bake_virtual_layers(options)): Computes all requested virtual layers first, idempotently removes priorVirtual_<LAYER_KEY>KiCad groups whenclear_existing=True, writes nativeGrLine/GrArc/GrCircle/GrPolyprimitives onto each mapped layer, groups every item underVirtual_<LAYER_KEY>, and sets readable KiCadUser.Ndisplay names whenrename_user_layers=True.clear_baked_virtual_layers(pcb, *, keys=None): Removes previously bakedVirtual_*primitives and groups without touching user-authored graphics.
Field (BakeVirtualLayersOptions) | Type | Default | Meaning |
|---|---|---|---|
layers | tuple[str, ...] | 15 core virtual layers | Ordered virtual layer keys to bake (add "PAD_LABELS_TOP"/"PAD_LABELS_BOTTOM" as needed). |
layer_map | Mapping[str, str] | None | DEFAULT_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_options | VirtualLayerOptions | None | None | Shared virtual-layer options. |
clear_existing | bool | True | Remove prior Virtual_<KEY> items before writing new geometry. |
force | bool | False | Write even if non-virtual artwork occupies a target layer. |
rename_user_layers | bool | True | Ensure target User.N layers exist in (layers ...) with readable display names from the baked virtual keys. |
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:
- Synthesizes footprint-local assembly outlines on
F.Fabplus optional Pin 1, diode, capacitor, inductor, and resistor symbols onto configurableUser.*layers (DEFAULT_FOOTPRINT_VIRTUAL_LAYERS). - Pass
--fab-only(alias--outlines-only) on the CLI — orlayers=("ASSEMBLY_OUTLINES_TOP",)in Python — to bake cleanF.Fabcomponent outlines without adding passive/diode/Pin 1 symbols. - Honors the same documentation-layer cleanup guard (
--clean/--no-clean/--clean-only/--clear-only) while protecting pads, courtyards (*.CrtYd), silkscreen, copper, and 3D models.
Inspecting VirtualLayerResult Directly
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
- Fab &
KiCadFabView— Gerber X2, Excellon NC Drill, IPC-2581B, SVG, PnP/BOM, and Micro-STEP - CLI Fabrication Guide (
kcr fab,kcr vdoc) - 34-Part Virtual Fab Layers Showcase Example