Tell Me All You Know: Attribute Extraction, Part 1 (Learning Curve AutoCAD tutorial)1 Dec, 2007 By: Bill Fane
How to interrogate an AutoCAD drawing and pull attribute information out of it.
It was a cloudy day but quite warm and muggy. Captain LearnCurve was on special assignment. His driver was making good use of his Tom-Tom navigation system as he adroitly maneuvered his way through the traffic-clogged streets of . . .
Where now? Beijing? Shanghai? Kansas City?
As in Paris, Texas? Paris, Illinois? Paris, Kentucky? Idaho? Ohio? Arkansas? California? Indiana? Iowa? Maine? Virginia? Wisconsin? Oregon? Ontario, Canada? Yukon Territory, Canada?
Nope. Nope, nope, nope, nope. Paris, France.
Captain LearnCurve was in Paris to attend the Autodesk Manufacturing Media Summit, where he hoped to extract as much information as he could . . .
That's it! Extract! That will be this month's topic!
Earlier this year, I wrote two "Learning Curve" columns about how to create special objects called attributes (see Learning Curve: To Whom Do You Attribute That Information? and Learning Curve: Attributes, Take Two) and how to attach them to block definitions.
We learned that an attribute is a special fill-in-the-blank text object. We can assign all the usual text parameters to it such as the style, font, size, and location. We assign everything except the actual text string. A single block definition can include multiple attributes. For example, a block definition of a motor could include all the nameplate specifications such as brand, speed, voltage, and frame type.
When the block is inserted, AutoCAD asks us to fill in the blanks, and our text object appears in the drawing.
What Goes In Can Come Out . . .
Ah, but now comes the cunning bit. We can interrogate the drawing and pull attribute information back out of it by applying selective filters. It then can be saved in a file that can be opened by other programs such as word processors or spreadsheet and database applications. Thus, we could have a factory layout from which we could pull a list of all 20 hp motors and their x, y coordinates within the building.
In the past, when I started using AutoCAD back in the last millennium, this operation could be a little messy in that you had to manually set up a text extraction template file that included the names of the attribute tags and any other properties such as coordinates and layer names. The bad news was that the extracted data by default went into a file with the same name as the extraction template, so your template got wiped out each time unless you were smart enough to keep a separate copy.
Somewhere around AutoCAD 2000 or so, the EATTEXT (Enhanced ATTribute EXTract) dialog box came on the scene. This function was quite a bit better, but it still had its lumpy bits.
AutoCAD 2006 changed all that with a new extraction wizard that greatly simplified the process.
Let's see how it works, starting from a very simple example. In the first of my two columns about attributes, we created a simple organization chart. It had several insertions of a block whose definition included a simple rectangle and a single attribute for the person's name.
A simple drawing consisting of inserted blocks that each have an attached attribute.
Now let's extract some of the information from that drawing.
Start the DataExtraction command (Tools | Data Extraction . . .), which brings up the first of eight pages of the wizard.
We'll begin by creating a new extraction.
This page lets us create a new extraction definition or to use or edit an existing one. Because we're going through for the first time, let's take the default to Create a New Data Extraction. Click Next.
I won't bother showing the next screen because it is just a standard Windows file dialog box. It asks for a name and location in which to store the extraction definition so it can be used again with this or other drawings. Data extraction files have the extension DXE.
Enter a suitable location and name and then click Save. This step brings up page two of the wizard.
Page two of the wizard lets us define the source of the data extraction.
This page of the wizard can be very significant in the long run. With it we can specify more than one drawing and/or sheet sets and/or complete folders, with or without subfolders, from which to extract our data. All extracted data ends up in one big extract file. For example, it could be used to create a single door schedule for a large project that consists of several multistory buildings with each floor being shown on separate xref'd drawings.
We also can choose to select specific objects manually from within the current drawing. If we select this option, then we have to click on the icon to the right of the Select Objects window to actually initiate the selection process.
For our purposes, let's just click on Next because we are interested only in the current drawing.
This page of the wizard lets us filter the type of objects to be our data source.
Page three of the wizard indicates the type of object from which we can extract data. Hmmm, very interesting. Note that it isn't limited to blocks or even to blocks with attributes. I think we need to come back to this later, but first let's turn off the Display All Object Types button and turn on the Display Blocks with Attributes only button. This narrows our selection down to the single NAME-TAG row. Click Next.
Page four gives us a wide range of data from which to select.
Wow! That's quite a list! This page shows all of the properties of our selected objects. I have expanded the window to show them all; initially, only roughly one-third of them showed.
The first thing to notice is that many of the items don't seem to have anything to do with attributes. Once again, we'll come back to them in more detail later. For now, note that each line in the left-hand window has a Category entry beside it. Go to the Category window and turn off all categories except Attribute and Geometry. This selection narrows the list down to just seven items, which are the attribute tag name and the x, y, z positions and scale factors.
Back in the Properties window, turn off everything except NAME, Position X, and Position Y. Click Next.
Page five of the Wizard previews the extracted data.
Okay, we're five-eighths of the way there. Page five of the data extraction wizard previews our extracted data and lets us manipulate it. Most manipulations follow standard Windows practice. For example, click on the NAME column header to sort alphabetically, and then click on it again to reverse the sequence. Drag the column boundaries to change the column width, and drag the column names to change their sequence.
Before going any further, I should explain a couple of the column headers. The column head Name (second from left) indicates that this column shows the name of the block definition of each insertion, and NAME (third from left) indicates that this column shows the specific attribute value for each insertion. Why the near-duplicate column headers? Because I didn't think things through far enough when I created the original attribute definition and specified its tag as being NAME. Perhaps I should have called it First_Name to avoid this confusion. (Don't you just hate it when a computer does exactly what you tell it to do?)
We have two choices for the destination of our extracted data.
Page six is an easy one. We can either use the extracted data to build a table in our AutoCAD drawing or we can output it to one of four file formats. Let's start with the least-obvious choice; click on both buttons. That's right; we can create a table in the drawing and extract the data to an external file at the same time!
Click on the three-dot white button, which brings up a Windows-standard file dialog box. Browse to find a suitable location and then supply an appropriate name.
Select *.xls from the Files of Type drop list and then click Save.
We can define the style when we insert our data into an AutoCAD table.
This step brings up a dialog box that lets us select or customize the table style. You can play with this if you want to; it follows exactly the same procedures as the normal table definition/table editing commands. As a minimum, enter a title for our table, such as Name-tag Locations. Click Next.
I won't bother with a screen shot of page eight, because basically all it says is to click Finish, and the table and/or file will be created.
Click Finish and then pick an insertion point for the table.
Our extracted data has been inserted as an AutoCAD table.
And there we have it! Our extracted data has been inserted into our drawing as an AutoCAD table. The column widths and sort order are as specified on page five of the wizard. You also can open the extracted Microsoft Excel file and verify that it holds the same data.
This exercise has been a good start on the principles and practices of extracting attribute data from AutoCAD drawings. Be sure to come back next month when we dig even deeper into the subject; I'll show you how you can extract the properties of common objects such as circles and filter the results ("Find the x, y coordinates of all circles with a diameter larger than 10 but less than or equal to 20").
And Now for Something Completely Different . . .
When departing from Charles de Gaulle Airport in Paris, security is the last thing you pass through before entering the final boarding lounge, and the final lounge only contains a minimal coffee shop. Any eating or last-minute shopping must be done before you enter security. Also, be careful what you buy. The airport shops sell dangerous things that are not allowed through security, such as bottled water.
In her easy-to-follow, friendly style, long-time Cadalyst contributing editor and Autodesk Technical Evangelist Lynn Allen guides you through a new feature or time-saving trick in every episode of her popular AutoCAD video tips. Subscribe to the free Cadalyst Video Picks newsletter and we'll notify you every time a new video tip is published. All exclusively from Cadalyst!