extract those attributes1 Jan, 2003 By: Bill Fane
Captain LearnCurve had just returned from scuba diving in Key Largo, Florida, where he cuddled up to 79 nurse sharks and 59 Moray eels. Suddenly, the voice of a distraught AutoCAD user drifted over the rumble of the surf.
Woe is me! I need to include extra data in this drawing, and then somehow get it into a spreadsheet file!
No problem. Just attach attributes to block insertions and then extract the attributes to an external file. We'll use a four-step process. In a major departure from my usual way of thinking, let's start with step 1.
STEP 1: CREATE ATTRIBUTE DEFINITIONS
Attributes are a special kind of text item. You can define them as you would a text item-insertion point, justification, text style, size, and so on. You specify everything except the actual text they contain. In addition, you assign a tag name to each attribute.
As an example, draw a rectangle 2 units wide by 1.5 units tall. Select Draw | Block | Define Attributes to start the Attdef command. This brings up the Attribute Definition dialog box (figure 1).
Figure 1. Attribute Definition dialog box.
Fill in the Attribute blanks as indicated (Tag 5 First, Prompt 5 First name). Change Text Justification to Middle.
Select the Pick Point button. The dialog box collapses, and AutoCAD prompts you to pick an insertion point. Pick a point near the upper
Press <Enter> to repeat the command. When the dialog box returns, click the Align Below Previous Attribute Definition button to turn it on. Enter the tag name Last, with prompt Last Name, and click OK. The new attribute appears in the rectangle, aligned below the first one.
Repeat the last two steps two more times. Make sure you turn on the Align Below Previous button each time. Create attributes with tag Office and prompt Office number, followed by tag Local with prompt Phone local. Your drawing should now look like figure 2.
STEP 2: CREATE THE BLOCK DEFINITION.
Click on Draw | Block | Make to bring up the Block Definition dialog box (figure 3).
Figure 3. Block Definition dialog box.
Enter the block name Head. Click on the Pick Point button, then pick a suitable base point within or near the rectangle.
Click on the Select Objects button. Select the rectangle, and select the four attributes. The sequence in which you pick the attributes is very important. When you insert the block later, you will be asked to supply values for each attribute in the same sequence. This sequence also determines the sequence when the values are later extracted to an external file.
Press <Enter>, then click OK, and the block definition is created. Because the Convert to Block radio button is on by default, a block insertion replaces the selected objects and a dialog box asks you to supply attribute values. Observe how the sequence in the dialog box matches the selection sequence when you created the block definition, even though AutoCAD's Help facility says to select them in the opposite order to what you want.
STEP 3: INSERT BLOCKS
Select Insert | Block and insert the block Head. Specify an insertion point, then supply suitable attribute values when prompted to do so. Repeat this several times so your drawing looks something like figure 4.
Figure 4. Drawing with several insertions of attributed blocks.
STEP 4: EXTRACT ATTRIBUTE VALUES
Now we come to the real meat of this month's column. We are going to extract the attribute values from the drawing and write them out to a file.
Start the Eattext (Enhanced ATTribute EXTract) command by clicking Tools | Attribute Extraction to conjure forth the Attribute Extraction wizard.
In this example we'll generally take the defaults, so click Next four times until you reach the View Output wizard screen. Click on Alternate View, then Next twice more to reach the Export screen. In the File Type scroll window, change the type to Microsoft Excel. Click the box to the right of the File Name window, navigate to a suitable folder, enter the filename HeadOut, and click Save. Click Finish, then click Yes. Now launch Microsoft Excel and open your new file HEADOUT.XLS.
Magic! Here is all your attribute value data, along with a lot of other information (figure 5).
Figure 5. Extracted data.
I formatted the header row and column widths a bit, but the data is exactly as extracted. You could now produce a phone list sorted by last name, first name, office number, x and y coordinates within the drawing, and so on.
Once again, notice how the order of the last four columns matches the picking sequence when you defined the block. This cannot be changed, except by redefining the block and redoing all the insertions.
EATTEXT OPTIONS IN DEPTH
Select a Drawing. This screen defaults to extracting from the current drawing, but you have two other choices.
Click the Select Objects button to select block insertions onscreen. Attribute values are extracted only from selected insertions.
Click Select Drawings, then the File dialog button, and you can specify multiple drawings. All extracted attributes are written to a single file. An architect may have a drawing for each floor in a building, but can extract the door schedule attributes from all of them at once. This is a major improvement over the old command.
Settings is pretty obvious. You can control the search to include or exclude nested blocks and xrefs.
Use Template controls whether to use a template file. A template file holds extraction configuration data, so if you want to repeat a particular extraction later, you don't have to repeat all the entries. More on this later.
Select Attributes. By this point, the software has already searched all specified locations, found all block insertions, extracted the attribute data from the attributes, and is showing the first set to you.
In the Blocks window you can unselect any block names whose attribute values you do not want extracted.
In the Attributes window you can uncheck anything you don't want extracted. For example, you probably don't need the x, y, and z scale factors for the block insertions of a telephone list.
View Output. The default is to have one column for all the block names, plus one column for each attribute tag name. This format is probably most suitable when you are extracting to a database file format and want one database record for each item.
If you click the Alternate View button, the display shifts to a spreadsheet format, with one row for each block insertion and one column for each attribute tag. This is a live display that shows your actual output data. In fact, you can click the Copy to Clipboard button and then paste the data into almost any other Windows application.
Save Template. If you click the Save Template button, you are prompted for a filename. When you save, all the configuration information you set after the Use Template screen is saved. If you make changes to the drawing, you can extract the updated attribute data without setting everything again. The bad news is that template files are not compatible between the newer Eattext wizard and the older Attext command.
Export. The File Type scroll list allows four choices. Microsoft Excel spreadsheet and Microsoft Access database formats usually cover most needs. Two generic choices are provided for applications that do not support these two formats.
CSV-comma delimited writes data out as a single line of generic text, one line for each item. Fields within a line are separated by commas, like this:
Tab Delimited. Like CSV, except items are separated by tabs. This avoids the extra-comma problem.
AND NOW FOR SOMETHING COMPLETELY DIFFERENT
When partaking of a car journey, driver and navigator can communicate in two ways:
Wrong. Driver: Do we turn left at the next light?<
Either/both: Hey, we're going the wrong way!
Right. Driver: Do we turn left at the next light?
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!