Circles and Lines: Add Intelligence to Your Blocks with Attributes

14 Aug, 2005 By: Lynn Allen Cadalyst

Attaching attributes to your blocks automates key information.

AutoCAD's attributes have been a key feature for more than a decade. But as I travel, I find that the creation and extraction of attributes is mostly reserved for the gurus of the world (especially extraction). One of AutoCAD 2006's great features is the ability to extract attributes to a linked AutoCAD table that will update automatically should you add or remove any additional blocks. I'll cover this new feature in the coming months, but thought it best if I started at the beginning for this column.

Attributes bundle data together with your library symbols. They are special text entities that are stored within a block definition. Manufacturing numbers, cost, materials, size, etc., are all examples of possible attributes. When you insert a block, AutoCAD prompts you for the required attribute value information. Later you might choose to use this data to calculate a bill of material, door schedules, etc.

Many users also use attributes to fill in their title blocks. Done properly, your title block would automatically prompt you for the necessary information upon insertion. The text for all your title blocks would consistently be the same height and in the same location. You can easily accomplish this scenario by attaching attributes to your title blocks.

Note: Those of you using AutoCAD 2005 and 2006 might also want to take a look at fields for your title block information.

The ATTDEF Command
Before you start, draw the geometry for your block. If you plan on adding attributes to an existing block, then explode it and you're ready to go. The magical command to add an attribute to your block is the ATTDEF command (figure 1). You'll find the ATTDEF command in the Draw pull-down menu / Block / Define Attributes (well hidden!). You can assign many different settings to your attributes, and they are all set in ATTDEF. Let's take the ATTDEF dialog box apart piece by piece so you have a solid understanding of all the possibilities.

Figure 1. Use the ATTDEF command to create attributes.

The upper left corner of the ATTDEF dialog box lets you turn on four different modes (figure 2).

Figure 2. Select the proper modes for your attributes.
Invisible: An invisible attribute will not display when later inserted as a block. An invisible attribute is usually one you don't want to display on the hard copy. Tags such as material costs, salary information, etc., might be good candidates for the invisible mode. Even though the attributes are invisible, you can still extract their information later.

Constant: Constant assigns a fixed value to the block that you cannot change later. Constant is a great mode for a value that never needs to change. Selecting the constant mode also disables the preset and verify attribute modes.

Verify: When using attributes with complicated values, it is sometimes helpful to reprompt the user to ensure accuracy. We see this all the time when filling forms on the Internet. A complicated model number or code is a good example of a possible verified attribute. Personally, I find this setting somewhat annoying as I dislike keying in any information more than once.

Preset: A preset attribute automatically sets the default value to the block, suppressing the prompt. An attribute that almost always defaults to the same value could be a potential preset attribute. You can change this value if needed (a better choice if you suffer from fear of commitment!).

Creating Attributes
Next we'll move on to the Attribute section. Here you'll set up the prompts and values for your attribute.

Tag: This is the internal title of the desired attribute. This title does not appear on the block after it's inserted, but AutoCAD uses it to extract attribute information down the road. Examples of tag names are model#, date, price, etc. No spaces are allowed, and the tag automatically converts the characters to upper case.

Prompt: This is the prompt the user will see when inserting the block. The prompt might be something like "Enter model no. " or "Drawing name." AutoCAD automatically appends a colon to the end of the prompt for you, so there's no need for you to include one. (You would end up with two!)

Value: This is the default value that displays to the user. Choose the most frequently used value as your default value. If you've chosen to make the attribute constant, you cannot change this value.

For those of you on AutoCAD 2005 or higher, you will see the Insert Field button displayed to the right of the value field. You can also assign fields such as the date as a default value, and the field automatically assigns the date for you using the format you chose (figure 3). Fields are very powerful --attributes on steroids, as I like to call them -- and definitely a topic for a future article!

Figure 3. Use fields as attributes values for efficiency.

After selecting the tag name, prompt and default value, select the justification, height, text style and rotation angle just like you would with standard text. The final step is selecting the attribute location relative to the block. In most cases you'll manually select the location. If you'd like your attributes to line up one below the other, you can select Align Below Previous Attribute Definition. This option only becomes available after you've created one attribute (which is logical). New to AutoCAD 2006 is the Lock Position in Block option. When selected, you cannot move the attribute position.

After everything in the ATTDEF command is as you want, select OK and you created your first attribute!

If you need to change anything, it's best to do so before turning it into a block. The Properties command is your best bet for making changes to the attribute, double-clicking on the attribute will only let you change the value information (figure 4).

Figure 4. Double clicking on an existing attribute lets you modify the tag, prompt and value only.

Inserting Blocks
After adding all the attributes you can turn it into a block.

Try inserting your new smarter block a few times. If you created a preset or constant attribute, AutoCAD won't prompt you for a value. The other attributes, however, will issue prompts, and you'll need to answer. Pressing the Enter key accepts the default value as you would expect. By default, AutoCAD prompts for attribute information on the command line. Most of us prefer to work with a dialog box, and you can get one for your attributes by setting ATTDIA to a value of 1. (I get asked about this ALL the time!) Personally, I think it should just be the default.

You can force invisible attributes to display with the ATTDISP command.

ATTDISP has three modes: Normal, On and Off. Normal displays the attributes as created; On turns all attributes on regardless of their previously defined mode; and Off makes all attribute definitions invisible. ATTDISP automatically regenerates the screen to make the appropriate display changes.

You may wish to suppress the prompts when inserting your blocks. (Maybe you have a rush job and no time for setting attributes.) You can turn off the system variable ATTREQ to disable the attribute prompts. You can edit the attribute values later when you have more time.

Well that's a lot to digest in one sitting -- the key here is practice, practice, practice. Next month we'll dive deeper into the amazing world of attributes and help you kick the IQ up even further in your drawing files!

Until next month, Happy AutoCAD-ing!

More News and Resources from Cadalyst Partners

For Mold Designers! Cadalyst has an area of our site focused on technologies and resources specific to the mold design professional. Sponsored by Siemens NX.  Visit the Equipped Mold Designer here!

For Architects! Cadalyst has an area of our site focused on technologies and resources specific to the building design professional. Sponsored by HP.  Visit the Equipped Architect here!