Files
Introduction
FME can automate the extraction of AutoCAD block attribute data. AutoCAD blocks can contain attribute (data) information. In AutoCAD, when a block with attribute definition(s) is inserted, the user is prompted to type in data. To edit blocks within AutoCAD, users are presented with a block attribute editing form (AutoCAD block attributes displayed in the AutoCAD image below). Each entity in AutoCAD has a unique, unchangeable handle that can be used as a unique ID. Tracking the AutoCAD block handle information, combined with the drawing name, allows tracking and updating drawing data in a database.
This article will demonstrate how to extract AutoCAD Block "Tags" and "Values"—stored as block attributes—in an AutoCAD DWG using FME. The extracted attributes are then saved to an Excel spreadsheet. The example is of interest to users who need to extract AutoCAD block attribute information. Using FME, extracted block attribute values can be used in GIS and database systems.
Downloads
Starting data, Blocks, and Table DWG drawing:
http://download.autodesk.com/us/samplefiles/acad/blocks_and_tables_-_imperial.dwg
If the above link does not work, copy and paste it into your address bar.
Completed Template Workspace available from the Files section of this article
Source Data
The image below shows an example of the attribute block called "Window" being edited in AutoCAD.
Let's see how FME handles this data by looking at the DWG file in the FME Data Inspector, with the reader parameter Explode Blocks into Entities unchecked.
The same DWG information, as in AutoCAD, is displayed in the FME Data Inspector as a list:
FME reads block attribute information and stores the information as a list. For the first list element, the first AutoCAD block attribute field name - or "Tag" - is captured in FME with fme_attrib_info{0}.field_name, and the first AutoCAD Block attribute field value - or "Value" - is captured in FME with fme_attrib_info{0}.field_value.
The above example shows the first attribute {0} as "SYM" having a value of "3". The second attribute {1} follows the same format.
Step-by-step Instructions
1. Start FME Workbench and add an AutoCAD DWG/DXF Reader to a new blank workspace
In the Add Reader dialog, select AutoCAD DWG/DXF as the format, and select blocks_and_tables_-_imperial.dwg for the dataset.
Select Single Merged Feature Type. Note that selecting the "Single Merged Feature Type" makes the reader flexible so that it can process any DWG with any layer naming structure (and schema) and generally makes AutoCAD DWG files easier to work with. AutoCAD drawings have user-defined layer structures (they could be named anything). By NOT breaking the drawing into layers (who knows what layer might be encountered), processing in FME is easier/generic.
Click on the Parameters button.
We want to preserve the blocks as single entities, so uncheck Explode Blocks into Entities and enable Read Attribute Entity Data As List.
Humans typically make AutoCAD drawings by hand. Of note is that the example DWG provided by Autodesk contains a block (or two) on the wrong layer. Therefore, extracting DWG data based on layers might give faulty results.
2. Add an AttributeExposer
Although the "AutoCAD DWG/DXF reader" has a place for "Additional Attribute to Expose," use the AttributeExposer to make it clear what is being exposed. We find it easier to manage and troubleshoot something that is explicit.
All the hidden format AutoCAD and FME attributes are accessible. Click the ellipsis, then filter by typing "fme_attr" and select the attribute.
At a minimum, expose:
- autocad_attr_def_tag
- autocad_entity
- autocad_attributes_follow
- fme_attrib_info{}.field_name
- fme_attrib_info{}.field_value
For database or GIS synchronization/updates, make sure to expose the block handle, block name, and DWG file name:
- autocad_entity_handle
- autocad_block_name
- autocad_source_filename
3. Add a TestFilter to filter for blocks with attributes
In the TestFilter, we need to specify two test conditions: true and false.
First, we will fill in the test for the "true" values. Double-click on the top left box beside If and under Test to open the Test Conditions dialog window. Fill in the following values:
| Logic | Left Value | Operator | Right Value |
| autocad_entity | = | autocad_insert | |
| AND | autocad_attributes_follow | = | true |
Leave the Comparison Mode as Automatic. Set the Output Port to BlocksWithAttributes and click OK.
Notice the TestFilter Parameter has the first row filled. Now we need to set the definition for the "false" values.
Double-click on the next row next to Else If to open a new Test Conditions dialog and enter the following:
| Logic | Left Value | Operator | Right Value |
| autocad_entity | = | autocad_insert | |
| AND | autocad_attributes_follow | = | false |
Leave the Comparison Mode set to Automatic. Finally, set the Output Port as Blocks. Click OK, and your TestFilter Parameters window should look like the image below.
The above TestFilter detects/directs "Blocks with Attributes" block inserts by looking for an "autocad_entity" equal to "autocad_insert". Blocks that have attributes have "autocad_attributes_follow" equal to true.
4. Add a ListConcatenator
Connect the ListConcatenator transformer to the “Blocks with Attributes” port of the TestFilter.
FME can read the AutoCAD block attributes as a list (make sure the DWG reader has this set). The block attribute list can be considered a list of pairs containing all the information about the block attribute. As mentioned previously, for this example, the first attribute contains a tag called "SYM" with a value of 3.
- List Attribute: fme_attrib_info{}.field_name
- Separator Character: Newline(\n) (open up the Text Editor and add a Newline character)
- Destination Attribute: Tags
Typically, when working with lists, a comma separator is used. However, CAD attribute data can also contain commas or quotes. For instance, this example drawing has an attribute tag of Height with a value of 1'-6". To be on the safe side, using a special separator character - Newline(n) - avoids the hazards of parsing attribute data that could mess up comma-separated or quoted values.
5. Add a ListConcatenator for Values
Connect a second ListConcatenator transformer to the output port of the first ListConcatenator.
- List Attribute: fme_attrib_info{}.field_value
- Separator Character: Newline(\n)
- Destination Attribute: Values
6. Add an AttributeManager
Remove the following attributes:
- autocad_entity
- autocad_attr_def_tag
- fme_attrib_info{}.field_name
- fme_attrib_info{}.field_value
- autocad_attributes_follow
- fme_feature_type
7. Add Excel Writer
For Sheet Definition, select Automatic.
Set Sheet Name to Blocks with Attributes.
Connect the Excel Blocks with Attributes feature type to the AttributeManager Output port.
Results
Attributes from the sample drawing were exported to Excel.
Data Attribution
Thank you to Autodesk for providing the sample DWG. Autodesk Inc. licenses the "Block and Tables (Imperial) dataset" under the CC BY-NC-SA v.3.0 license.