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:
| Property | Module | Description |
|---|---|---|
sch.crud | CRUDOperations | Create, read, update, delete items |
sch.symbols | SymbolOperations | Symbol placement and manipulation |
sch.wiring | WiringOperations | Wire creation and routing |
sch.labels | LabelOperations | Net labels and power symbols |
sch.sheets | SheetOperations | Hierarchical sheet management |
sch.erc | ERCOperations | Electrical rules checking |
sch.graphics | GraphicsOperations | Text, shapes, annotations |
sch.page | PageOperations | Page settings and title block |
sch.library | LibraryOperations | Symbol library search |
sch.selection | SelectionOperations | Editor selection |
sch.connectivity | ConnectivityOperations | Net and bus queries |
sch.transform | TransformOperations | Move, rotate, mirror, align |
sch.buses | BusOperations | Bus 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