AutoCAD

holy Battman, Robin!

1 Oct, 2003 By: Bill Fane


Captain LearnCurve spent the morning water-skiing, the afternoon windsurfing, and was now sitting by the campfire with his gorgeous wife, waiting for the wood-fired sauna to heat up. Suddenly, he was inundated with an e-mail from a reader who, after reading recent columns on block editing (March 2003) and attribute extraction (January 2003), wants to revise and update block attributes.

As you know, attributes are fill-in-the-blank text objects. When you create an attribute definition, you specify all of its properties, just like any other piece of text. You specify the insertion point, alignment, size, rotation angle, and so on. The one thing you don't specify is the actual text.

The next step is to create a block definition that includes the attribute as one of its components.

AN INSERT OFF THE OLD BLOCK
Now comes the clever part. Every time you insert the block, AutoCAD asks you to fill in the actual contents of the text object and then creates it as part of the block insertion. All you need to supply is the content, because you've already defined the other specifications of the text object.

By the way, here are two quick tips for inserting blocks with attributes:

  • When ATTDIA is set to the default value of 0 (zero), AutoCAD prompts for attributes values one at a time at the Command prompt. When it's set to 1, a dialog box asks for all attribute values at once.
  • When ATTREQ is set to the default of 1, AutoCAD prompts for attribute values when you insert the block. When it's set to 0 (zero),
    figure
    Figure 1. Two insertions of a block with an attribute.
    AutoCAD won't ask, but simply uses the default value for each attribute.

Once you insert the block, you can easily edit its attribute values. In later releases, simply double-click on an insertion that contains attributes to bring up a suitable dialog box. So far, so good, but what happens when you want to add another attribute to an existing block definition?

figure
Figure 2. A Refedit in progress.
Figure 1 shows two insertions of a simple block. The block definition contains a rectangle and a single attribute. Figure 2 shows the Refedit command in action on the left-hand insertion ("Learning Curve," March 2003). I moved the attribute up, added the horizontal line across the rectangle, and created a new attribute definition below the line.

Figure 3 shows what happens when I complete the Refedit and save the changes. Now that's weird-the line was added, but the attributes

figure
Figure 3. The completed edit. Hey! What’s wrong?
didn't change, not even in the specific insertion that I was editing.

When I add another insertion of the same block, however, it does reflect the changes (figure 4).

ALL IS MADE CLEAR
Each insertion of a block consists of a simple pointer back to the block definition, but each attribute is created as a separate

figure
Figure 4. A new insertion works!
semi-independent drawing object once its parent is inserted. If you change the block definition, all insertions update, but the attributes do not.

The bad news in the early days of AutoCAD was that to add or delete an attribute from a block definition you had to erase and reinsert every insertion of the block. Ewww! The good news is that Autodesk followed the lead of a great many amateur programmers (including yours truly) and added two commands that automate the updating of attributes.

The Attredef (Attribute Redefine) command is fast and efficient, but a little crude (sort of like Captain LearnCurve). It runs only at the Command prompt. To use it, you need to follow these steps:

  • Insert the desired block at a known location, say 0,0.
  • Explode the insertion.
  • Perform any editing on the normal objects and the attribute definitions. You can add, delete, move, and revise any of them.

When you're finished, enter Attredef at the Command prompt. AutoCAD asks you to:
Enter name of the block you wish to redefine:
You must type in the exact name of the block, which means you need to know it before you start.

The next prompt asks:
Select objects for new Block. . .
Pick the attributes one at a time in the order in which you want AutoCAD to prompt for them, then select everything else for the block. Press <Enter> to move on.

Finally, you are asked to:
Specify insertion base point of new Block:
Specify a point. This is why I suggested a known location such as 0,0. When you do specify a point, all the selected objects disappear, and all of your existing insertions update to the new specifications.

As the updates take place, AutoCAD adds all new attribute definitions to each insertion, using the default value. All existing attributes retain their current values. If you delete an attribute definition, the matching attribute is deleted from each insertion and its value lost.

A word of warning-don't use the same tag name for two different attributes in the same block. This is not desirable on a good day, but Autodesk specifically warns that it can confuse Attredef.

BATTMAN TO THE RESCUE
Let's move on to Battman (Block Attribute Manager). Battman began life as a Bonus Tool and became a regular command in AutoCAD 2002. It offers a number of major advantages over Attredef, but as you'll see shortly it has two significant holes.

To start Battman, you can type it at the Command prompt, you can pick Modify | Object | Attribute | Block Attribute Manager, you can pick it from the Modify II toolbar, or you can flash the Bat Signal into the sky. Just kidding about that last option.

figure
Figure 5. Block Attribute Manager dialog box.
Next, the Block Attribute Manager dialog box shown in figure 5 appears, but only when your drawing contains at least one block definition that contains at least one attribute definition.

From here on, Battman's basic operation is pretty obvious, but some interesting bits are buried a little deeper. Let's start with the obvious.

First, look at the top region of the dialog box. You can select a block definition to edit through either of two methods. The scroll list displays the names of only those blocks with attribute definitions attached. You can select one of them, or you can click the Select Block button. This dismisses the dialog box, which reappears once you click on a block insertion with attributes in your drawing.

Now look at the list of attributes that appears in the main window. They appear in the same order in which AutoCAD prompts for them when you insert the block. You can highlight one, and then use the Move Up and Move Down buttons to change the sequence.

You can remove attributes that you no longer want to include in the definition.

figure
Figure 6. Edit Attribute dialog box.
When you click on the Edit button, the Edit Attribute dialog box (figure 6) appears. The three tabs let you change three different sets of parameters for the selected attribute.

The Attribute tab covers the tag name, the prompt, the default value, and the modes such as Invisible and Verify.

The Text Options tab, also shown in figure 6, lets you change pretty much anything you want about the appearance of the attribute text.

The Properties tab covers the attribute's layer, linetype, lineweight, color, and plot style, if applicable.

The interesting button is in the lower left corner. When Auto Preview is checked, all insertions of the target attribute appear to update on the fly as you make changes. Nothing actually sticks, however, until you select OK. When you click OK or Cancel, this dialog is dismissed, and you return to the Battman main dialog box.

The Settings button in the main dialog box lets you decide which properties appear in the main listing window. It also lets you highlight in red any duplicate tag names in the listing window.

Okay, campers, it's pop quiz time! What two features are missing from Battman?

Here are two hints. First, you can't change the positions of attributes relative to the other objects in the block. And although you can remove an attribute, you can't add one.

Luckily, there is a workaround. Simply use Refedit to make the desired changes, and then use Battman on the same block. In the Battman dialog box, click on the Sync button in the upper right corner, and all the insertions update, exactly as if you had used Attredef.

So there you have it. Between them, Battman, Attredef, and Refedit provide total control over attribute definitions.

AND NOW FOR SOMETHING COMPLETELY DIFFERENT
In the November 1990 Learning Curve I suggested you use a red light in your wood-fired lakeside sauna so it doesn't disturb your night vision. I also suggested using a meat thermometer instead of an expensive sauna thermometer. This month we have a related tip: make sure the thermometer has a red liquid column so you can see it under the red light. Silver ones don't show up too well.


AutoCAD Tips!

Lynn Allen

Autodesk Technical Evangelist Lynn Allen guides you through a different AutoCAD feature in every edition of her popular "Circles and Lines" tutorial series. For even more AutoCAD how-to, check out Lynn's quick tips in the Cadalyst Video Gallery. Subscribe to Cadalyst's free Tips & Tools Weekly e-newsletter and we'll notify you every time a new video tip is published. All exclusively from Cadalyst!
Follow Lynn on Twitter Follow Lynn on Twitter


Poll
At your company, who has the most say in CAD-related software purchasing?
CAD manager
CAD users
IT personnel
vice-president/department manager
CEO/company owner
Submit Vote