Kenneth Pettit e-mailed a request to take information from a Microsoft Access database and use that information to change AutoCAD attribute blocks. Kenneth has used the Automatic Attribute Extraction tool to export his attributes directly into Access. It's interesting that this is now possible to do without knowledge of the format or type of data that is being exported, and even a template file is no longer needed. Kenneth has a set of blocks that have attributes for the address and location of rooms in a building. The address codes have a format such as XX:A1-01, and they never change, but the room location values may change, and they are subject to updating in the drawing. The attributes for the room location may be updated in the Access database. The AutoLISP Solution is ATTRIB-REPLACER.LSP, which uses a comma-delimited file exported from Microsoft Access. Any changes that have been made to the location field cause changes to be made to the corresponding attributes in the drawing. To test the code, I made a drawing with rooms and attributes for address codes and locations. I named the blocks containing the attributes ROOM-ID, although any block name can be used. The Microsoft Access table created by the Attribute Extraction tool is shown here (figure 1). The attribute values are Block name, Count, X insertion point, Y insertion point, LOCATION, and ADDRESS, as shown.
When the comma-delimited file is exported from Access (figure 2), it includes the headings. ATTRIB-REPLACER.LSP relies on the block name being in the first column, and the LOCATION and ADDRESS strings in columns 5 and 6, respectively. The other data in the table are not used, and there may be additional columns to the right of column 6.
|