Nov 032013
 

Photo by flickr.com/cbrobotics

I’d like to share a neat Eagle hack for all our the people who have taken our Eagle CAD classes (myself included) and our Eagle-using friends.

BOM-EX is nifty little ULP (User Language Program) that extends the functionality of the built-in BOM ULP. BOM-EX not only helps you assemble a coherent BOM (Bill of Materials) right from your Eagle schematic, but it also makes it easy to assemble a database of parts, and associate those parts with parts numbers for DigiKey, Mouser, Newark, etc.

I made a nice little script that lets me build my BOM database without ever leaving the DigiKey website…

My usual process for selecting parts goes something like this:

1) Drop a part in the schematic.
2) Check to see if this part (in this size) exists, is available, is affordable, etc.
3) No? Keep looking.
4) When the project is done, go back and find every part again.
5) Assemble a BOM by hand, or spend time cleaning up the output from BOM.ulp.
6) Punch everything in to DigiKey, triple check to see what I forgot, etc.
7) Place the order, hope I didn’t forget anything, hope I ordered enough, etc.

BOM-EX makes things much simpler; I wish I has been using it from the start:

1) Find the part on DigiKey, etc.
2) Drop it into BOM-EX
3) When the project is done, export a BOM file that can be uploaded straight to DigiKey, Mouser, etc.
4) Order your parts with confidence!

But wait, how can we make this even simpler? How about populating our database straight from DigiKey?

First make sure you have BOM-EX set up. You can download the latest version of BOM-EX from Cadsoft’s webpage. Search for BOM-EX and download the latest version (bom-ex156 as of this writing). There’s a nice tutorial for setting it up here, and also a nice PDF included with BOM-EX itself.

Choose a location for your parts database file to live – it can be inside your Eagle project folder, but I recommend keeping it global, so you have an easy-to-reference library of common components for all your projects.

Next, download our Grab-Bag repository and find the python script in the Bom-ex folder. Open the script and change the PARTSDB path to point to where you keep your parts database file.

You can now add parts to your database file straight from the command line:
python addDKPartToBom-ex.py ATMEGA644A-AU-ND
will add the following line to your parts database file:
ATMEGA644A-AU Atmel DK ATMEGA644A-AU-ND IC MCU 8BIT 64KB FLASH 44TQFP 44-TQFP

Note: you may need to install the BeautifulSoup module for Python. You can install it with pip install beautifulsoup4 or easy_install beautifulsoup4. It’s also available as the python-beautifulsoup4 package in recent versions of Debian, Ubuntu, and Fedora, or you can download it from their website.

For extra coolness, drop addDKPartToBom-ex.py into /usr/local/bin (or anywhere else in your PATH, make it executable (chmod +x addDKPartToBom-ex.py), and now you can run it from anywhere.

But wait, there’s more! If you’re on a Mac, grab the Add Parts To Library.workflow file in the repository and double-click. Select Open With Automator

Screen Shot 2013-11-03 at 2.09.51 PM

If you followed the above instructions, you shouldn’t have to change anything, otherwise update the “Run Shell Script” box in Automator to reflect the correct location for your addDKPartToBom-ex.py script. Close Automator, double-click on the workflow again, and select Install.

Now, when you’re browsing the DigiKey website, just right click on the DigiKey part number, select Services, and select Add Part to Library

Screen Shot 2013-11-03 at 2.13.24 PM

Et Voilà, your parts are appended to your BOM-EX parts database, no manual entry required! Enjoy a few hours saved in BOM-hell on your next Eagle project. See this tutorial for more information on using BOM-EX.

Do you have any slick Eagle hacks? Share them in the comments!

 Posted by at 2:26 pm
  • Jon Fraser

    The python script wont work for me. I used your example of ATMEGA644A-AU-ND and it’s giving “none” for all values aside from that part number.

  • Paul Ryan

    @jon_fraser:disqus Looks like because digikey recently attempted to add some more Javascript which broke parsing you need to use the html5lib parser for this script. To do that get the parser with easy_install html5lib then change the line that reads soup = BeautifulSoup(data) to soup = BeautifulSoup(data, ‘html5lib’).

    Hope this helps.

  • Laura Zumbrunnen

    I think I followed all the instructions (thanks!), but when I try to add the part via the Services – Add to Parts Library nothing actually gets added. I don’t get any errors popping up that tells me something is wrong. Also, it works when i can add from command line. What am I missing?

    • Gearhead

      First, this appears to be a Python 2.7 script (need to know this in order to know which version of python to install). When run, this is the error:

      Traceback (most recent call last):
      File “C:Python27ScriptsaddDKPartToBom-ex.py”, line 24, in
      partNo = sys.argv[1]
      IndexError: list index out of range

      When I change this from sys.argv[1] to sys.argv[0], I get this:
      Traceback (most recent call last):
      File “C:Python27ScriptsaddDKPartToBom-ex.py”, line 33, in
      data = opener.open(request).read()
      File “C:Python27liburllib2.py”, line 410, in open
      response = meth(req, response)
      File “C:Python27liburllib2.py”, line 523, in http_response
      ‘http’, request, response, code, msg, hdrs)
      File “C:Python27liburllib2.py”, line 448, in error
      return self._call_chain(*args)
      File “C:Python27liburllib2.py”, line 382, in _call_chain
      result = func(*args)
      File “C:Python27liburllib2.py”, line 531, in http_error_default
      raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
      HTTPError: HTTP Error 404: Not Found

      I think DigiKey has changed the format, somehow and the script is not aligned to the change.

  • Douglas Bakkum

    I had similar problems but was able to get it to work. First, html5lib needs to be used as Paul Ryan wrote. Second, the reason it worked from command line but not from the Services – Add to Parts Library was because the input argument for Services was a url, whereas by command line, it is a part number that gets converted into a url.

    To solve, I modified the python code:

    if “http://” in partNo:
    url = partNo
    else:
    url = DIGIKEY_URL + partNo.replace(“/”, “%2F”).replace(“#”, “%23″)

    And later, to get the correct partNo (note ‘contents[1]‘):

    # Parse out the PartNo
    for elem in soup(text=re.compile(r’Digi-Key Part Number’)):
    try:
    parent = elem.parent.parent.td
    partNo = parent.contents[1]
    except:
    pass

    Thanks a lot for this very convenient tool!