On This Page (12)
kcr pcb
Board and footprint maintenance commands: clean documentation layers and embed external 3D STEP models.
| Command | Aliases | Category | Runtime | Config | Guide |
|---|---|---|---|---|---|
kcr pcb | — | Projects, Libraries & Assets | Python kcr | Explicit --config <FILE> (pcb.clean.config, kicad_cruncher.pcb.clean.config.a0) for pcb clean; installed KiCad prefs for pcb embed-models | KiCadPcb & Board Model |
Opposite Write Defaults: clean vs embed-models
kcr pcb cleanis DRY-RUN / PLAN BY DEFAULT: it prints a JSON cleanup plan to stdout and touches nothing on disk until you pass--apply.kcr pcb embed-modelsWRITES IN PLACE BY DEFAULT: it modifies the target.kicad_pcbor.kicad_modimmediately unless you pass--dry-runor redirect output with-o <path>.
Running kcr pcb without a subcommand prints help to stderr and exits with code 2.
Usage
kcr pcb [-h] <pcb-action> ...Subcommands
| Subcommand | Description |
|---|---|
kcr pcb clean | Plan (default) or apply (--apply) documentation-layer cleanup on a .kicad_pcb, .kicad_pro, .kicad_mod, or .pretty library. |
kcr pcb embed-models | Resolve external STEP/STP models (and .wrl -> .step/.stp siblings) using KiCad preferences and environment variables, then embed them natively (KiCad 10.0.8 zstd level 15 + MMH3-128) at deduplicated board scope (.kicad_pcb) or footprint scope (.kicad_mod). |
kcr pcb clean
Plan (default) or apply (--apply) documentation-layer cleanup on a .kicad_pcb, .kicad_pro, .kicad_mod, or .pretty library.
kcr pcb clean [-h] [--config CONFIG]
[--write-config WRITE_CONFIG] [--dry-run |
--apply]
[file]Positional Arguments
| Argument | Description |
|---|---|
file | .kicad_pcb, .kicad_pro, .kicad_mod, or .pretty library directory |
Options
| Flag | Description |
|---|---|
--config CONFIG | PCB clean JSONC config (pcb.clean.config) |
--write-config WRITE_CONFIG | Write the default PCB clean config |
--dry-run | Write a cleanup plan only. Mutually exclusive with --apply. |
--apply | Apply cleanup mutations. Mutually exclusive with --dry-run. |
kcr pcb embed-models
Resolve external STEP/STP models (and .wrl -> .step/.stp siblings) using KiCad preferences and environment variables, then embed them natively (KiCad 10.0.8 zstd level 15 + MMH3-128) at deduplicated board scope (.kicad_pcb) or footprint scope (.kicad_mod).
kcr pcb embed-models [-h] [-o OUTPUT] [--doc PCBDOC]
[--dry-run | --apply]
[--refs REFS [REFS ...]]
[--update-project-library] [--re-embed]
[--prune-unused] [--backup]
[--model-search-dir MODEL_SEARCH_DIR]
[--no-installed-kicad] [--json]
[--no-color]
[file]Positional Arguments
| Argument | Description |
|---|---|
file | .kicad_pcb, .kicad_pro, or .kicad_mod input (auto-detected in CWD if omitted) |
Options
| Flag | Description |
|---|---|
-o, --output OUTPUT | Write modified file to this path instead of editing in place |
--doc, --pcbdoc PCBDOC | With .kicad_pro input, select a specific .kicad_pcb by filename or stem |
--dry-run | Resolve models and report what would be embedded without writing any file. Mutually exclusive with --apply. |
--apply | Explicitly apply embedded model updates (default when --dry-run is not set). Mutually exclusive with --dry-run. |
--refs REFS | Limit embedding to specific footprint reference designators (e.g. --refs U4 U5) |
--update-project-library | Also embed updated STEP payloads into matching project-local .kicad_mod footprints |
--re-embed | Re-encode existing embedded STEP models in KiCad 10.0.8 native format, consolidate footprint copies to board scope, and prune unused model entries |
--prune-unused | Remove unreferenced type=model embedded_files entries while keeping fonts/other files |
--backup | Save a .bak backup alongside the input file before in-place replacement |
--model-search-dir MODEL_SEARCH_DIR | Additional 3D model search directory (repeatable) |
--no-installed-kicad | Do not probe installed KiCad installations or kicad_common.json preferences |
--json | Emit machine-readable JSON summary to stdout |
--no-color | Disable ANSI colors and animated spinners |
Configuring pcb clean
kcr pcb clean runs the shared safe documentation-layer cleanup engine (the exact same engine used by kcr vdoc) against a .kicad_pcb, .kicad_pro, .kicad_mod, or .pretty footprint library, emitting a structured JSON plan (kicad_cruncher.pcb.clean.plan.a0) or mutation report to stdout.
Config Discovery & pcb.clean.config
- Explicit
--config <path>only:kcr pcb cleannever auto-discovers or auto-creates a config file; omitting--configuses built-in defaults. --write-config <path>writes the commented starterpcb.clean.configtemplate and exits0.
Schema contract: kicad_cruncher.pcb.clean.config.a0.
{
"schema": "kicad_cruncher.pcb.clean.config.a0",
"targets": {
"user_layers": true, // Reset custom KiCad User.N display names on matched layers
"generated_graphics": true, // Remove generated cleanup metadata graphics
"footprint_graphics": true, // Remove matching footprint-local doc graphics
"board_graphics": false, // Disabled by default (enabled in kcr vdoc)
"reference_fields": true, // Hide visible Reference fields on matched layers
"value_fields": true // Hide visible Value fields on matched layers
},
"safety": {
"protect_pads": true, // Never remove pads
"protect_models": true, // Never remove 3D models
"protect_mandatory_fields": true,// Never delete Reference/Value fields (hide only)
"require_explicit_apply": true
},
"layers": {
"include": ["*.User", "User.*", "*.Fab"],
"exclude": ["F.Cu", "B.Cu", "In*.Cu", "Edge.Cuts"]
},
"metadata": {
"field_name": "ALX_HLR_META", // Legacy compatibility field name used to tag cleanup metadata
"schema": "kicad_cruncher.pcb_clean.metadata.a0"
}
}pcb clean Conflict & Safety Rules
layers.excludeALWAYS beatslayers.include: any layer matching anexcludeglob is unconditionally protected even if it also matches anincludeglob.- Mandatory fields are hidden, never deleted:
ReferenceandValueproperties on cleaned layers are marked(hide yes)rather than removed, preserving schematic/PCB identity. --dry-runvs--apply: mutually exclusive; omitting both behaves as plan/dry-run and never writes files.
How pcb embed-models Resolves & Locks Boards
Resolves external STEP/STP 3D models — including .wrl references that have a sibling .step or .stp file beside them — and embeds them directly into a .kicad_pcb (deduplicated by SHA-256 at board scope) or standalone .kicad_mod (at footprint scope) using KiCad 10.0.8 native encoding (one-shot zstd level 15 with frame content size + KiCad legacy-tail MMH3-128 checksum).
3D Model Discovery
By default, kcr pcb embed-models searches:
${KIPRJMOD}and paths relative to the board/project.- Installed KiCad 3D libraries,
kicad_common.jsonenvironment variables, andsystem.extra_3d_search_dirs(disable with--no-installed-kicadfor hermetic CI runs). - Process environment variables (
KICAD10_3DMODEL_DIR,KICAD9_3DMODEL_DIR, etc.). - Any explicit repeatable
--model-search-dir <DIR>roots.
Inspect your workstation's resolved 3D paths with kcr kicad prefs.
pcb embed-models Safety Guards & Conflict Rules
- KiCad
.lcklock-file guard:- Before any in-place write,
kcr pcb embed-modelschecks for KiCad lock files (~<file>.lck,.<file>.lck,<file>.lck,~<stem>.kicad_pro.lck,<stem>.kicad_pro.lck) beside the target board — and, when--update-project-libraryis set, pre-validates lock files on every touched local.kicad_modbefore mutating the board on disk so partial writes never occur. - Refuses with exit code
1if any lock file exists. Bypass safely by closing KiCad, using--dry-run, or writing to a separate file with-o <path>.
- Before any in-place write,
--update-project-library+-oconflict:- Combining
--update-project-librarywith-o <path>is rejected unless--dry-runis also passed, preventing a detached output board from mutating live project-local.prettylibrary files.
- Combining
--backupis in-place only:--backupwrites<input>.bakonly when editing in place; when-o <path>targets a separate file, the original input is untouched so no.bakis created.
- Never converts VRML (
.wrl) meshes:- If a
.wrlreference has a sibling.step/.stp, it is upgraded and embedded cleanly. Truly WRL-only references are left untouched and reported aswrl_onlywarnings (never lossily mesh-converted).
- If a
--re-embed,--prune-unused, and--refssemantics:--re-embedre-encodes legacy embedded STEP payloads into KiCad 10.0.8 native zstd-15 + MMH3-128 format, consolidates footprint-level embedded STEP copies up to deduplicated board scope, and prunes orphanedtype=modelentries.--prune-unusedremoves unreferencedtype=modelembedded_filesentries while always preserving embedded fonts, worksheets, other non-model assets, WRL entries, and payloads referenced by footprints outside--refs.--refs U4 U5limits embedding to the listed designators (unselected footprints remain untouched).--jsonemits the structuredkicad_cruncher.pcb_embed_models.a0summary to stdout.
Quick Examples
# Preview PCB cleanup rules without modifying the board (dry-run is default for pcb clean)
kcr pcb clean --dry-run board.kicad_pcb# Write a starter pcb.clean.config JSONC template
kcr pcb clean --write-config pcb.clean.config# Preview which external STEP 3D models would be embedded natively (KiCad 10.0.8 format)
kcr pcb embed-models board.kicad_pcb --dry-run# Embed all resolved external STEP models at deduplicated board scope (and sync local .pretty footprints)
kcr pcb embed-models board.kicad_pcb --apply --update-project-library --backup# Re-encode legacy embedded STEP payloads in KiCad 10.0.8 native format and prune orphans
kcr pcb embed-models board.kicad_pcb --re-embed --prune-unused