Function Reference
Sketching interface for macking function printed circuit boards
- class circuitpainter.CircuitPainter(filename=None, library_path=None, preserve_origin=False)
- layers = {'B_Adhes': pcbnew.B_Adhes, 'B_CrtYd': pcbnew.B_CrtYd, 'B_Cu': pcbnew.B_Cu, 'B_Fab': pcbnew.B_Fab, 'B_Mask': pcbnew.B_Mask, 'B_Paste': pcbnew.B_Paste, 'B_SilkS': pcbnew.B_SilkS, 'Cmts_User': pcbnew.Cmts_User, 'Dwgs_User': pcbnew.Dwgs_User, 'Eco1_User': pcbnew.Eco1_User, 'Eco2_User': pcbnew.Eco2_User, 'Edge_Cuts': pcbnew.Edge_Cuts, 'F_Adhes': pcbnew.F_Adhes, 'F_CrtYd': pcbnew.F_CrtYd, 'F_Cu': pcbnew.F_Cu, 'F_Fab': pcbnew.F_Fab, 'F_Mask': pcbnew.F_Mask, 'F_Paste': pcbnew.F_Paste, 'F_SilkS': pcbnew.F_SilkS, 'In10_Cu': pcbnew.In10_Cu, 'In11_Cu': pcbnew.In11_Cu, 'In12_Cu': pcbnew.In12_Cu, 'In13_Cu': pcbnew.In13_Cu, 'In14_Cu': pcbnew.In14_Cu, 'In15_Cu': pcbnew.In15_Cu, 'In16_Cu': pcbnew.In16_Cu, 'In17_Cu': pcbnew.In17_Cu, 'In18_Cu': pcbnew.In18_Cu, 'In19_Cu': pcbnew.In19_Cu, 'In1_Cu': pcbnew.In1_Cu, 'In20_Cu': pcbnew.In20_Cu, 'In21_Cu': pcbnew.In21_Cu, 'In22_Cu': pcbnew.In22_Cu, 'In23_Cu': pcbnew.In23_Cu, 'In24_Cu': pcbnew.In24_Cu, 'In25_Cu': pcbnew.In25_Cu, 'In26_Cu': pcbnew.In26_Cu, 'In27_Cu': pcbnew.In27_Cu, 'In28_Cu': pcbnew.In28_Cu, 'In29_Cu': pcbnew.In29_Cu, 'In2_Cu': pcbnew.In2_Cu, 'In30_Cu': pcbnew.In30_Cu, 'In3_Cu': pcbnew.In3_Cu, 'In4_Cu': pcbnew.In4_Cu, 'In5_Cu': pcbnew.In5_Cu, 'In6_Cu': pcbnew.In6_Cu, 'In7_Cu': pcbnew.In7_Cu, 'In8_Cu': pcbnew.In8_Cu, 'In9_Cu': pcbnew.In9_Cu, 'Margin': pcbnew.Margin, 'Rescue': pcbnew.Rescue, 'User_1': pcbnew.User_1, 'User_2': pcbnew.User_2, 'User_3': pcbnew.User_3, 'User_4': pcbnew.User_4, 'User_5': pcbnew.User_5, 'User_6': pcbnew.User_6, 'User_7': pcbnew.User_7, 'User_8': pcbnew.User_8, 'User_9': pcbnew.User_9}
Board layers, from pcbnew
see: https://gitlab.com/kicad/code/kicad/-/blob/master/include/layer_ids.h
- __init__(filename=None, library_path=None, preserve_origin=False)
Create a Circuit Builder context
- Parameters:
filename – (optional) If specified, load the given PCB. If not specified, start with a blank PCB
library_path – (optional) Path to the footprint libraries
preserve_origin – By default, Circuit Painter translates the board origin to (40,40), so that the board will be inside of the title block. Set this to false to keep the origin at (0,0).
- width(width)
Set the width to use for drawing commands
Sets the width for objects like lines, tracks, arcs, etc.
- Parameters:
width – Width (mm)
- layer(layer)
Set the PCB drawing layer
- Parameters:
layer – Layer to use, for example “F_Cu”
- fill()
Enable fills for drawing commands
Drawing objects such as circles, rectangles, and polygons will have their fill property set to true.
- no_fill()
Disable fills for drawing commands
Drawing objects such as circles, rectangles, and polygons will have their fill property set to false.
- designators()
Enable silkscreen reference designtors for placed footprints
- no_designators()
Disable silkscreen reference designtors for placed footprints
- push_matrix()
Save the state of the current transformation matrix
- pop_matrix()
Restore the state of the last transformation matrix
- translate(x, y)
Translate all following graphics commands by the given amounts
- Parameters:
x – x translation (mm)
y – y translation (mm)
- rotate(angle)
Rotate all following graphics commands by the given angle
- Parameters:
angle – rotation angle (degrees)
- get_object_position(o)
Get a local coordinate for a PCB object
Can be a pad, footprint, etc
- Parameters:
o – Object to find coordinate for
- track(x1, y1, x2, y2, net=None)
Place a PCB track
- Parameters:
x1 – starting point (mm)
y1 – starting point (mm)
x2 – ending point (mm)
y2 – ending point (mm)
net – (optional) Net to connect track to
- arc_track(x, y, radius, start, end, net=None)
Draw an arc-shaped PCB track
Note that arc-shaped tracks are a little weirder than normal arcs. The DRC engine expects them to be connected at both ends (like a normal track), and the PCB Editor considers it a DRC violation to place certain objects (like vias) on them.
- Parameters:
x – center of arc (mm)
y – center of arc (mm)
radius – arc radius (mm)
start – starting angle of arc (degrees)
end – ending angle of arc (degrees)
net – (optional) Net to connect track to
- via(x, y, net=None, d=0.3, w=0.6)
Place a via
- Parameters:
x – via coordinate (mm)
y – via coordinate (mm)
net – (optional) name of net to connect via to
d – (optional) drill diameter (mm)
w – (optional) annular ring diameter (mm)
- poly_zone(points, net=None)
Place a polygonal zone
Zones can be placed on both copper and non-copper layers
- Parameters:
points – List of x,y coordinates that make up the polygon (mm)
net – (optional) name of net to connect zone to.
- rect_zone(x1, y1, x2, y2, net=None)
Place a rectangular zone
Zones can be placed on both copper and non-copper layers
- Parameters:
x1 – first corner of rectangle (mm)
y1 – first corner of rectangle (mm)
x2 – second corner of rectangle (mm)
y2 – second corner of rectangle (mm)
net – (optional) name ofnet to connect rectangle to
- circle_zone(x, y, radius, net=None)
Place a circular zone
Zones can be placed on both copper and non-copper layers
Note that the zone is made of a line segments that approximate the circle.
- Parameters:
x – center of circle (mm)
y – center of circle (mm)
radius – radius of circle (mm)
net – (optional) name of net to connect rectangle to
- footprint(x, y, library, name, reference='P?', angle=0, nets=None, library_path=None)
Place a footprint
Places a footprint from the given library onto the board
- Parameters:
x – x coordinate (mm)
y – y coordinate (mm)
library – Library name, relative to the system library path. To change the system library path, edit the ‘library_path’ variable. For example: ‘LED_SMD’
name – Part name, for example: LED_1210_3225Metric
reference – (optional) Reference designator to assign to part. There are three options: 1. If you don’t care about the designator, leave this as the default, and the footprints will be assigned sequential reference designators P1, P2, … 2. If you want more conventional naming, specify a leading portion of the designator followed by a question mark (for example: LED?), and the footprints will be assigned sequential reference designators based on their type. 3. If you want to assign sequence numbers yourself, specify a designator string that does not end in a question mark (for example: LED3). In this case, the supplied designator will be used without modification.
angle – (optional) Angle to rotate the part before placement (degrees)
nets – (optional) List of nets to assign to the footprint pads, in order that they are referenced in the part. Caution: Be sure to double check that the right nets are assigned! This script knows nothing about how the parts are meant to be used and will happily make connections that will damage your part.
- get_pads(reference)
Get a list of the pads in the specified footprint
- Parameters:
reference – Reference designator to retrieve pads from. For example: LED1
- line(x1, y1, x2, y2)
Draw a line from x1,y1 to x2,y2
A line is a graphical object, and can be used to make a board outline soldermask, for example, but not to make a conductive track.
- Parameters:
x1 – starting point (mm)
y1 – starting point (mm)
x2 – starting point (mm)
y2 – eneding point (mm)
- arc(x, y, radius, start, end)
Draw an arc
An arc is a graphical object, and can be used to make a board outline soldermask, for example, but not to make a conductive track.
- Parameters:
x – center of arc (mm)
y – center of arc (mm)
radius – arc radius (mm)
start – starting angle of arc (degrees)
end – ending angle of arc (degrees)
- circle(x, y, radius)
Draw a circle
A circle is a graphical object, and can be used to make a cutout in a soldermask, for example, but not to make a conductive track.
- Parameters:
x – center of circle (mm)
y – center of circle (mm)
radius – radius of circle (mm)
- poly(points)
Draw a polygon
A polygon is a graphical object, and can be used to make a cutout in a soldermask, for example, but not to make a conductive track.
- Parameters:
points – List of points to add to the polygon (mm)
- rect(x1, y1, x2, y2)
Draw a rectangle
A rectangle is a graphical object, and can be used to make a cutout in a soldermask, for example, but not to make a conductive track.
Note: Rectangles are created as polygon objects, so that they can support rotation.
- Parameters:
x1 – first corner of rectangle (mm)
y1 – first corner of rectangle (mm)
x2 – second corner of rectangle (mm)
y2 – second corner of rectangle (mm)
- text(x, y, message, angle=0, mirrored=False, bold=False, italic=False, knockout=False)
Draw text
Text is is a graphical object, and can be used to make a cutout in a soldermask, for example, but not to make a conductive track.
- Parameters:
x – x coordinate to place text (mm)
y – y coordinate to place text (mm)
message – Text string to display (single line only)
angle – angle to rotate text (degrees)
mirrored – If true, draw text backwards
bold – If true, use a bold font
italic – If true, use an italic font
knockout – If true, draw the text as a filled rect with the text cut from the rectangle
- dimension(x1, y1, x2, y2, height)
Draw a linear dimension line
Dimension lines can be used to document importanat sizes or spacings between objects. They aren’t needed by a computer to process the board files, but are helpful for humans who are inspecting board files. Common things that you might want to add dimensions for are the bounding box of the PCB edges (to show how big the PCB is), or distances between a reference point and mounting holes or test points.
Dimension lines are usually placed on the ‘Dwgs_User’ layer.
- Parameters:
x1 – starting point (mm)
y1 – starting point (mm)
x2 – ending point (mm)
y2 – ending point (mm)
height – Spacing between measured points and dimension line
- save(filename)
Save the board design to a KiCad board file
- Parameters:
filename – File name to write to
- preview()
Preview the output file in KiCad
This saves the file to a temporary loation, then opens it using pcbnew.
- export_gerber(name, output_dir='.', layers=[])
Export the design to gerbers / drill file
This saves the file to a temporary loation, uses the kicad command line interface to render gerber outputs, and finally places the gerbers in a zip file.
- Parameters:
name – Name of zip file to write to
directory – (optional) Directory to place the file in
layers – (optional) List of layers to export.
- export_svg(name, output_dir='.')
Export the design to an SVG
This saves the file to a temporary loation, uses the kicad command line interface to render an svg, then copies it to the specified location
- Parameters:
name – Name of output file
directory – (optional) Directory to place the file in
- export_step(name, output_dir='.')
Export the design to an STEP file
This saves the file to a temporary loation, uses the kicad command line interface to render a step file, then copies it to the specified location
- Parameters:
name – Name of output file
directory – (optional) Directory to place the file in
- export_pos(name, output_dir='.')
Export a pick-and-place file
This saves the file to a temporary loation, uses the kicad command line interface to render a pnp file, then copies it to the specified location
- Parameters:
name – Name of output file
directory – (optional) Directory to place the file in