Take the Express Way!12 Mar, 2004 By: Bill Fane
More AutoCAD Express Tools for layers and blocks.
Once upon a time, in an AutoCAD release far, far away, there were the Bonus Tools, sent to good little girls and boys who registered their copies of AutoCAD. As we saw in my last column, these evolved into the Express Tools, which now ship standard with AutoCAD 2004 or can be purchased from www.autodesk.com for any 200x release.
Last time, we did a detailed study of the amazing Laywalk tool. A logical approach would be to continue with the other Express tools that fall under the Layer category, but a word of warning: This could be a short column. The remaining tools are useful and powerful, but I can describe each one in a single sentence. In fact, most of their functions are obvious from their menu names.
If you want more detailed information on the Express Tools, click Express/Help, which brings up a separate Help screen. Here are a few samples to get you going.
Change to Current Layer (Laycur)-Move selected object(s) to the current layer.
Layer Merge (Laymrg)-When you select an object on one layer followed by an object on a second layer, everything on the first layer is moved to the second, so you can purge the first layer.
Layer Match (Laymch)-Move selected object(s) to a different layer. You define the destination layer by selecting an object on it.
Layer Freeze (Layfrz)-Select an object, and its layer freezes. Actually, this one is a little more powerful than it first appears. When you enter the letter O instead of selecting an object, you're prompted to select an Option and then an object:
- Entity-level nesting-freezes the layer of a selected object even if it's nested within a block or xref.
- Block-level nesting-freezes the layer of the object if it's nested within an xref, but freezes the layer of the block insertion if the object is nested within a block.
Okay, I'm going to have to move on to a different category if I want to get paid for producing a column of reasonable length.
Kick That Block!
Figure 1. Block Express Tools.
Once again, I can explain many tools in a sentence or two. Here are a few examples.
Explode Attributes to Text (Burst)-If you explode a block insertion using the normal AutoCAD Explode command, attached attributes revert to attribute definitions and lose their values. On the other hand, when you Burst a block insertion, the attributes become normal text and retain their current values.
Extend to Nested Objects (Bextend) and Trim to Nested Objects (Btrim) aren't listed in the Help facility, but this isn't a problem because they're very easy to use. They behave almost exactly like AutoCAD's normal Extend and Trim commands, except that they let you select objects nested within a block insertion to be the trim or extend boundaries. Now that's cool!
The Learning Curve in January 2003 explained how to extract attribute values from block insertions and write them out to disk as a file. If you found that column interesting, you'll find these two Express Tools fascinating.
Export Attribute Information (Attout) exports attribute information to disk as a simple text file. It isn't as powerful or versatile as the regular AutoCAD Eattext command in that it won't export things such as x, y, and z coordinates and scale factors. It exports only the attribute values plus their AutoCAD "handles," but this shouldn't be a problem because most of the time all we want are the attribute values.
Why then does it also export the handles? Ah, there's the clever bit. You see, Import Attribute Values (Attin) is also an Express Tool, and it uses them.
Let's work through an example to see how these two tools work.
We'll start with a drawing that has several block insertions, each of which has several attributes attached (figure 2).
Figure 2. A drawing with six block insertions, each with four attributes.
Next, run Attout, which displays two prompts: A standard dialog box asks you to provide a file name and then to select objects. It filters out anything that isn't a block insertion with attributes.
That's it! Figure 3 shows the simple text file it created. A single tab delimits each field, so the columns don't always line up. If you want, you can open it in something like Word and reset the tab positions for better alignment.
HANDLE BLOCKNAME FIRST LAST OFFICE LOCAL '85 Head Alfred Newman 3212 246376 '7F Head Mary Poppins 2301 17 '79 Head Robin Hood 1004 4 '73 Head Sam Hill 1003 3 '6D Head Fred Flinstone 1002 2 '67 Head Alexander Bell 1001 1
Because this is a text file, I can use a simple text editor such as Notepad to edit any of the values, as shown in figure 4. The file can be saved back to the same name or to a new name.
HANDLE BLOCKNAME FIRST LAST OFFICE LOCAL '85 Head Alf Alfa 322 24 '7F Head Mary Poppouts 23 17 '79 Head Robin Trunk 1004 41 '73 Head Sam Mountain 103 34 '6D Head Fred Flinstone 102 2 '67 Head Alex Chime 1001 10
Now comes the cunning part. When you run Attin, a standard dialog box asks you to select a suitable text file. When you do, the drawing updates so that all the attributes on all the selected block insertions update to the new values, as shown in figure 5.
Figure 5: Updated drawing.
Now that's magic!
This tool has a great many uses. For example, note that any suitable file can be imported into a drawing, so let's begin by defining "suitable."
Earlier I drew your attention to the handles in the file. As you create and edit a drawing, AutoCAD automatically assigns a unique name, or handle, to each object. Handles are truly unique within a drawing-when an object is deleted, its handle is gone forever. Attin uses handles in the first column of text to find the correct insertion for each set of values.
If you Save As from within AutoCAD or use Windows Explorer to copy a file, the handles will be the same in the new file. Most spreadsheet programs such as Microsoft Excel can open or save as a tab-delimited text file.
Putting this all together means that you can have a standard startup drawing full of attributed block insertions. You can create the new data for the new drawing in a spreadsheet and then use Attin to put the correct values into each block insertion.
You don't even need to create the file by first extracting it from an existing drawing. You can create it directly using a text editor or another program.
The file has only three requirements:
- It must be a plain text file, not a word processor (i.e., Word) file.
- The first line must be a header that names each of the fields, using the tag of the attributes to be modified.
- It must contain the handles of the insertions to be modified.
- The fields, including the handle fields, don't need to be in any particular order.
By now you should have a pretty good idea of what can be found in the Express Tools, a virtual treasure trove awaiting your exploration.
And Now, for Something Completely Different
If you own a gas fireplace, sprinkle a few wisps of steel wool around the base of the artificial logs. These sparkle and twinkle much more realistically than the fake "embers" that are usually supplied with these units.
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!