Footprints
The FootprintOperations module handles footprint placement and manipulation.
board = kicad.get_board()
footprints = board.footprints
Placing Footprints
place(lib_id, position, ...)
Places a footprint on the board.
from kipy.geometry import Vector2
pos = Vector2.from_xy_mm(100, 50)
# Basic placement
fp = board.footprints.place("Package_SO:SOIC-8_3.9x4.9mm_P1.27mm", pos)
# With rotation
fp = board.footprints.place("Resistor_SMD:R_0603_1608Metric", pos, rotation=90)
# With layer (front or back)
from kipy.board import BoardLayer
fp = board.footprints.place(
"Package_QFP:LQFP-48_7x7mm_P0.5mm",
pos,
layer=BoardLayer.BL_B_Cu # Place on back
)
# With reference designator
fp = board.footprints.place("Resistor_SMD:R_0603", pos, reference="R10")
Finding Footprints
find_by_reference(reference)
Finds a footprint by reference designator.
fp_id = board.footprints.find_by_reference("U1")
get_all()
Gets all footprints on the board.
footprints = board.footprints.get_all()
for fp in footprints:
print(f"{fp.reference}: {fp.lib_id} at {fp.position}")
Footprint Properties
get_pads(footprint_id)
Gets all pads of a footprint.
pads = board.footprints.get_pads(fp_id)
for pad in pads:
print(f"Pad {pad.number}: {pad.position} on {pad.layer}")
get_fields(footprint_id)
Gets footprint fields (value, etc.).
fields = board.footprints.get_fields(fp_id)
set_field(footprint_id, field, value)
Sets a footprint field.
board.footprints.set_field(fp_id, "Value", "100nF")
Manipulation
move(footprint_id, position)
Moves a footprint.
new_pos = Vector2.from_xy_mm(120, 60)
board.footprints.move(fp_id, new_pos)
rotate(footprint_id, angle)
Rotates a footprint.
board.footprints.rotate(fp_id, 45) # Rotate 45 degrees
flip(footprint_id)
Flips a footprint to the other side of the board.
board.footprints.flip(fp_id) # Move from front to back (or vice versa)
delete(footprint_id)
Deletes a footprint.
board.footprints.delete(fp_id)
Example: Place Components
from kipy import KiCad
from kipy.geometry import Vector2
from kipy.board import BoardLayer
kicad = KiCad()
board = kicad.get_board()
# Place an IC
ic_pos = Vector2.from_xy_mm(100, 100)
ic = board.footprints.place(
"Package_QFP:LQFP-48_7x7mm_P0.5mm",
ic_pos,
reference="U1"
)
# Place decoupling caps near IC
cap_positions = [
Vector2.from_xy_mm(95, 92),
Vector2.from_xy_mm(105, 92),
Vector2.from_xy_mm(95, 108),
Vector2.from_xy_mm(105, 108),
]
for i, pos in enumerate(cap_positions):
board.footprints.place(
"Capacitor_SMD:C_0402_1005Metric",
pos,
reference=f"C{i+1}",
rotation=90 if i % 2 else 0
)
print("Components placed")
Example: Arrange Footprints in Grid
# Get all resistors
footprints = board.footprints.get_all()
resistors = [fp for fp in footprints if fp.reference.startswith("R")]
# Arrange in a grid
cols = 5
spacing = 5 # mm
for i, fp in enumerate(resistors):
col = i % cols
row = i // cols
pos = Vector2.from_xy_mm(10 + col * spacing, 10 + row * spacing)
board.footprints.move(fp.id, pos)
Example: Flip Components to Back
# Find all components that should be on the back
back_components = ["U2", "U3", "J2"]
for ref in back_components:
fp_id = board.footprints.find_by_reference(ref)
if fp_id:
board.footprints.flip(fp_id)
print(f"Flipped {ref} to back")
Footprint Info Structure
class FootprintInstance:
id: str # Unique identifier (KIID)
reference: str # Reference designator
lib_id: str # Library ID
position: Vector2 # Position on board
rotation: float # Rotation in degrees
layer: BoardLayer # Front or back copper
locked: bool # Is position locked