Skip to content

Instantly share code, notes, and snippets.

@omerk
Created January 21, 2014 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omerk/8549302 to your computer and use it in GitHub Desktop.
Save omerk/8549302 to your computer and use it in GitHub Desktop.
Converts rectangles to SMD pads in Eagle 6.x libraries. Since this is essentially a quick hack, you should isolate the package you are working with into a new library and copy the resultant pad data into the file manually.
import sys
from xml.dom import minidom
def main():
print "Opening " + sys.argv[1]
xmldoc = minidom.parse(sys.argv[1])
rects = xmldoc.getElementsByTagName('rectangle')
print "Found " + str(len(rects)) + " rectangles"
count = 0;
for r in rects:
dx = float(r.attributes['y2'].value) - float(r.attributes['y1'].value)
dy = float(r.attributes['x2'].value) - float(r.attributes['x1'].value)
x = (dy / 2) + float(r.attributes['x1'].value)
y = (dx / 2) + float(r.attributes['y1'].value)
print '<smd name="RP${0}" x="{1}" y="{2}" dx="{3}" dy="{4}" layer="16" rot="R90"/>'.format(count, x, y, dx, dy)
count += 1
if __name__ == "__main__":
if len(sys.argv) < 2:
print "Usage: " + sys.argv[0] + " <library_name>"
sys.exit(1)
else:
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment