Update Block Attributes Using Excel

by Donnie Gladfelter on March 12, 2008

in AutoCAD

Express > Blocks > Import/Export Attribute InformationMy post titled “Quickly Link Excel Tables to AutoCAD” from last August continues to be one of my most popular posts to date. As a result I have received a number of e-mails from readers such as you asking about other ways to link Excel data with AutoCAD data. A popular variation has been asking about a way in which you can link Excel data with AutoCAD Block Attributes. Since Block Attributes function much like a database form, it seems logical that we should be able to use Excel as a data source for those Block Attributes. Sadly there is not a true “Link Block to Excel” command (to my knowledge) within AutoCAD. That however does not mean there’s no workaround to the situation!

I originally developed this workaround back in the days before Sheet Set Manager. At the time I was working on a two-part project, each of which consisted of more than 100 sheets. The kicker was that we had to include the station range of the alignment being illustrated on each plan and profile sheet. Of course, as luck would have it, our road alignments were constantly changing in the early phases of design, consequently making our sheet titles incorrect. I thought to myself – there has to be a better way!

After a little digging around I found two Express Tool Commands which caught my eye; ATTIN and ATTOUT. Using these commands in conjunction with one another I was able to export a text file containing my attribute values, bring that text file into Excel to change and manage values, finally importing that text file back into AutoCAD. Admittedly the process is a little rough around the edges, but at the end of the day – it works!

Staging your Blocks

image The first and arguably most critical element to this procedure is the Attribute Blocks their self. Every object we draw and/or insert into an AutoCAD drawing has what is called a handle. Looking at a DWG file as a database, an objects handle is effectively its unique identifier, separating it from any other object within the current drawing. I mention this detail because the ATTOUT command records this unique object handle to the text file it exports. It’s by this unique handle the ATTIN command knows which instance of a given block to update.

That said you will want to first insert your blocks into your drawing(s). Back when I used this method for managing sheets, I would create my various layout tabs, inserting my attributed sheet title block into each respective layout tab. From that point on I made it a point to NEVER ERASE THAT BLOCK FROM THE DRAWING. Since AutoCAD sees any block insertion as a new object, it will consequently create a new handle. Consequently, the ATTIN command will only work if a handle in your Attribute Extraction Text File matches with a handle in the current drawing.

 

Creating your Export Files

With your block insertions made, you’re ready to begin exporting their attribute values. You can do that by using the ATTOUT command, which can also be launched by going to Express > Blocks > Export Attribute Information. Upon launching the command, simply select on the attributed blocks you wish to include in your export. Finally, after selecting the desired blocks, you’ll be prompted for a location to save the TXT export file.

Working in Excel

After creating your Block Attribute Export File(s), you’re ready to begin importing things into Excel. Getting the TXT file into Excel is rather straight forward. Using Excel 2007…

1. Go to the Data tab, and select “From Text”

2. Browse to the location of your Block Attribute Export File, and click [Import]

3. The Block Attribute Export File is a Tab Delimited TXT file. Consequently you’ll want to select “Delimited” from the resulting dialog box.

4. In Step 2 of the Text Import Wizard, select “Tab” as the delimiter type.

imageYour Block Attribute Data will be structured into a familiar table format. From this point you can keep things simple, or make them as complex as you desire. For instance, you may wish to use the table created in the above as more of a data source, using subsequent tables to further refine the data. Additional tables may perform calculations, or even make basic formatting adjustments. Whatever you choose to do, just be sure your final table subscribes to the same format as the original Block Attribute Export File.

To create an updated Block Attribute File:

1. Click on the Office Button, select Save As > Other Formats.

2. From the Save As dialog, change the “Save as type” to “Text (Tab delimited) (*.txt).

Updating AutoCAD Blocks

image You have made it to the homestretch, and only one command away from updating your Attributed Blocks.  Use the ATTIN command, which is also available from Express > Blocks > Import Attribute Information, to update your block insertions.  After invoking the command, you’ll be prompted to browse to wherever you saved your updated TXT file to from within Excel.  As soon as you press [Open] AutoCAD will update the attributes of any block for which it finds a matching handle.

Admittedly the procedure isn’t as eloquent as we may want it to be. Perhaps Autodesk will include a more dynamic way of achieving this in a future release of the software. Until then, this procedure is the best I have been able to work up!

  • http://www.thecadgeek.com Donnie Gladfelter

    @Aurélie – It’s important to note that ATTIN/ATTOUT are Express Tools. It’s been a while since I worked with our 2008 deployments, but I’m pretty certain Express Tools is one of the optional things you can install.

    You may need to re-run your install (or modify your deployment to include the Express Tools).

  • http://thecadgeek.com/ Donnie Gladfelter

    @Aurélie – It’s important to note that ATTIN/ATTOUT are Express Tools. It’s been a while since I worked with our 2008 deployments, but I’m pretty certain Express Tools is one of the optional things you can install.

    You may need to re-run your install (or modify your deployment to include the Express Tools).

  • Aurélie

    Hi everybody!

    I have a problem with these ATTIN and ATTOUT.
    that’s working in ACAD 2007, and it’s wonderful :)
    But in ACAD 2008, the command seems not to exist anymore…

    May some of you guys help me ?

  • Aurélie

    Hi everybody!

    I have a problem with these ATTIN and ATTOUT.
    that’s working in ACAD 2007, and it’s wonderful :)
    But in ACAD 2008, the command seems not to exist anymore…

    May some of you guys help me ?

  • Tony

    Hi guys,

    First of all I have to tell this is a great site, it provides lots of tips and info to Acad users.
    I would like to add my two cents: there’s a way to do what Lyn is trying to do by means of VBA, I am actually developing the code to do so. The reason I am doing this is that I work for a structural detailing firm and very often we need to update title block info on tons of drawings! so using an Excel sheet with the tag attribute and string attribute on the rows and the dwg filenames on the columns, there can be inserted all the info in a batch mode to each drawing.
    I would explain more as I have more progress on this code.
    Cheers!!

    Tony

  • Tony

    Hi guys,

    First of all I have to tell this is a great site, it provides lots of tips and info to Acad users.
    I would like to add my two cents: there’s a way to do what Lyn is trying to do by means of VBA, I am actually developing the code to do so. The reason I am doing this is that I work for a structural detailing firm and very often we need to update title block info on tons of drawings! so using an Excel sheet with the tag attribute and string attribute on the rows and the dwg filenames on the columns, there can be inserted all the info in a batch mode to each drawing.
    I would explain more as I have more progress on this code.
    Cheers!!

    Tony

  • Larry Johnson

    This is a great site!
    I have a question regarding using EXCEL with the data links in ADT 2006. I have been able to create links between individual excel cells and either text, attributes, or even property information. Once I’ve created the link, I would like to be able to use both the excel file and the drawing file as a template for other projects. I have not found a way to switch the referenced linked excel file name and location to a different one globally so that I do not have to re-link each cell when copy the files to a different project folder.
    Any thoughts on this would be helpful.

  • Larry Johnson

    This is a great site!
    I have a question regarding using EXCEL with the data links in ADT 2006. I have been able to create links between individual excel cells and either text, attributes, or even property information. Once I’ve created the link, I would like to be able to use both the excel file and the drawing file as a template for other projects. I have not found a way to switch the referenced linked excel file name and location to a different one globally so that I do not have to re-link each cell when copy the files to a different project folder.
    Any thoughts on this would be helpful.

  • http://www.thecadgeek.com Donnie Gladfelter

    @Lyn – If you do a Save As on a DWG – chances are the handles will be duplicated. You would need to erase and re-insert the block to make AutoCAD assign it a new handle. Looking at a DWG as a database, the handle is simply the “unique key” AutoCAD assigns to each object within it.

    As for the HandleToObject method – that’s a function of the AutoCAD API. There’s a discussion forum thread which may help you out: http://discussion.autodesk.com/thread.jspa?messageID=4955666

  • http://thecadgeek.com/ Donnie Gladfelter

    @Lyn – If you do a Save As on a DWG – chances are the handles will be duplicated. You would need to erase and re-insert the block to make AutoCAD assign it a new handle. Looking at a DWG as a database, the handle is simply the “unique key” AutoCAD assigns to each object within it.

    As for the HandleToObject method – that’s a function of the AutoCAD API. There’s a discussion forum thread which may help you out: http://discussion.autodesk.com/thread.jspa?messageID=4955666

Previous post:

Next post: