Skip to content

Batch Operations

The apply_batch tool applies multiple schematic modifications atomically from a JSON file. All operations share a single load-save cycle for performance and consistency.

Batch files live in the .mckicad/ sidecar directory by default (next to the schematic). The schema supports six operation types, processed in dependency order:

  1. components — placed first so pin-reference wires can find them
  2. power_symbols — attached to component pins
  3. wires — connect components by coordinates or pin references
  4. labels — local or global net labels, by coordinates or pin references
  5. label_connections — place the same net label on multiple pins simultaneously
  6. no_connects — no-connect flags by coordinates or pin references
Apply the batch file circuit.json to my schematic at /path/to/project.kicad_sch

Validate the batch without modifying the schematic:

Apply the batch file circuit.json to my schematic with dry_run=True

Returns validation results and a preview of what would be applied.

For sub-sheets in a hierarchical design, pass parent_uuid and sheet_uuid (both returned by add_hierarchical_sheet). This sets the instance path so that kicad-cli correctly resolves power symbol nets during netlist export.

Without hierarchy context, power symbols (GND, +3V3, etc.) may be silently dropped from the netlist.

{
"components": [
{
"lib_id": "Device:C",
"reference": "C1",
"value": "100nF",
"x": 100,
"y": 200,
"rotation": 0,
"unit": 1
}
],
"power_symbols": [
{
"net": "GND",
"pin_ref": "C1",
"pin_number": "2",
"lib_id": "power:GND",
"stub_length": 2.54
}
],
"wires": [
{
"start_x": 100,
"start_y": 200,
"end_x": 200,
"end_y": 200
},
{
"from_ref": "R1",
"from_pin": "1",
"to_ref": "R2",
"to_pin": "2"
}
],
"labels": [
{
"text": "SPI_CLK",
"x": 150,
"y": 100,
"global": false,
"rotation": 0
},
{
"text": "GPIO5",
"pin_ref": "U8",
"pin_number": "15",
"global": true,
"shape": "bidirectional",
"direction": "left",
"stub_length": 2.54
}
],
"label_connections": [
{
"net": "BOOT_MODE",
"global": true,
"shape": "bidirectional",
"stub_length": 2.54,
"connections": [
{"ref": "U8", "pin": "48"},
{"ref": "R42", "pin": "1", "direction": "right", "stub_length": 5.08}
]
}
],
"no_connects": [
{"x": 300, "y": 300},
{"pin_ref": "U8", "pin_number": "33"}
]
}
FieldRequiredTypeDescription
lib_idyesstringLibrary symbol ID (e.g., "Device:C", "MCU_Microchip:ATmega328P-PU")
referencenostringReference designator (e.g., "C1", "U3")
valuenostringComponent value (e.g., "100nF", "10k")
xyesnumberX position in schematic units (mm)
yyesnumberY position in schematic units (mm)
rotationnonumberRotation angle in degrees (default: 0)
unitnointegerUnit number for multi-unit components (default: 1)
FieldRequiredTypeDescription
netyesstringPower net name (e.g., "GND", "+3V3", "VCC")
pin_refyesstringReference of the component to attach to
pin_numberyesstringPin number on that component
lib_idnostringOverride the power symbol library ID
stub_lengthnonumberWire stub length in mm

Wires accept either coordinate mode or pin-reference mode:

Coordinate mode:

FieldRequiredTypeDescription
start_xyesnumberWire start X
start_yyesnumberWire start Y
end_xyesnumberWire end X
end_yyesnumberWire end Y

Pin-reference mode:

FieldRequiredTypeDescription
from_refyesstringSource component reference
from_pinyesstringSource pin number
to_refyesstringDestination component reference
to_pinyesstringDestination pin number

Labels accept either coordinate placement or pin-reference placement (with automatic wire stub):

FieldRequiredTypeDescription
textyesstringLabel text (net name)
xcoord modenumberX position
ycoord modenumberY position
pin_refpin modestringComponent reference to attach to
pin_numberpin modestringPin number on that component
globalnobooleanTrue for global label, false for local (default: false)
rotationnonumberRotation in degrees (default: auto-calculated for pin mode)
shapenostringGlobal label shape: "bidirectional", "input", "output", etc.
directionnostringOverride label direction: "left", "right", "up", "down"
stub_lengthnonumberWire stub length in mm

Place the same net label on multiple pins simultaneously:

FieldRequiredTypeDescription
netyesstringNet name for all labels
globalnobooleanTrue for global labels (default: false)
shapenostringGlobal label shape
stub_lengthnonumberDefault stub length for all connections
connectionsyesarrayList of pin connections

Each connection in the connections array:

FieldRequiredTypeDescription
refyesstringComponent reference
pinyesstringPin number
directionnostringOverride label direction for this pin
stub_lengthnonumberOverride stub length for this pin

No-connect flags accept either coordinate or pin-reference placement:

FieldRequiredTypeDescription
xcoord modenumberX position
ycoord modenumberY position
pin_refpin modestringComponent reference
pin_numberpin modestringPin number

The following limits are enforced during validation:

LimitValue
Max components per batchConfigured in BATCH_LIMITS
Max wires per batchConfigured in BATCH_LIMITS
Max labels per batchConfigured in BATCH_LIMITS (includes label_connections)
Max total operationsConfigured in BATCH_LIMITS

Before applying, the batch tool validates:

  • All required fields are present
  • No unknown top-level keys
  • Component lib_id values reference valid libraries
  • Pin references (pin_ref, from_ref, to_ref) exist in the schematic or are declared in the same batch
  • Operation counts are within limits

Project-local symbol libraries (referenced in sym-lib-table) are automatically registered with the kicad-sch-api cache so that non-standard lib_id values resolve correctly.

When placing pin-referenced labels, the batch tool:

  1. Clamps stub length to avoid bridging adjacent pins
  2. Resolves label collisions — shifts labels that would overlap existing ones
  3. Resolves wire collisions — adjusts wire stubs that would overlap existing wire segments

The summary reports how many collisions were resolved.

On success:

{
"success": true,
"components_placed": 5,
"component_refs": ["C1", "C2", "R1", "R2", "U1"],
"power_symbols_placed": 3,
"wires_placed": 4,
"labels_placed": 6,
"no_connects_placed": 2,
"collisions_resolved": 1,
"wire_collisions_resolved": 0,
"total_operations": 20,
"batch_file": "/path/to/.mckicad/circuit.json",
"schematic_path": "/path/to/project.kicad_sch",
"engine": "kicad-sch-api"
}