Attributes, Take Two (Learning Curve AutoCAD Tutorial)9 Apr, 2007 By: Bill Fane
There's more to them than meets the eye.
Once upon a time . . . scratch that and let's begin again. About a month ago, Captain LearnCurve wrote about creating and using attributes in AutoCAD. As complete and comprehensive as that article was, it didn't completely cover the Captain's vast knowledge of the subject. Let's at least partially rectify that situation, beginning with a brief review of our plot so far.
Last month, we learned that attributes are a special fill-in-the-blank-type text object. We create them using the AttDef command from the Attribute Definition dialog box.
Use the AttDef dialog box to create attribute definitions.
This dialog box lets us assign most of the properties of a normal text object, except for the text itself. We define the text style, size, location, justification and rotation. In short, we define everything except for what the text actually says.
While we're at it, we can define a few extra properties for each attribute. These properties include its tag, a prompt and a default value. Last month, we also explored the various mode settings.
Having created one or more attributes, we can use them as objects within a block definition. Each time the block is inserted, the program asks us to provide a specific value for the text in each attribute.
Please Come to Order!
Now that we understand the basics, let's look at some specific details starting with a few things that the AttDef and Block definition dialog boxes never told you.
To ensure the following instructions work properly, it's necessary to make sure that the AttReq (Attribute Request) system variable is set to the default value of 1 and that AttDia is set to its default value of 0 (zero). You can do this simply by entering the system variable names at the Command prompt and then enter the appropriate values.
Next create two attributes, one called First and the other called Second. Give them default values of 1 and 2, respectively. Copy them so you have a pair of Firsts and a pair of Seconds.
Create two block definitions called 1-2 and 2-1 respectively. When picking objects for 1-2, select a First attribute and then select a Second.
Repeat the process for block 2-1, but this time select the remaining Second attribute before you pick the remaining First.
Next Insert each block and notice the difference in their behavior. Yes! The system asks you for the specific attribute values in the same order in which you selected them during the block definition process. (Who's on first?)
Your lesson? When selecting attributes for a block definition, select them in a logical sequence. For example, Model or Type should probably come before Color. The order of selecting other objects such as lines or circles is irrelevant. If you do mess up, however, it isn't necessary to redefine the entire block.
BattMan to the Rescue!
Trust me. BattMan is a genuine AutoCAD command. You will find it under Modify / Object / Attribute / Block Attribute Manager. I wrote about it in full detail in October 2003. You can use it to modify the properties of attribute definitions from within or to delete attributes from a block definition, and it can also be used to change the sequence of attribute definitions within a block definition.
While we're on the subject of inserting blocks with attributes, let's go back and look at the two system variables that I referred to a few paragraphs back.
If the AttReq (Attribute Request) system variable is set to the default value of 1, then when you insert a block you are asked for a specific value for each attribute. When it is set to 0 (zero), then you are not asked, but all attributes assume their default values. The sneaky bit here is that if you forget to specify a default value when you created the attribute definition, then each insertion of it is blank.
The setting of AttReq is saved in the system registry, so that all insertions of all blocks in all drawings obey its current value.
The value of AttDia also is saved in the system registry. If it's set to 0 (zero), then you are asked for each attribute value one at a time in sequence at the Command line, but if it's set to 1, a cool dialog box appears showing all attributes.
Attribute values can be supplied through a dialog box when AttDia is set to 1.
The attributes are displayed in the order in which you selected them when you created the block definition, but you can edit them in any sequence. Click OK to conclude the block insertion.
The slightly strange thing in this day and age of toolbars, dashboards, tool palettes and dialog boxes is that the default value when AutoCAD is installed is 0, which is the Command line setting.
Time for a Change . . .
Okay, so you want to edit attribute values. Here's where it gets interesting.
Let's start with the basic commands and then look at an interesting anomaly in the Help facility.
If you start the AttEdit command at the Command prompt, you are asked to select a block insertion that has attributes attached. When you do, AutoCAD brings up the same Edit Attributes dialog box that you saw during block insertion in the image above.
You can change the value of any attribute attached to the selected block. If the block has 9 or more attached attributes, then the Next and Previous buttons give access to all of them.
On the other hand, the EAttEdit (Enhanced Attribute Edit) command calls up the Enhanced Attribute Editor dialog box.
The Enhanced Attribute Editor (EAttEdit) dialog box.
As you might guess, the Attribute tab lets you edit the value of any attribute attached to a block insertion.
In addition, the Text Options tab lets you change the text style, justification, size and so forth of the attribute currently selected on the Attribute tab and the Properties tab lets you change its layer, color, lineweight and plot style. The strange thing here is that it also lets you edit the linetype, even though linetype has no effect on text objects.
Actually, there's another bit of strangeness at play here. As far as I can tell, the only way to invoke the AttEdit command is to enter it at the Command prompt. The Help file says you invoke it by selecting Modify / Object / Attribute / Single, but in the current releases this actually invokes EAttEdit.
When all is said and done, the easiest way to edit an attribute value is to simply double-click on it to invoke EAttEdit.
All Together Now . . .
In the good old days, way back in the last millennium, several years BW (before Windows), the AttEdit command didn't have a dialog box but was all command-line driven.
We can still force it into this mode by entering -AttEdit at the Command prompt (note the leading minus sign). Although it has a clunky command-line interface in this mode, it does have one useful feature. It lets you simultaneously change the value of every instance of a specific tag. You can thus change the voltage of all motor blocks from 208 to 440 almost instantly all in one hit.
Playing the Fields
My August 2006 and September 2006 "Learning Curve" columns covered the new Field objects introduced in AutoCAD 2005. Fields are automatically updating text objects that can be used to display things such as the date last plotted, the area enclosed by a polyline and so on.
So how do you get an attribute that automatically updates like a field? Easy. Refer to the Attribute Definition dialog box in the first figure. At the right end of the Value window simply click on the Field Insert button to invoke the Field command. Note that you also can add regular text before and after the field.
Now What Do I Do?
Now that you know how to create and manipulate attributes, let's take a look at some uses for them.
Many articles focus on the fact that it's possible to have AutoCAD search through a drawing looking for specified attribute tags. AutoCAD then can write to an external file the attribute values attached to those tags, plus a host of other data such as the block name and the insertion coordinates. Thus, you can easily extract a telephone directory from an office layout or a list of all 20hp motors in a factory and so on.
Data extraction is not the only use, however. Virtually every user can use attributes in things such as title blocks. They make it much faster to fill in the boxes, because you only need to supply the requested values. All the location, style, size, layer and other text specifications are taken care of by the attributes. It also helps to ensure compliance with standards.
Related to the latter suggestion is the fact that any file on disk can be inserted into the currently open one, at which point it becomes a block definition. It's unnecessary to create the block definition within the incoming file.
If the incoming file includes attribute definitions, then you are prompted for their values just as if the block definition already existed in your drawing.
And Now for Something Completely Different . . .
When you stay at an all-inclusive tropical resort, be sure to bring a large insulated mug. They keep your drinks cold in the hot sun, and the larger size means fewer trips to the beach bar.
Create Professional 3D Models Anywhere - Shapr3D is an industrial-strength CAD tool that runs natively on your iPad. Import and Export files from most major desktop applications. Find out more and download a free copy here!
Running AutoCAD? Test Your Hardware! Designed to test and compare the performance of systems running AutoCAD, Cadalyst's Benchmark Test is a popular and long-time favorite.