Zones

The ZoneOperations module handles copper pour zones and rule areas.

board = kicad.get_board()
zones = board.zones

Creating Zones

add_zone(polygon, layer, net=None)

Creates a copper zone.

from kipy.geometry import Vector2
from kipy.board import BoardLayer

# Define zone boundary
boundary = [
    Vector2.from_xy_mm(10, 10),
    Vector2.from_xy_mm(90, 10),
    Vector2.from_xy_mm(90, 90),
    Vector2.from_xy_mm(10, 90),
]

zone_id = board.zones.add_zone(
    polygon=boundary,
    layer=BoardLayer.BL_F_Cu,
    net="GND"
)

add_zone_rectangle(position, size, layer, net)

Creates a rectangular zone.

board.zones.add_zone_rectangle(
    position=Vector2.from_xy_mm(10, 10),
    size=Vector2.from_xy_mm(80, 80),
    layer=BoardLayer.BL_F_Cu,
    net="GND"
)

Zone Settings

set_clearance(zone_id, clearance_mm)

Sets the zone clearance.

board.zones.set_clearance(zone_id, clearance_mm=0.3)

set_min_thickness(zone_id, thickness_mm)

Sets the minimum track width in zone.

board.zones.set_min_thickness(zone_id, thickness_mm=0.25)

set_thermal_settings(zone_id, ...)

Configures thermal relief settings.

board.zones.set_thermal_settings(
    zone_id,
    thermal_gap_mm=0.5,
    thermal_spoke_width_mm=0.5,
    thermal_spokes=4
)

set_priority(zone_id, priority)

Sets zone fill priority (higher = fills first).

board.zones.set_priority(zone_id, priority=1)

Filling Zones

fill(zone_id)

Fills a specific zone.

board.zones.fill(zone_id)

fill_all()

Fills all zones on the board.

board.zones.fill_all()

unfill(zone_id)

Removes zone fill.

board.zones.unfill(zone_id)

Rule Areas (Keepouts)

add_rule_area(polygon, ...)

Creates a rule area (keepout zone).

keepout = [
    Vector2.from_xy_mm(40, 40),
    Vector2.from_xy_mm(60, 40),
    Vector2.from_xy_mm(60, 60),
    Vector2.from_xy_mm(40, 60),
]

board.zones.add_rule_area(
    polygon=keepout,
    no_tracks=True,
    no_vias=True,
    no_pours=True,
    layers=[BoardLayer.BL_F_Cu, BoardLayer.BL_B_Cu]
)

Getting Zones

get_all()

Gets all zones on the board.

zones = board.zones.get_all()

for zone in zones:
    print(f"Zone on {zone.layer}, net: {zone.net}")

get_zone(zone_id)

Gets zone details.

zone = board.zones.get_zone(zone_id)
print(f"Net: {zone.net}")
print(f"Priority: {zone.priority}")
print(f"Filled: {zone.is_filled}")

Modifying Zones

set_net(zone_id, net_name)

Changes the zone's net.

board.zones.set_net(zone_id, "VCC")

delete(zone_id)

Deletes a zone.

board.zones.delete(zone_id)

Example: Ground Plane

from kipy import KiCad
from kipy.geometry import Vector2
from kipy.board import BoardLayer

kicad = KiCad()
board = kicad.get_board()

# Get board outline (simplified - assumes rectangular)
outline = [
    Vector2.from_xy_mm(0, 0),
    Vector2.from_xy_mm(100, 0),
    Vector2.from_xy_mm(100, 80),
    Vector2.from_xy_mm(0, 80),
]

# Create ground plane on back copper
gnd_zone = board.zones.add_zone(
    polygon=outline,
    layer=BoardLayer.BL_B_Cu,
    net="GND"
)

# Configure
board.zones.set_clearance(gnd_zone, 0.3)
board.zones.set_min_thickness(gnd_zone, 0.2)
board.zones.set_thermal_settings(
    gnd_zone,
    thermal_gap_mm=0.5,
    thermal_spoke_width_mm=0.5
)

# Fill the zone
board.zones.fill(gnd_zone)

print("Ground plane created and filled")

Example: Power Island

# Create a VCC island zone
vcc_area = [
    Vector2.from_xy_mm(60, 10),
    Vector2.from_xy_mm(95, 10),
    Vector2.from_xy_mm(95, 40),
    Vector2.from_xy_mm(60, 40),
]

vcc_zone = board.zones.add_zone(
    polygon=vcc_area,
    layer=BoardLayer.BL_In1_Cu,  # Inner layer
    net="VCC"
)

# Higher priority than GND
board.zones.set_priority(vcc_zone, 2)

# Fill
board.zones.fill(vcc_zone)

Example: Keepout Under Antenna

# Create keepout zone under antenna area
antenna_keepout = [
    Vector2.from_xy_mm(70, 5),
    Vector2.from_xy_mm(95, 5),
    Vector2.from_xy_mm(95, 25),
    Vector2.from_xy_mm(70, 25),
]

board.zones.add_rule_area(
    polygon=antenna_keepout,
    no_tracks=False,      # Allow signal tracks
    no_vias=True,         # No vias
    no_pours=True,        # No copper pour
    layers=[BoardLayer.BL_F_Cu, BoardLayer.BL_B_Cu,
            BoardLayer.BL_In1_Cu, BoardLayer.BL_In2_Cu]
)

Zone Fill Modes

Zones support different fill modes:

  • Solid - Solid copper fill (default)
  • Hatched - Cross-hatch pattern
  • None - Unfilled (outline only)