Are Your Blocks Smart?1 Jan, 2000 By: Lynn Allen
Realizing that many of you are still on AutoCAD Release 14, I've decided to throw in a column you can all relate to. And even if you are still back on AutoCAD R12 or up to AutoCAD 2000, you'll be able to use it. Of course I'll toss in a couple of cool new features from AutoCAD 2000 as a bonus. I chose the Attributes topic because I've received a bunch of emails asking about them, so it must be time for an updated stab at them!
Just about all of us use blocks in our day-to-day drawing life. Why not make them smart? When you insert a title block, do you tediously go through the process of entering line after line of text to fill in the boxes? Or do you have it set up so the block automatically prompts you for the answers while you sit back and watch AutoCAD fill in the boxes for you? When you insert a part, would you like to store the model number, cost or anything else along with it? Perhaps later you'd like to extract the information into a bill of materials and insert the information into the drawing. All of this is possible with Attributes.
I'm going to use a very simple example of a sofa with four attributes. The first attribute will be Room No., the second attribute will be Furniture type, the third attribute will be Manufacturer and the fourth attribute will be Cost. The sofa will look similar to Figure 1 after you add the attributes.
Figure 1. The four attributes to use in the sofa block are Room_No, Furniture_Type, Manufacturer and Cost.
Figure 2. Use the ATTDEF dialog to define block attributes. Here I've added Room_No to the definition and have set no modes.
Figure 2 shows the ATTDEF dialog with our first attribute added. Let's get familiar with the dialog box before we jump in and create our attribute definitions.
There are four different modes you can apply to your attributes: Invisible, Constant, Verify and Preset. An Invisible attribute contains data, but that data doesn't display on the drawing. An example of this might be the cost of an object. The information is stored with the drawing; you can extract the information, but you don't want it to display on the final plotted drawing. You can override an attributes Visibility mode by setting ATTDISP to ON. Our Cost attribute will be an Invisible attribute.
I find that Constant attributes are seldom used. A Constant attribute can never change. It's practically the same thing as assigning Text to a block, except you can export this text to an external file. When inserting a block with a Constant attribute, you will not be asked to input any information; the data stored when the block is created will always remain the same. Let's set our Furniture Type attribute to be a Constant attribute that says Sofa. This object will always be a sofa. Later you might choose to extract the furniture types into an external file.
Verified attributes are a rare breed as well. If you had a complicated model number or a key piece of information that absolutely must be accurate, you might choose to use the Verify mode when creating your attributes. When inserting a block with a verified attribute, you'll be prompted twice to verify that the information you provided was correct. If ATTDIA is set to 1, this attribute mode has no effect. Just for the heck of it, let's set our Manufacturer attribute to be verified.
If you have an attribute that defaults to a specific value 90 percent of the time, you might consider making it a Preset attribute. This mode is similar to Constant in that you won't be prompted for the attribute value, but it's changeable after the fact. If ATTDIA is set to 1, you won't notice the effect of setting the Preset mode ON for an attribute. (Note: I'll address this ATTDIA function later on.)
The three main parts that comprise the attribute definition are the Tag, Prompt and Value. The Attribute Tag is the name you'll use to refer to the attribute. You will specify what information you want extracted by using this tag, which can have up to 256 characters but no spaces or exclamation marks (!). AutoCAD will automatically convert the tag to uppercase. I found, however, that I could use the new Object Properties dialog in AutoCAD 2000 to override that (but heaven only knows what problems this might cause).
When inserting a block with attributes, your users will see a prompt asking them what they want the attribute value to be. You have complete control over this prompt. If you are asking for a revision number, then that prompt could look like any of the following:
Enter revision number:
Hey buddy, put the revision number here!
If you leave the attribute prompt empty, AutoCAD will substitute the attribute tag for the prompt. Unlike the tag, you'll find you can use spaces in the attribute prompt. You'll also find that there is no prompt for Constant attributes since they are unchangeable.
Just as you do with all good commands, you'll want to include a default value. In most cases, this value should be the most common value assigned to the attribute. This eliminates extra work when inserting the block since you'll be able to just accept the default and go on. In some cases you can use the default to denote the type of input. For example:
dd/mm/yy would be the default, indicating that you wanted the date to be input by day, month and year.
After you've selected the modes and set up the description, you'll need to position the attribute definition on the block. Do you want it centered? What height and text style would you like the attribute to use? All of this information is determined by the lower half of the ATTDEF dialog box. I think this information is self explanatory, so I'll proceed. For the record, the height I used on my sofa was 4 units.
The first attribute I'm including is the Room Number attribute. Figure 2 shows that I've set no modes for this attribute, that the Tag is called ROOM_NO, the prompt is Room No. and the default denotes I'd like four digit input-NNNN.
Figure 3. Because Furniture_Type is a Constant attribute, its Verify, Preset and Prompt options are grayed out.
Figure 4. For the Manufacturer attribute, we'll use a Preset value of Ethan Allen.
I wanted the second attribute to go directly beneath the first attribute. In the lower left-hand corner of the dialog you'll notice an option that says "Align below previous attribute definition." When selected, you won't be prompted for any height, rotation or placement since this will all be controlled for you.
Figure 4 shows the third in our line of attribute definitions. This attribute is Preset as indicated and also placed beneath the previous attribute.
Figure 5 shows that our fourth (and last) attribute is Verified. Since the Prompt and Tag are the same, I left Prompt blank.
Notice the $ in the value? If you ever choose to extract the data, you'll probably want to leave the dollar sign out of the attribute definition. I suspect you'd want this field to be numeric, and that
Figure 5. The fourth (and last) attribute, Cost, sets the Mode at Verify.
I've heard of users making one attribute, copying it several times on a block, then editing the default values to save time. This is fine as long as you have no intention of ever extracting the data. If your blocks have multiple attribute tags with the same values, scary things will occur in the extraction process!
After you've added your attributes, you are ready to make a block (or WBLOCK) out of your new sofa. Go ahead and make your block as you usually do with the exception of one step-the order in which you select the attributes will be the same order in which AutoCAD prompts you for them later when inserting. If you want AutoCAD to prompt you starting from the top down, then you should individually select them in that order. If you use a window to select the objects, there's no telling in what order the attributes will prompt you. It's much easier to get the prompts in the proper sequence now, than to change the prompt order after the fact.
Now you're ready to INSERT your new block with its attributes. The command-line sequence below should mirror your results:
Specify insertion point or [Scale/X/Y/Z/Rotate/ PScale/PX/PY/PZ/PRotate]:
Enter attribute values
Cost <$900.00>: $795.00
Room Number <NNNN>: 1043
You'll notice that since the Manufacturer attribute was set to Preset, you were not prompted to change it, and the default value was set to Ethan Allen. And of course the Constant attribute, Furniture_Type, will never change, so there was no input required. You'll also note that since you made the Cost attribute tag invisible, it doesn't show up on the inserted blocks.
Many users prefer seeing the attribute dialog box rather than the
Figure 6. Setting ATTDIA to 1 will cause AutoCAD to display a dialog box for attributes, if you prefer not to use the command-line interface.
You'll also notice that the Preset attribute displays in the dialog box and is available for modification.
Go ahead and insert a few desks. Editing attributes should be a dedicated column all to itself, but I'll put it in a quick little nutshell. If you want to change the Attribute Value after you've inserted the block, you can use the DDATTE command-affectionately referred to as Double Date. To change any of the other properties (such as position, height, rotation angle and so on), you'll need to use the ATTEDIT command. If you're using AutoCAD 2000, the only way you can get to the ATTEDIT command is to put a dash in front of the command "-ATTEDIT".
Should you decide you want to see the invisible attributes, the ATTDISP command will display all the attributes, invisible or not, when set to ON.
This is really only a start down the road of Attributes. Next month, we'll take a look at the next phase of attributes-editing and redefining blocks that contain attributes.
Until then ...
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!