Extracting Block Information Using Attributes AutoCad Help

This chapter mentioned that you can extract information regarding blocks, as well as attributes. To do this, you must use the following format:

This example includes some typical values for the attribute-codes. The following list describes what each line in the above example is used for.

LEVEL Returns the nesting level.

NAME Returns the block name.

X Returns the x-coordinate of the insertion point.

Y Returns the y-coordinate of the insertion point.

Z Returns the z-coordinate of the insertion point.

NUMBER Returns the order number of the block.

HANDLE Returns the block’s handle. If no handle exists, a 0 is returned.

LAYER Returns the layer the block is inserted on.

ORIENT Returns the insertion angle.

X SCALE Returns the X scale.

Y SCALE Returns the Y scale.

Z SCALE Returns the Z scale.

X EXTRUDE Returns the block’s.X extrusion direction .

Y EXTRUDE Returns the block’s Y extrusion direction.

Z EXTRUDE Returns the block’s Z extrusion direction.

Performing the Extraction

AutoCAD allows you to extract attribute information from your drawing as a list in one of three different formats:

• CDP (comma-delimited format)

• SDF (space-delimited format)

• DXP (data exchange format).

Using the CDF Format

The CDF format can be read by many popular database management programs, as well as programs written in the programming language BASIC. This is the format you will use in this exercise.

1. Type Ddattext↵, The Attribute Extraction dialog box appears.

2. If it isn’t already selected, click the radio button labeled Comma Delimited File (CDF).

3. Click the Template File button. Then, using the Template File dialog box, locate and select the Door. txt file you created earlier.

4. Click the Output File button. Then, using the File dialog box, enter the name Plan.bet for your output file and place it in the \Prog ram Files\AutoCA02000 directory.

5. Click OK in the Attribute Extraction dialog box. The message 16 records in extract file appears.

AutoCAD has created a file called P] an. txt that contains the extracted list. Let’s take a look at its contents.

1. Open the Notepad application (Start > Programs> Accessories> Notepad).

2. Choose File> Open to open Plan . txt from the current directory. (In this exercise, the template file is located in the \Program Files\AutoCAD2000 directory.) The following list appears:

Since you picked the comma-delimited format (CDF), AutoCAD placed commas between each extracted attribute value (or field, in database terminology).

The commas are used by some database management programs to indicate the separation of fields in ASCII files. This example shows everything in uppercase letters because that’s the way they were entered when the attribute blocks were inserted in the working example. The extracted file maintains the case of whatever you enter for the attribute values.

Using Other Delimiters with CDF Some database managers require the use of other symbols, such as double quotes and slashes, to indicate character values and field separation. AutoCAD allows you to use a different symbol in place of , the single quote or comma. For example, if the database manager you use requires double-quote delimiters for text in the file to be imported, you can add the statement

c:quote

to the template file to replace the single quote with a double quote. A line from an extract file using c: quote in the template file would look like this:

Notice that the single quote (‘) is replaced by a double quote (“). You can also add the statement

c:delim /

to replace the comma delimiter with the slash symbol. A line from an extract file using both c: quote and c :delim / in the template file would look like this:

Here, the comma is replaced by a forward slash. You can add either of these statements to the beginning or end of your template file.

Using the SDF Format

Like the COP format C, the space-delimited format (SDF) can be read by most database management programs. This format is the best one to use if you intend to enter information into a word-processed document because it leaves out the commas and quotes. You can even import it into an AutoCAD drawing using the method described in Chapter 8. In this exercise, you will use the SDF option to extract the same list you extracted a moment ago using CDF.

1. Type Ddattext↵ at the command prompt.
2. In the Attribute Extraction dialog box, use the same template file name, but for the attribute extract file name, use Plan-SDF. txt to distinguish this file from the last one you created.
3. Click the SOP radio button, and then click OK. You will see a message that reads 16 records in extract file.
4. After AutoCAD has extracted the list, use Windows WordPad to view the contents of the file. You will see a list similar to this one:

This format shows text without any special delimiting characters.

5. Now save the Plan . dwg file for future chapters .

Using the DXF Format

The third file format is the data exchange format (DXF).There are actually two methods for DXF extraction. The Attribute Extraction dialog box you saw earlier offers the DXF option. This option extracts only the data from blocks containing attributes. Choose the File >- Export option; then select DXF from the List Files of Type drop down list to convert an entire drawing file into a special format for data exchange between AutoCAD and other programs (for example, other PC CAD programs).

Using Extracted Attribute Data with Other Programs

You can import any of these lists into any word-processing program that accepts ASCII files. They will appear as shown in our examples.

As mentioned earlier, the extracted file can also be made to conform to other data formats.

Microsoft Excel

Excel has no specific requirements for the formatting of AutoCAD extracted data. Choose File >- Open from the Excel pull-down menu, and then select the Text File option from the Files of Type drop-down list in the File dialog box. Next, select the text file you want to import, then click Open. Excel then opens an easy-to-use import tool that steps you through the import process. You can choose the delimiting method, regardless of whether the field contains text, date, or another type of data, and other formatting options .

If you are a database user familiar with Microsoft Visual Basic, you will want to look at the sample Visual Basic utility supplied with AutoCAD. It shows how you can use VBA to export attribute data directly from AutoCAD to Excel without having to create a template file or perform an export using the Ddattext command. You can find the sample program in the \sample\activeX\ExtAttr directory.

Microsoft Access

Like Excel, you can open the exported attribute data directly in Access. First, create a new database table. Then use the Pile >Get External Data >Import option in the Access pull-down menu, and then choose Text Files from the Files of Type drop down list. After selecting the attribute-extracted file, Access offers an easy-to-use import tool that steps you through the process of importing the file. You can specify field and record names, as well as the delimiting method.

If you plan to update the attribute data file on a regular basis, you can have the file linked, instead of imported (File >Get External Data >Link Tables). A linked file is best suited for situations where you want to read the data without changing it. You can generate reports, link the attribute data to other databases, perform searches, or sort the attribute data.

As with Excel, if you are a Visual Basic user, you can add controls to enhance your attribute data link to Access.

Posted on November 7, 2015 in Storing and Linking Data with Graphics

Share the Story

Back to Top
Share This