footprinter.py gEDA PCB Footprint Generator
version 0.1
footprinter.py gives you a set of classes for generating footprint files as used by the PCB program.
By importing footprinter in a very small Python program, you have all the facilities of Python, when you need then, to create your part footprints.
Differences from version 0.0:
- The "clearance" parameter initializing the Pad and Pin classes has been renamed to "trace_clearance".
- The "mask" parameter initializing the Pad and Pin classes has been replaced by a "mask_clearance" parameter.
The new parameter specifies the gap between the edge of the Pad or Pin and the solder mask.
- A "description" parameter initializing the Footprint class has been added to fill in the element's description field.
A simple source file looks like this:
#!/usr/bin/env python
'''Footprint -- Holes, outline for 4-lead cylindrical W02 bridge rectifier.
'''
from footprinter import inch, mil, mm, Footprint, Pad, Pin, ElementArc, ElementLine
fp = Footprint (
[
Pin (1, inch(-.2), inch(-.1), mil(100), mil(25), mil(2), mil(49), sflags='square'), #+ positive
Pin (2, inch(.2), inch(.1), mil(100), mil(25), mil(2), mil(49)), #~ AC
Pin (3, inch(.1), inch(-.2), mil(100), mil(25), mil(2), mil(49)), #- negative
Pin (4, inch(-.1), inch(.2), mil(100), mil(25), mil(2), mil(49)), #~ AC
],
[
ElementArc (0,0, inch(.27),inch(.27), 0,360, inch(.01))
]
, description="W02 bridge rectifier"
)
fp.file_element ('W02.fp')
The import statement brings in these functions and classes:
- inch, mil, mm
- give you functions to specify units of measure for sizes and coordinates.
- Footprint
- is a Python class that collects all the information describing a footprint.
The arguments for Footprint are:
- padpins
- a Python list of all the Pad and Pin instances (see below) included in this footprint.
Empty if omitted.
- linearcs
- a Python list of all the ElementArc and ElementLine instances (see below) included in this footprint.
Empty if omitted.
- sflags
- the comma-separated flag symbols for the footprint file "Element" line. Blank if omitted.
- description
- A descriptive string for this footprint. Blank if omitted.
- Pad
- collects all the information describing a pad in the footprint. The parameters are
- number
- the part's pin number associated with this pad
- padrect
- a 4-item Python list or tuple containing the x- and y-coordinates of the diagonally opposite corners of this pad's copper rectangle: e.g.
(x1,y1, x2,y2)
for corner#1 and corner#2.
- trace_clearance
- the clearance value for the footprint file "Pad" line
- mask_clearance
- width of the gap between each edge of the copper pad and the solder mask. (In the older release, this parameter gave the entire width of the mask.)
- name
- the name value for the footprint file "Pad" line. Blank if omitted.
- sflags
- the comma-separated flag symbols for the footprint file "Pad" line. Blank if omitted.
- Pin
- collects all the information describing a pin in the footprint. The parameters are
- number
- the part's pin number associated with this pin
- rx
- the X-coordinate of the center of this pin
- ry
- the Y-coordinate of the center of this pin
- thickness
- the thickness value for the footprint file "Pin" line
- trace_clearance
- the clearance value for the footprint file "Pin" line
- mask_clearance
- width of the gap between the edge of the copper pin and the solder mask. (In the older release, this parameter gave the entire width of the mask.)
- drill
- the drill diameter value for the footprint file "Pin" line
- name
- the name value for the footprint file "Pin" line. Blank if omitted.
- sflags
- the comma-separated flag symbols for the footprint file "Pin" line. Blank if omitted.
- ElementArc
- collects all the information describing an arc in the footprint. The parameters are:
- rx
- the X-coordinate of the center of this arc
- ry
- the Y-coordinate of the center of this arc
- width
- the thickness value for the footprint file "ElementArc" line
- height
- the height value for the footprint file "ElementArc" line
- start_angle
- the start_angle value for the footprint file "ElementArc" line
- delta_angle
- the delta_angle value for the footprint file "ElementArc" line
- thickness
- the thickness value for the footprint file "ElementArc" line
- ElementLine
- collects all the information describing an arc in the footprint. The parameters are:
- rx1
- the X-coordinate of the start point of the line
- ry1
- the Y-coordinate of the start point of the line
- rx2
- the X-coordinate of the end point of the line
- ry2
- the Y-coordinate of the end point of the line
- thickness
- the thickness of the line
All coordinates are relative to the notional "center" of the part that you select.
Since the footprint source file is actually Python, you can make your specifications clearer by using named arguments, e.g.
ElementArc (rx=0,ry=0, width=inch(.27),height=inch(.27), start_angle=0,delta_angle=360, thickness=inch(.01))
You can also define functions and use if-statements and loops to avoid cumbersome boilerplate code in your definitions.
With all the information for the footprint complete, use the file_element method to write the .fp footprint file for PCB.
The argument for the file_element method is the path to the file to be written.

footprinter.py by Mel Wilson <mwilson@melwilsonsoftware.ca> is licensed under a Creative Commons Attribution 3.0 Unported License.