AutoCAD DWG Block Attribute Extraction

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2017.x

Introduction

FME can automate the extraction of AutoCAD block attribute data. AutoCAD blocks have the ability to 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 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 – in combination with the drawing name – allows for 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. Extracted attributes are then saved to an Excel spreadsheet. The example is of interest to users that 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
Note if the above link does not work, copy and paste it into your address bar. 

Completed Template Workspace available from the Files section on this article

 

Source Data

The image below shows an example of the attribute block called "Window" being edited in AutoCAD.

1-blockattributeautocad.png

2-blockattributedi.png

AutoCAD block attributes displayed 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, displayed in the FME Data Inspector as a list:

2-blockattributedi.png

AutoCAD block attribute displayed in the Data Inspector. The tricky bit – as always – is knowing where to look for the data. The FME Data Inspector rocks!

 

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 Workbench and add a "AutoCAD DWG/DXF Reader" to a new blank workspace

In the Add Reader dialogue, select AutoCAD DWG/DXF as the format, and select blocks_and_tables_-_imperial.dwg for the dataset.

Click on the Parameters button.

We want to keep the block preserved as single entities, so uncheck Explode Blocks into Entities as we do not want to explode the blocks in the readers parameters. Also, be sure to place a checkmark on “Read Attribute Entity Data As List”.

3-dwgreaderparametesr.png

Select Single Merged Feature Type. Note, selecting the "Single Merged Feature Type" makes the reader flexible so that it can to 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 the layer that might be encountered), processing in FME is easier/generic. The other thing to remember, is that AutoCAD drawings are typically made by hand by humans. Of note, 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.

4-dwgreader.png

2. Add an AttributeExposer

Although the "AutoCAD DWG/DXF Reader" has a place for "Additional Attribute to Expose", use the Attribute Exposer to make it clear as to 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 (no need to use the Import button), click the button with three dots (in a row), then filter by typing "fme_attr" and select the attribute.

5-attributeexploder.png

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

6-testfilter.png

In the TestFilter, specify the following:

If
TEST @Value(autocad_entity) = autocad_insert AND
TEST @Value(autocad_attributes_follow) = true

Output Port -> Blocks with Attributes

Else If
TEST @Value(autocad_entity) = autocad_insert AND
TEST @Value(autocad_attributes_follow) = false

Output Port -> Blocks

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" equals true.

 

4. Add a ListConcatenator

Connect the ListConcatenator transformer to the “Blocks with Attributes” port of the TestFilter. Rename the ListConcatenator_Tags.

8-listconcatenator.png

FME can read the AutoCAD block attributes as a list (make sure the DWG reader has this set). The block attribute list can be thought of as list pairs that contain all the information about the block attribute. As mentioned previously, for this example, the first attribute contains a tag called "SYM." and it has a value of 3.

 

2-blockattributedi.png

  • List Attribute: fme_attrib_info{}.field_name
  • Separator Character: Newline(\n) (open up the Text Editor and add a Newline character)
  • Destination Attribute: Tags

9-texteditor.png

Typically, when working with lists, the use of 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.

Using the Newline separator will make it easy to work with the data and present the data later on.

 

5. Add a ListConcatenator for Values

Connect the second ListConcatenator transformer to the output port of the first ListConcatenator. Rename the ListConcatenator_Values.

  • List Attribute: fme_attrib_info{}.field_value
  • Separator Character: Newline(\n)
  • Destination Attribute: Values

 

6. Add an AttributeManager

10-attributemanager.png

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 Excel Blocks with Attributes feature type to the AttributeManager Output port.

11-excelwriter.png

 

Results

12-exceloutput.png

Attributes from the sample drawing exported to Excel

 

Data Attribution

Thank you to Autodesk for providing the sample DWG. The "Block and Tables (Imperial) dataset" is licensed by Autodesk Inc. under the CC BY-NC-SA v.3.0 license and is available from http://download.autodesk.com/us/samplefiles/acad/blocks_and_tables_-_imperial.dwg

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.