Labels

The LabelOperations module handles net labels, power symbols, and hierarchical connectivity.

sch = kicad.get_schematic()
labels = sch.labels

Net Labels

add_label(name, position, orientation)

Adds a net label.

from kipy.geometry import Vector2

pos = Vector2.from_xy_mm(75, 50)
label_id = sch.labels.add_label("VCC", pos, orientation="right")

Orientation options: "right", "left", "up", "down"

add_global_label(name, position, orientation, shape)

Adds a global label for cross-sheet connectivity.

sch.labels.add_global_label(
    "DATA_BUS",
    position,
    orientation="right",
    shape="input"
)

Shape options: "input", "output", "bidirectional", "tri_state", "passive"

Power Symbols

add_power(name, position)

Adds a power symbol (GND, VCC, etc.).

gnd_pos = Vector2.from_xy_mm(50, 100)
sch.labels.add_power("GND", gnd_pos)

vcc_pos = Vector2.from_xy_mm(50, 20)
sch.labels.add_power("VCC", vcc_pos)

Common power symbols:

  • "GND" - Ground
  • "VCC" - Positive supply
  • "VDD" - Positive supply (digital)
  • "VSS" - Negative supply / Ground
  • "+5V", "+3V3", "+12V" - Specific voltages

add_power_flag(position)

Adds a PWR_FLAG symbol to satisfy ERC power pin requirements.

sch.labels.add_power_flag(position)

Hierarchical Labels

add_hierarchical_label(name, position, orientation, shape)

Adds a hierarchical label for sheet-to-sheet connectivity.

sch.labels.add_hierarchical_label(
    "CLK",
    position,
    orientation="right",
    shape="input"
)

Finding Labels

find_by_net(net_name)

Finds all labels on a specific net.

labels = sch.labels.find_by_net("VCC")
for label in labels:
    print(f"Label at {label.position}")

get_all()

Returns all labels on the current sheet.

all_labels = sch.labels.get_all()

Label Properties

set_text(label_id, text)

Changes the label text (net name).

sch.labels.set_text(label_id, "DATA0")

move(label_id, position)

Moves a label.

sch.labels.move(label_id, new_position)

delete(label_id)

Deletes a label.

sch.labels.delete(label_id)

Example: Label a Circuit

from kipy import KiCad
from kipy.geometry import Vector2

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

# Add power symbols
vcc_pos = Vector2.from_xy_mm(50, 20)
gnd_pos = Vector2.from_xy_mm(50, 100)

sch.labels.add_power("VCC", vcc_pos)
sch.labels.add_power("GND", gnd_pos)

# Add net labels
sch.labels.add_label("SDA", Vector2.from_xy_mm(120, 40), orientation="left")
sch.labels.add_label("SCL", Vector2.from_xy_mm(120, 50), orientation="left")

# Add global labels for cross-sheet nets
sch.labels.add_global_label(
    "I2C_SDA",
    Vector2.from_xy_mm(150, 40),
    orientation="right",
    shape="bidirectional"
)

Example: Power Distribution

# Create power rails with multiple connection points
power_points = [
    Vector2.from_xy_mm(50, 20),
    Vector2.from_xy_mm(100, 20),
    Vector2.from_xy_mm(150, 20),
]

ground_points = [
    Vector2.from_xy_mm(50, 100),
    Vector2.from_xy_mm(100, 100),
    Vector2.from_xy_mm(150, 100),
]

for pos in power_points:
    sch.labels.add_power("VCC", pos)

for pos in ground_points:
    sch.labels.add_power("GND", pos)