Extracting Attribute Data

Attribute values can be extracted from drawings, which is another reason why you should consider using blocks with attributes.

  • use the Attext command to extract attribute values to either a comma delimited file (CDF) or space delimited file (SDF).

You must create a template file (in ASCII format) to control which attributes are extracted and how they are formatted in the output file.

  • a record (line in the output file) is made for each selected object and each line in the template file controls one field in the record.
  • begin each line with one of the 15 BL field names or an attribute tag, add one or more spaces & then a type the Format Code.
  • you can include any or all BL fields and you must have at least one attribute tag (numeric or character) in the template.

The first character of the Format code in template files specifies whether the data is characters (C) or numeric (N).

  • the next 3 characters in the code control the total number of characters to use in that field (i.e. the field width).
  • you control the number of decimals to include for numeric data using the last 3 characters of the format code.

For example, you could create a template file called T207_dsk.txt for the DESK block example from the previous exercise.

  • the first line (BL:NAME) would generate a field in each output file record that includes the block name (i.e. DESK)
  • the format code for this line (C008000) specifies that the block name is character data and you would like to use 8 characters.
  • the 2nd & 3rd lines specify tag names (DESKTYPE & DESKMAN) and field widths for the attribute values to extract.

When you specify field widths & the number of decimals for numeric values you must take care to use ONLY digits in template files.

  • the letter O looks like the number 0 but using letters results in error messages and your attribute extraction will fail.
See also  Creating Rectangular Viewports

If you want to import the text from the output file back into AutoCAD you may want to choose the SDF file format.

  • use the Mtext command and select the Import Text button to import the output file directly as a single MTEXT object.
  • use a font in AutoCAD in which the width of every character is the same (or your field columns will not be aligned).
  • these special fonts normally have “mono” in the font name.

If you want to import the data into spreadsheets or databases you may want to choose the CDF file format instead.

  • then you can sort, analyze & generate reports using this data.

Some third party applications use attributes in block inserts to automatically generate bills of materials (BOM) or schedules.

  • facility management
  • material schedules in construction
  • parts lists for mechanical assemblies – etc.

Data can also be explicitly attached to objects as extended entity data without having to define and use blocks with attributes.

  • this requires custom programming to attach, extract and then manipulate the data.
  • however, you have more flexibility using this approach.


  1. If you completed the more practice section of the last exercise you can continue in the same drawing. (otherwise Open the T207_5.dwg drawing in your personal folder).
  2. Type ATTEXT at the keyboard to invoke this command. Select the Space Delimited File (SDF) File Format. Pick the Template File button and select T207_dsk.txt file in your personal folder and pick Open to return. Pick the Output File button and type My results in your personal folder and pick Save to return. Pick the Select Objects button and type ALL then press <enter> to return. Pick OK to extract the attributes and create the output file.

3) Pick Format + Text Style. Pick the New button and type Mono as the text Style Name & pick OK. Select Monospace821 BT TrueType font (or Monotxt.shx) as the Font Name and pick Apply. Then pick Close.

You are about to import the output file back into the drawing as an MTEXT object and you will want the columns to align.

See also  Finding Drawings With Attributes In DesignCenter

» 4) Pick Draw + Text + Multiline Text. Pick a point near P1 by eye. Enter W to invoke the Width option & enter . Pick the Import Text button. Select My results.txt in your personal folder & pick Open to return. Then pick OK.

Command: MTEXT
Current text style: “Mono” Text height: 2.4000
Specify first corner: <Osnap off> (pick by eye near P1)
Specify opposite corner or [Height/Justify/Line spacing/Rotation/Style/Width]: W
Specify width: 0
(continue as per instructions)

5) Type ATTEXT again. Change File Format to Comma Delimited File (CDF). Change the Template File to T207_all.txt in your personal folder. Change the Output File to My records in your personal folder. Pick Select Objects and enter ALL then press <enter> to return. Pick OK extract the attributes using this new template file.

7) Open the My records.txt file in MS Excel or import this file into another available spreadsheet application. (Most spreadsheet applications allow importing text files in CDF format.) Then Close the file without making any changes.

8) Save the changes you made to the current drawing then Close the file.

Back to top button