Graphics
The GraphicsOperations module handles graphical elements on PCBs.
board = kicad.get_board()
graphics = board.graphics
Lines
add_line(start, end, layer, width_mm=0.1)
Draws a line.
from kipy.geometry import Vector2
from kipy.board import BoardLayer
start = Vector2.from_xy_mm(10, 10)
end = Vector2.from_xy_mm(50, 10)
board.graphics.add_line(
start, end,
layer=BoardLayer.BL_F_SilkS,
width_mm=0.15
)
Rectangles
add_rectangle(position, size, layer, width_mm=0.1)
Draws a rectangle.
board.graphics.add_rectangle(
position=Vector2.from_xy_mm(10, 10),
size=Vector2.from_xy_mm(30, 20),
layer=BoardLayer.BL_F_SilkS
)
add_filled_rectangle(position, size, layer)
Draws a filled rectangle.
board.graphics.add_filled_rectangle(
position=Vector2.from_xy_mm(10, 10),
size=Vector2.from_xy_mm(30, 20),
layer=BoardLayer.BL_F_SilkS
)
Circles
add_circle(center, radius_mm, layer, width_mm=0.1)
Draws a circle.
board.graphics.add_circle(
center=Vector2.from_xy_mm(50, 50),
radius_mm=10,
layer=BoardLayer.BL_F_SilkS
)
add_filled_circle(center, radius_mm, layer)
Draws a filled circle.
board.graphics.add_filled_circle(
center=Vector2.from_xy_mm(50, 50),
radius_mm=5,
layer=BoardLayer.BL_F_SilkS
)
Arcs
add_arc(center, radius_mm, start_angle, end_angle, layer, width_mm=0.1)
Draws an arc.
board.graphics.add_arc(
center=Vector2.from_xy_mm(50, 50),
radius_mm=15,
start_angle=0,
end_angle=90,
layer=BoardLayer.BL_F_SilkS
)
Polygons
add_polygon(points, layer)
Draws a polygon.
points = [
Vector2.from_xy_mm(10, 10),
Vector2.from_xy_mm(30, 10),
Vector2.from_xy_mm(20, 30),
]
board.graphics.add_polygon(
points=points,
layer=BoardLayer.BL_F_SilkS
)
Text
add_text(text, position, layer, ...)
Adds text.
board.graphics.add_text(
text="REV A",
position=Vector2.from_xy_mm(50, 5),
layer=BoardLayer.BL_F_SilkS,
size_mm=1.5,
thickness_mm=0.15,
bold=False,
italic=False,
rotation=0
)
Dimensions
add_dimension(start, end, ...)
Adds a dimension annotation.
board.graphics.add_dimension(
start=Vector2.from_xy_mm(10, 10),
end=Vector2.from_xy_mm(90, 10),
layer=BoardLayer.BL_F_Fab,
height_mm=5
)
Board Outline
set_board_outline(points)
Sets the board outline.
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),
]
board.graphics.set_board_outline(outline)
add_mounting_hole(position, diameter_mm)
Adds a mounting hole to the board outline.
# Add mounting holes in corners
positions = [
Vector2.from_xy_mm(5, 5),
Vector2.from_xy_mm(95, 5),
Vector2.from_xy_mm(95, 75),
Vector2.from_xy_mm(5, 75),
]
for pos in positions:
board.graphics.add_mounting_hole(pos, diameter_mm=3.2)
Example: Add Silkscreen Logo
from kipy import KiCad
from kipy.geometry import Vector2
from kipy.board import BoardLayer
kicad = KiCad()
board = kicad.get_board()
# Draw a simple logo (company initials in a box)
logo_x, logo_y = 45, 2
# Box
board.graphics.add_rectangle(
position=Vector2.from_xy_mm(logo_x, logo_y),
size=Vector2.from_xy_mm(10, 5),
layer=BoardLayer.BL_F_SilkS,
width_mm=0.15
)
# Text
board.graphics.add_text(
text="ACE",
position=Vector2.from_xy_mm(logo_x + 5, logo_y + 2.5),
layer=BoardLayer.BL_F_SilkS,
size_mm=2,
thickness_mm=0.2,
justify="center"
)
Example: Create Board Outline with Rounded Corners
import math
# Board size
width, height = 100, 80
corner_radius = 5
# Generate outline with rounded corners
points = []
steps = 8 # Points per corner
# Bottom-left corner
for i in range(steps + 1):
angle = math.pi + (math.pi / 2) * (i / steps)
x = corner_radius + corner_radius * math.cos(angle)
y = corner_radius + corner_radius * math.sin(angle)
points.append(Vector2.from_xy_mm(x, y))
# Bottom-right corner
for i in range(steps + 1):
angle = (3 * math.pi / 2) + (math.pi / 2) * (i / steps)
x = width - corner_radius + corner_radius * math.cos(angle)
y = corner_radius + corner_radius * math.sin(angle)
points.append(Vector2.from_xy_mm(x, y))
# Top-right corner
for i in range(steps + 1):
angle = 0 + (math.pi / 2) * (i / steps)
x = width - corner_radius + corner_radius * math.cos(angle)
y = height - corner_radius + corner_radius * math.sin(angle)
points.append(Vector2.from_xy_mm(x, y))
# Top-left corner
for i in range(steps + 1):
angle = (math.pi / 2) + (math.pi / 2) * (i / steps)
x = corner_radius + corner_radius * math.cos(angle)
y = height - corner_radius + corner_radius * math.sin(angle)
points.append(Vector2.from_xy_mm(x, y))
board.graphics.set_board_outline(points)
Example: Add Fabrication Notes
# Add fab notes on Fab layer
notes = [
"MATERIAL: FR4 TG150",
"THICKNESS: 1.6mm",
"COPPER: 1oz",
"FINISH: ENIG",
]
y = 85
for note in notes:
board.graphics.add_text(
text=note,
position=Vector2.from_xy_mm(5, y),
layer=BoardLayer.BL_F_Fab,
size_mm=1.0,
thickness_mm=0.1
)
y += 3