Thursday, March 03, 2005

Extracting a BOM from blocks

Platform: AutoCAD 2004

Creating and maintaining Bill of Material lists or BOMs have always been a tedious task in AutoCAD. Many of the Autodesk vertical products (Mechanical, MDT, Inventor) have inherent tools to help but if you're stuck with vanilla AutoCAD like me, you know the pain and suffering involved in creating an accurate BOM list.

The company I currently work for has instituted the standard of blocking every item in their assembly drawings with intelligent names; this really speeds up the detailer's jobs and allows for easy reuse in later projects. Most of the drawings I work with are plan-view layouts, so I only have one view to worry about. I've taken a bit of my own time and expanded on their idea, what if one could extract a first level BOM (no sub-assemblies or sub objects listed) and export it to a CSV file? CSV files are great because they open natively in Microsoft Excel without all the hassle of programming a hook into Excel. Before anyone asks, yes, I know using a collection would be quicker when searching for duplicate items but VBA has a few quirks with collections so I opted to use a for-next loop, just to be safe.

There are a couple of neat tricks in this article, for one the 'GetAttrValue' function is a nicely encapsulated function to extract a single known attribute value. Also, most people seem to miss the fact that you can search for multiple strings while creating a selection set. Simply separate each string by a comma and end each term with an asterisk wild card. For example, to search for all blocks that start with the words 'TEST' or 'HARDWARE', use the following:

CreateSelectionSet(objSS, DXF_NAME, "TEST*,HARDWARE*")

This article is far from a complete BOM solution; it simply asks you to select items on screen, extracts an item number from each block name and a description from an attribute named 'DESC'. The code for this article is quite extensive (about 260 lines) so please download it from the link above. The zip file also includes a sample drawing I whipped together to show you how it works.

Once you have the DVB extracted and loaded, open the Macros window (press Alt+F8) and run the 'CreateBOM' macro to get things started. If for some reason the macro is not showing up, go to the VBAIDE and run the CreateBOM subroutine.

Here are some thoughts for future development:

  1. Filter out alternate views (top, side, front) of the same object

  2. Create the BOM in the drawing instead of exporting to a CSV

  3. Sort the BOM before exporting it to screen or file

  4. Create the BOM as an AutoCAD table entity (AutoCAD 2005 or greater required)

If you enjoyed this article and would like to see an example of exporting the BOM to the screen, drop me a line.

This page is powered by Blogger. Isn't yours?

vba, acad vba, cad vba, cad, visual basic, visual basic for applications, autocad vba, acad vba, training, vba training, cad training, acad training, autocad training, autocad vba training, bom, bill of material, meta-data, meta data, metadata, property data, data, inventor properties, document management, document, management,technical support resource for users of Autodesk Mechanical CAD Software including Autodesk Inventor & Mechanical Desktop inventor, autodeskinventor, inventor 2, inventor 3, inventor 4, inventor 5, inventor 6, inventor7, inventor 8, inventor 9, inventor 10, autodesk inventor, autodesk inventor2, autodesk inventor 3, autodesk inventor 4, autodesk inventor 5, autodeskinventor 6, autodesk inventor 7, autodesk inventor 8, autodesk inventor9, autodesk inventor 10, inventor r, inventor r2, inventor r3, inventor r4, inventor r5, inventor r6, inventor r7, inventor r8, inventor r9, inventorr10, autodesk inventor, autodesk inventor r2, autodesk inventor r3, autodeskinventor r4, autodesk inventor r5, autodesk inventor r6, autodesk inventorr7, autodesk inventor r8, autodesk inventor r9, autodesk inventor r10,inventor series, autodesk inventor series, inventor series 5, inventorseries R5, autodesk inventor series 5, autodesk inventor series r5, inventorseries 6, inventor series R6, autodesk inventor series 6, autodesk inventorseries r6, inventor autodesk, autodesk inventor download, autodesk inventortutorial, autodesk inventor help, autodesk inventor faq, autodesk inventortips, autodesk inventor routines, autodesk inventor support, autodesk inventor, inventor download, inventor tutorial, inventor help, inventorfaq, inventor tips, inventor routines, inventor support, inventor, inventor help line, help for inventor, inventortraining, autodesk inventor training, mdt, mdt 4, mdt 5,mdt 6, mdt 7, mdt 8, mdt4, mdt5, mdt6, mdt7, mdt8, mdt 2000, mdt 2002,mdt r4, mdt r5, mdt r6, mdt r2000, mdt r2002, mechanical desktop, mechanicaldesktop 4, mechanical desktop 5, mechanical desktop 6, mechanical desktop7, mechanical desktop 2000, mechanical desktop 2002, autodesk, autodesk auto cad, autodesk inc,training, education, auto cad support, autocad support, mcad, autocad mechanical,mechanical, autocad mechanical 6, autocad mechanical 7, autocad mechanical8, autocad mechanical 9, autocad mechanical r6, autocad mechanical r7,autocad mechanical r8, autocad mechanical r9, support, help, tips, routines, reseller, mech, cad, acad, technical, ontario, canada, f.a.q.,faq, answers, resource, barrie, autolisp, auto lisp, autocad, auto cad, autocad desktop, auto cad desktop, autocad inventor, auto cadinventor, powerpack, MAI, desktop, cad software, autocad lt, auto cad lt,cad cam, cad design, cad job, job cad, autocad lisp, auto cad lisp, 3dcad software, 3d cad, free, free cad software, service pack, render, system, computer, aided, drafting, design, manufacturing, modeling, solidmodeling, solid modelling