Schematic API

The Schematic API provides operations for working with schematic documents. Get a Schematic object from the KiCad instance:

from kipy import KiCad

kicad = KiCad()
sch = kicad.get_schematic()

Operations Modules

The Schematic object provides access to several operation modules:

PropertyModuleDescription
sch.crudCRUDOperationsCreate, read, update, delete items
sch.symbolsSymbolOperationsSymbol placement and manipulation
sch.wiringWiringOperationsWire creation and routing
sch.labelsLabelOperationsNet labels and power symbols
sch.sheetsSheetOperationsHierarchical sheet management
sch.ercERCOperationsElectrical rules checking
sch.graphicsGraphicsOperationsText, shapes, annotations
sch.pagePageOperationsPage settings and title block
sch.libraryLibraryOperationsSymbol library search
sch.selectionSelectionOperationsEditor selection
sch.connectivityConnectivityOperationsNet and bus queries
sch.transformTransformOperationsMove, rotate, mirror, align
sch.busesBusOperationsBus definition and routing

Quick Example

from kipy import KiCad
from kipy.geometry import Vector2

kicad = KiCad()
sch = kicad.get_schematic()

# Place symbols
pos1 = Vector2.from_xy_mm(50, 50)
pos2 = Vector2.from_xy_mm(80, 50)

r1 = sch.symbols.add("Device:R", pos1)
r2 = sch.symbols.add("Device:R", pos2)

# Wire them together
sch.wiring.wire_pins(r1, "2", r2, "1")

# Add power symbols
gnd_pos = Vector2.from_xy_mm(50, 70)
sch.labels.add_power("GND", gnd_pos)

# Run ERC
result = sch.erc.run()
print(f"ERC: {len(result.errors)} errors, {len(result.warnings)} warnings")

# Save
sch.document.save()

Document Operations

# Save the schematic
sch.document.save()

# Get document info
print(sch.document.path)  # File path
print(sch.document.name)  # Document name

Working with Items

All schematic items have a unique ID (KIID). You can retrieve items by ID:

# Get all items
items = sch.crud.get_items()

# Get specific item by ID
item = sch.crud.get_item(item_id)

# Delete items
sch.crud.delete_items([item_id1, item_id2])

Coordinate System

Schematic coordinates use internal units (IU). The Vector2 class provides convenience methods:

from kipy.geometry import Vector2

# Create from millimeters
pos = Vector2.from_xy_mm(50, 50)

# Create from mils (1/1000 inch)
pos = Vector2.from_xy_mils(2000, 2000)

# Access values
print(pos.x, pos.y)  # Internal units
print(pos.x_mm, pos.y_mm)  # Millimeters

Next Steps

  • Symbols - Placing and manipulating symbols
  • Wiring - Creating wires and connections
  • Labels - Net labels and power symbols
  • ERC - Electrical rules checking