Block Data Extraction
 
This article reviews extracting block attribute data from a drawing to a text file for processing.
Copyright©2000-2007 ActiveDwg.com

If your drawings contain blocks defining components, you can use the block information to create reports and material takeoffs. To get the data out of AutoCAD, you need to set up your blocks in AutoCAD and a template file using Notepad. 
For this example, we'll presume your block holds the following attributes: pMark, pQty, pWeight, pItem1, pItem2. We attach the 'p' prefix to isolate the attributes we want extracted. We may have other blocks that also need 'Mark' and 'Qty' and we don't want to mix them all together in the extraction process. 
The template file is a plain text file, and for our example, will look like this:
     pMark     C005000
     pQty        N009000
     pWeight   N009003
     pItem1     C005000
     pItem2     C005000
Each line corresponds to one attribute in the drawing block and has three main parts: The attribute tag, the extraction definition, and a Carriage Return(no spaces at the end). The definition tells AutoCAD how to treat each attribute. Note that if you align the fields as we have, you should only use spaces, if you insert a tab, the template file WILL NOT WORK.
'C005000' is the definition for 'pMark' and is split as:   C  005  000
The definition consists of three parts: Type(1 space), Field Length(next 3 spaces), and Decimal Precision(final 3 spaces). 'Type' describes the data type and may be either 'C' for character or 'N' for Numeric. 'Field Length' describes the maximum number of characters the attribute can hold. 'Decimal Precision' specifies how many decimal places a numeric value should hold.
For numeric data, the Field Length and Decimal Precision fields are bound. If you specify '009' for Field Length and '003' for Decimal Precision, the output will look like 'XXXXXX.xxx' for a total of 9 characters.
When the template file is completed, assign it a meaningful name and save it.
In addition to the block attribute tags, there are special place holders for block-specific information, which may also be used(they are listed below by 'Name'  'Format'  'Description':
   BL:LEVEL - Nxxx000  - Block Nesting Level
   BL:NAME - Cxxx000  - Block Name
 
  BL:X - Nxxxddd  - Block insertion point X coordinate
   BL:Y - Nxxxddd  - Block insertion point Y coordinate
   BL:Z - Nxxxddd  -  Block insertion point Z coordinate
   BL:NUMBER - Nxxx000 - Block Counter
   BL:HANDLE - Cxxx000 - Block handle
   BL:LAYER - Cxxx000 - Block insertion layer name
   BL:ORIENT - Nxxxddd - Block rotation angle
   BL:XSCALE  - Nxxxddd - X scale factor
   BL:YSCALE - Nxxxddd - Y scale factor
   BL:ZSCALE - Nxxxddd - Z scale factor
   BL:XEXTRUDE - Nxxxddd - Block extrusion direction X component
   BL:YEXTRUDE - Nxxxddd - Block extrusion direction Y component
   BL:ZEXTRUDE  - Nxxxddd - Block extrusion direction Z component

To do the extraction, use the AutoCAD command 'AttExt' (ATTribute EXTract). When you enter this command, you will be presented with the 'Attribute Extraction' dialog:


The file format section determines in what format AutoCAD exports the attribute data. The choice you make in the this section is largely dependent on the program you will be using to process the file. We use MS Excel 2000 and the default 'Comma Delimited File' works well. The Space Delimited File' uses spaces rather than commas, and the 'DXF Format Extract File' exports a block-only subset of a DXF format. 
The 'Output File' field defaults to the current drawing name. The first time you perform an export(per session), the path where AutoCAD places the output file is the AutoCAD 'Startup' folder. If you want the file located elsewhere, click the 'Output File' button and choose a different folder. Subsequent exports will default to your chosen folder. 
The 'Template File' field refers to the template file you created earlier. The first time you perform an export(per session), you will need to click the 'Template File' button,  navigate to your template file and select it.
The final step is the actual data export.
If you wish to select a particular portion of your drawing to extract from, click on the 'Select Objects<' button(you may have to click it twice). Now you can just select, usually by window, everything within the area you wish to isolate. Click 'OK' and the data for the area you selected will be exported.
If you wish to include the entire drawing in your selection, simply click the 'OK' button and skip the 'Select Objects<' step, and all data for the entire drawing will be exported.

Now you have a text format file with all the attribute information which can be imported into another database or spreadsheet application for processing.