Wiring
The WiringOperations module handles wire creation and routing.
sch = kicad.get_schematic()
wiring = sch.wiring
Creating Wires
add_wire(points)
Creates a wire along a series of points.
from kipy.geometry import Vector2
start = Vector2.from_xy_mm(50, 50)
end = Vector2.from_xy_mm(100, 50)
wire_id = sch.wiring.add_wire([start, end])
For L-shaped or multi-segment wires:
p1 = Vector2.from_xy_mm(50, 50)
p2 = Vector2.from_xy_mm(75, 50)
p3 = Vector2.from_xy_mm(75, 75)
wire_id = sch.wiring.add_wire([p1, p2, p3])
wire_pins(symbol1, pin1, symbol2, pin2)
Automatically wires two pins together.
# Wire R1 pin 2 to R2 pin 1
sch.wiring.wire_pins(r1_id, "2", r2_id, "1")
This method automatically determines the best path between pins.
wire_to_point(symbol, pin, point)
Wires a pin to a specific point.
point = Vector2.from_xy_mm(100, 100)
sch.wiring.wire_to_point(symbol_id, "1", point)
Junctions
add_junction(position)
Adds a junction (connection dot) at a position.
junction_pos = Vector2.from_xy_mm(75, 50)
junction_id = sch.wiring.add_junction(junction_pos)
Junctions are automatically added when wires cross and connect.
No-Connect Flags
add_no_connect(position)
Adds a no-connect flag to mark intentionally unconnected pins.
pin_pos = sch.symbols.get_pins(symbol_id)[0].position
sch.wiring.add_no_connect(pin_pos)
Bus Entry
add_bus_entry(position, direction)
Adds a bus entry point.
sch.wiring.add_bus_entry(position, direction="right")
Example: Wire Multiple Components
from kipy import KiCad
from kipy.geometry import Vector2
kicad = KiCad()
sch = kicad.get_schematic()
# Place components
pos_r1 = Vector2.from_xy_mm(50, 50)
pos_r2 = Vector2.from_xy_mm(100, 50)
pos_c1 = Vector2.from_xy_mm(75, 75)
r1 = sch.symbols.add("Device:R", pos_r1, reference="R1")
r2 = sch.symbols.add("Device:R", pos_r2, reference="R2")
c1 = sch.symbols.add("Device:C", pos_c1, reference="C1", rotation=90)
# Wire R1 to R2
sch.wiring.wire_pins(r1, "2", r2, "1")
# Wire junction point to capacitor
junction = Vector2.from_xy_mm(75, 50)
sch.wiring.add_junction(junction)
sch.wiring.add_wire([junction, Vector2.from_xy_mm(75, 75)])
Example: Create a Bus
# Create a vertical bus
bus_start = Vector2.from_xy_mm(150, 30)
bus_end = Vector2.from_xy_mm(150, 100)
sch.wiring.add_bus([bus_start, bus_end])
# Add bus entries
for i in range(4):
entry_pos = Vector2.from_xy_mm(150, 40 + i * 15)
sch.wiring.add_bus_entry(entry_pos, direction="left")
Getting Wire Info
get_wires()
Returns all wires on the current sheet.
wires = sch.wiring.get_wires()
for wire in wires:
print(f"Wire from {wire.start} to {wire.end}")
get_wire_net(wire_id)
Gets the net name of a wire.
net_name = sch.wiring.get_wire_net(wire_id)
print(f"Wire is on net: {net_name}")