# Using Python scripts to create Eagle parts

I dread creating part models in Eagle – it’s time consuming and error prone.

Over the years I have used scripting languages to help with the tedious work. It’s quite easy to create basic part footprint algorithms given the mechanical drawing. Much more tedious would be drawing a picture on graph paper and using your calculator.

If you’ve ever made a circuit board and made a very basic error that caused you to have to remanufacture your board, you’ll understand the value of getting it right the first time around.

Take this extremely simple script for example:

```#!/usr/bin/python
x=0.0
y=0.0
pins=24
print 'EDIT TSSOP_' + str(pins) + '.pac'
for p in range(1, pins/2+1):
x = (p-1)*0.5
y = -4.15
print 'SMD 0.27 1.0 \'' + str(p) + '\' (' + str(x) +' ' + str(y) + ');'
print 'SMD 0.27 1.0 \'' + str(pins+1-p) + '\' (' + str(x) +' ' + str(-y) + ');'```

You could really write this in any language and it would be about the same length. There’s no reason it has to be done in Python. The value is in what it prints out:

```EDIT TSSOP_24.pac
SMD 0.27 1.0 '1' (0.0 -4.15);
SMD 0.27 1.0 '24' (0.0 4.15);
SMD 0.27 1.0 '2' (0.5 -4.15);
SMD 0.27 1.0 '23' (0.5 4.15);
SMD 0.27 1.0 '3' (1.0 -4.15);
SMD 0.27 1.0 '22' (1.0 4.15);
SMD 0.27 1.0 '4' (1.5 -4.15);
SMD 0.27 1.0 '21' (1.5 4.15);
SMD 0.27 1.0 '5' (2.0 -4.15);
SMD 0.27 1.0 '20' (2.0 4.15);
SMD 0.27 1.0 '6' (2.5 -4.15);
SMD 0.27 1.0 '19' (2.5 4.15);
SMD 0.27 1.0 '7' (3.0 -4.15);
SMD 0.27 1.0 '18' (3.0 4.15);
SMD 0.27 1.0 '8' (3.5 -4.15);
SMD 0.27 1.0 '17' (3.5 4.15);
SMD 0.27 1.0 '9' (4.0 -4.15);
SMD 0.27 1.0 '16' (4.0 4.15);
SMD 0.27 1.0 '10' (4.5 -4.15);
SMD 0.27 1.0 '15' (4.5 4.15);
SMD 0.27 1.0 '11' (5.0 -4.15);
SMD 0.27 1.0 '14' (5.0 4.15);
SMD 0.27 1.0 '12' (5.5 -4.15);
SMD 0.27 1.0 '13' (5.5 4.15);```

If you open up the EAGLE Library editor and paste this script into the command console, you get this:

The same technique applies for much larger parts. Imagine how much time you’ll save when you’re creating a part model for a 256+ ball grid array?

I must say I don’t claim to be an expert Python coder – I have my own specialties and I’m really a low-level embedded systems guy. If you need a turn-key shoe-phone (that’s a joke) or a radio watch (if you don’t get the joke you’re too young) or an accelerometer based movement tracker with 6 months battery life, I’m your man.

I’m just rambling – back on topic: there’s another script I wrote that you can access via pastebin (click “see original”)
[iframe src=”http://pastebin.com/embed_iframe.php?i=2RqWXs83″ style=”border:none;width:100%”][/iframe]

This script takes a CSV file and a model name as command line options, i.e:

`\$ ~/bin/csv2model.py sn74.csv sn74vme22501a`

And produces helpful Eagle SCR data that you can call from Eagle to make a schematic symbol, and also to CONNECT the schematic part model PINs to the physical layout PADs. i.e:

```EDIT sn74vme22501a.sym;
PIN '1OEBY' Short (0 0.0)
PIN '1A' Short (0 -0.1)
PIN '1Y' Short (0 -0.2)
PIN 'GND' Short (0 -0.3)
PIN '2A' Short (0 -0.4)
PIN '2Y' Short (0 -0.5)
PIN 'VCC' Short (0 -0.6)
PIN '!2OEBY' Short (0 -0.7)
PIN '3A1' Short (0 -0.8)
PIN 'GND_2' Short (0 -0.9)
PIN 'LE' Short (0 -1.0)
PIN '3A2' Short (0 -1.1)
PIN '3A3' Short (0 -1.2)
PIN 'OE' Short (0 -1.3)
PIN 'GND_3' Short (0 -1.4)```

and:

```CONNECT sn74vme22501a.1OEBY 1;
CONNECT sn74vme22501a.1A 2;
CONNECT sn74vme22501a.1Y 3;
CONNECT sn74vme22501a.GND 4;
CONNECT sn74vme22501a.2A 5;
CONNECT sn74vme22501a.2Y 6;
CONNECT sn74vme22501a.VCC 7;
CONNECT sn74vme22501a.!2OEBY 8;
CONNECT sn74vme22501a.3A1 9;
CONNECT sn74vme22501a.GND_2 10;
CONNECT sn74vme22501a.LE 11;
CONNECT sn74vme22501a.3A2 12;
CONNECT sn74vme22501a.3A3 13;
CONNECT sn74vme22501a.OE 14;
CONNECT sn74vme22501a.GND_3 15;```

The CSV file contains (partially):

```PIN,NAME
1,1OEBY
2,1A
3,1Y
4,GND
5,2A
6,2Y
7,VCC
8,!2OEBY
9,3A1
10,GND
11,LE
12,3A2
13,3A3
14,OE
15,GND```

Here’s another script I generated for the FT256 / FTG256 package which is used by some Xilinx FPGAs:

```#!/usr/bin/python
# Create BGA SCR for Eagle 5.x
print 'GRID MM;'```
```rows = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'T']
cols = ['1', '2', '3', '4', '5', '6', '7', '8', '9' ,'10', '11', '12', '13', '14', '15', '16']
nrows = 16
ncols = 16
pitch = 1.0 # ball spacing in millimeters
```xstart = -(nrows - 1) / 2.0
ystart = (ncols - 1) / 2.0
x = xstart
y = ystart```
```for row in rows:
x=xstart
for col in cols:
print 'SMD ' + str(padsize) + ' ' + str(padsize) + ' -100 \'' + row + col + '\' (' + str(x) +' ' + str(y) + ');'
x=x+pitch
y=y-pitch```
```print 'LAYER 21;' #tplace
print 'WIRE .254MM (' + str(x) + ' ' + str(y) + ') (' + str(-x) + ' ' + str(y) + '); '
print 'WIRE .254MM (' + str(-x) + ' ' + str(y) + ') (' + str(-x) + ' ' + str(-y) + '); '
print 'WIRE .254MM (' + str(-x) + ' ' + str(-y) + ') (' + str(x) + ' ' + str(-y) + '); '
print 'WIRE .254MM (' + str(x) + ' ' + str(-y) + ') (' + str(x) + ' ' + str(y) + '); '

print 'LAYER 25; \n\
TEXT \'>NAME\' ('+ str(-x) +' '+ str(-y+.5) +'); \n\
CHANGE SIZE 0.05IN ('+ str(-x) +' '+ str(-y+.5) +'); \n\
CHANGE RATIO 20% ('+ str(-x) +' '+ str(-y+.5) +'); \n\
CHANGE FONT VECTOR ('+ str(-x) +' '+ str(-y+.5) +'); \n\
LAYER 27; \n\
TEXT \'>VALUE\' ('+ str(-x) +' '+ str(-y+2.5) +'); \n\
CHANGE SIZE 0.05IN ('+ str(-x) +' '+ str(-y+2.5) +');\n\
CHANGE RATIO 20% ('+ str(-x) +' '+ str(-y+2.5) +'); \n\
CHANGE FONT VECTOR ('+ str(-x) +' '+ str(-y+2.5) +');\n\
LAYER 51; \n\
TEXT \'>NAME\' (0 0); \n\
CHANGE SIZE 0.03IN (0 0); \n\
CHANGE RATIO 10% (0 0); \n\
CHANGE FONT VECTOR (0 0); \n\
'```

[iframe src=”http://pastebin.com/embed_iframe.php?i=0RSLWxWM” style=”border:none;width:100%”][/iframe]

And here’s what it produces, which can be run right in the Eagle Library editor:

[iframe src=”http://pastebin.com/embed_iframe.php?i=VMTYQPnK” style=”border:none;width:100%”][/iframe]

Which produces this in Eagle 5.x:

## Join the Conversation

1. Brianna says:

This is very helpful. Thank you for posting!

2. Nuno says:

With the newer versions of eagle ( v 6.x ) you can actually create parts and libraries directly in XML.

1. martin says:

I haven’t tried that yet. It would be trivial to write scripts to generate entire parts then instead of piecemeal Eagle-SCR.
I would be very excited if they exposed a Python API. Much of electronics can be parametrically designed.