Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Autocad 2005 And Autocad LT 2005 Bible (2004).pdf
Скачиваний:
92
Добавлен:
17.08.2013
Размер:
32.22 Mб
Скачать

508 Part III Working with Data

Using Windows Features

You can also insert objects by copying them from other drawings and pasting them into your current drawing or using the drag-and-drop feature. You may be able to insert objects in this way without creating blocks.

Manipulating objects with the Windows Clipboard

You’re probably familiar with cutting or copying data in other Windows applications and then pasting it, either within a file or from file to file. Table 18-2 compares copying, using blocks, and using the clipboard (with the CUTCLIP, COPYCLIP, and PASTECLIP commands).

Table 18-2: Comparison of Methods of Moving/Copying Objects

Method

Features

 

 

MOVE/COPY

Precise placement of objects; only works within a drawing.

BLOCK/WBLOCK/

Precise placement of objects; can scale and rotate; creates block definition; can

INSERT

insert many times even after other commands; can insert files (other drawings)

 

that you save permanently. With the DesignCenter or Tools palette, you can insert

 

blocks from other drawings.

CUTCLIP/

No precise placement of objects (uses bottom-left corner of extents of object(s)

COPYCLIP/

you copy); creates anonymous block in file with a name like A$CE314; can scale

PASTECLIP

and rotate; can both move and copy objects; can insert (paste) many times; can

 

copy from drawing to drawing or to other Windows applications.

 

 

In general, for one-time moving or copying with a drawing, you should use the MOVE or COPY command. If you want to copy an object several times over a period of time, use a BLOCK command. Use the Clipboard when you want to insert objects into another drawing one or more times without saving the objects. Also, the clipboard is indispensable for copying objects to other applications.

To place objects on the Clipboard, first select them. To move them, choose Cut to Clipboard on the Standard toolbar. To copy them, choose Copy to

Clipboard. You can paste objects that you’ve copied to the Clipboard into the same drawing as a block using the PASTEBLOCK command — right-click and choose Paste as Block. If you want to paste the objects in another drawing, open that drawing. Choose Paste from Clipboard on the Standard toolbar. The command line prompts you for an insertion point.

Cross-

Chapter 27 covers moving and copying objects to other applications.

Reference

 

Using drag-and-drop

The drag-and-drop feature in Windows enables you to drag another drawing file into your drawing. Then your drawing prompts you as it would if you inserted the file using the -INSERT command. You need to open either My Computer or Windows Explorer. In the following steps, I use Windows Explorer.

Chapter 18 Working with Blocks and Attributes

509

To insert a drawing file using drag-and-drop, follow these steps:

1.Open Windows Explorer (Choose Start Programs Windows Explorer).

2.In the Folders window, click the folder containing the drawing file you want to insert.

3.Locate the drawing file.

If the drawing window is visible, drag the drawing file into the AutoCAD window.

If the drawing window is not visible, drag the drawing file onto the AutoCAD or AutoCAD LT button on the task bar, wait for your drawing to appear, and then drag the file into the drawing window.

4.Respond to the prompts of the -INSERT command on the command line.

When you drag the file into the drawing area, you see a plus sign at the cursor (or a rectangular cursor, depending on your operating system), indicating that you can drop the file.

To open a drawing instead of inserting, drag the file onto the application title bar at the very top of the application window or simply double-click its icon in Windows Explorer. If you drag with the right mouse button, when you release the mouse button in the drawing area, you have some additional options to create an external reference (Create Xref) or create a hyperlink.

Tip

If you really don’t know where the file is, or you’re not even sure of its name, use the Windows

 

Find feature. Choose Start Find/Search Files or Folders. On the screen that appears, set the

 

criteria for the file. For example, you could find all drawings starting with the letter C by typing

 

c*.dwg in the Named text box. From the resulting list, choose the drawing you want and drag

 

it onto your drawing using the same steps listed previously.

Drag-and-drop is easy to use. It’s a helpful tool if you aren’t sure where the file you want is located because it’s easier to navigate with Windows Explorer than from the Select Drawing File dialog box.

You can also drag an object from one drawing to another. First open both drawings. It helps to be able to see them both at once. Choose Window Tile Vertically to see them side by side. Select the object or objects you want to copy. Now click the object or objects again, and hold down the mouse button until the cursor displays a small rectangle. Then drag the object(s) to the other drawing.

On the

The drawings that you need for the following Step-by-Step exercise on using the Windows

CD-ROM

Clipboard and drag-and-drop, ab18-f-1.dwg and ab18-f-2.dwg, are in the Drawings

 

folder on the CD-ROM.

STEP-BY-STEP: Using the Windows

Clipboard and Drag-and-Drop

1.Open ab18-f-1.dwg from the CD-ROM. This is a set of office furniture, as shown in Figure 18-14.

2.Pick the chair, which is a block and choose Copy to Clipboard from the Standard toolbar.

3.Choose Open from the Standard toolbar. Open ab18-f-2.dwg from the CD-ROM. This is the plan of an office building, as shown in Figure 18-15.

510 Part III Working with Data

Figure 18-14: A set of office furniture.

Figure 18-15: The office plan.

1

2

4.Save the drawing as ab18-06.dwg in your AutoCAD Bible folder.

5.Choose Paste from Clipboard from the Standard toolbar. At the Specify insertion point: prompt, pick 1 in Figure 18-15. This action inserts the arm-

chair in the lobby using the default scale and rotation.

6.Choose Window Tile Vertically. You can now see both drawings at once. Click in ab18-f-1.dwg to activate it. Select the chair. Click and hold the left mouse button on the chair again until you see the small rectangle at the cursor. Drag the chair into ab18-06.dwg and place it next to the first chair.

7.Click the Close button of ab18-f-1.dwg. (You don’t need to save any changes.) Click the Maximize button of ab18-06.dwg.

Chapter 18 Working with Blocks and Attributes

511

8.From the task bar menu, choose Start Programs Windows Explorer. Locate ab18- f-1.dwg on the CD-ROM. If necessary, resize the Exploring window so that you can see some of the drawing window.

9.Drag ab18-f-1.dwg from its listing in Windows Explorer onto the drawing area and release the mouse button.

10.Use Zoom Window to zoom in to the area around 2 in Figure 18-15. At the prompt, pick 2.

11.Press Enter three times to accept the defaults and insert the entire drawing.

12.Choose Zoom Previous from the Standard toolbar. Save your drawing. It should look like Figure 18-16.

As you can see, copying to the Clipboard is ideal when you want to insert part of an existing drawing into another drawing. Drag-and-drop is also a simple way to insert one or more objects or an entire drawing.

Figure 18-16: The office plan with added chairs and office furniture.

Working with Attributes

Your drawings do not exist in a vacuum. The objects in your drawing represent real objects. These objects have characteristics that you cannot visually represent in a drawing, such as cost, manufacturer, date purchased, and so on. Attributes are labels that are attached to blocks. Using attributes, you can attach labels with pertinent data to blocks. You can then extract the data and import it into a database program or spreadsheet.

512 Part III Working with Data

Cross-

You can also access and link to outside databases from within AutoCAD. See Chapter 20 for

Reference

more information on external databases.

 

Attributes can also be used to place text relative to blocks. A common example is to use attributes for completing title block information, such as the drawing name, drawing number, date, scale, revision number, drafter, and so on. In this case, your plan is not to extract the data at all — you just use the attributes to help you precisely place the text in the title block.

Attributes have several limitations. They can only be attached to blocks. However, you can create a dummy block that contains only attributes. Also, the database features are limited. Nevertheless, attributes are quite useful for simple database needs as well as for placing text.

New

In AutoCAD only, you can now add fields to attributes. For more information, see the discus-

Feature

sion of fields in Chapter 13.

 

Defining an attribute essentially creates a template into which you can place values when you insert the block. You define a tag that is equivalent to a field or category in a database. When you insert the block, you’re prompted for the tag’s value. For example, if your tag is COST, the value may be 865.79. This template is called an attribute definition.

Creating attribute definitions

The first procedure when working with attributes is to draw the individual objects that are to make up the block. The exception is when you want to create attributes without creating any other objects in the block. You might do this to extract attributes that apply to the drawing as a whole.

Tip

If the block already exists, explode it and then redefine the block, adding the attributes.

After you have the objects, choose Draw Block Define Attributes to start the ATTDEF command. The Attribute Definition dialog box opens, shown in Figure 18-17.

Figure 18-17: The Attribute Definition dialog box.

Chapter 18 Working with Blocks and Attributes

513

Mode section

The Mode section of the dialog box sets certain attribute properties including visibility and default value. These properties are shown in Table 18-3.

 

Table 18-3: Attribute Modes

 

 

Mode

Explanation

 

 

Invisible

The attribute values you set are not displayed in the drawing. Use this for attributes that

 

you want to extract into a database but do not want to see in the drawing. Examples

 

would be model numbers, purchase dates, cost, and so on. If you’re using attributes to

 

place text in a drawing, of course you want them to be visible.

Constant

Sets a constant value for an attribute. The attribute automatically takes the attribute value

 

you set (in the Attribute section of the dialog box) and you do not get a prompt for a

 

value. You might use this for the first three digits of employees’ telephone numbers that

 

have the same first three digits. You cannot edit constant attribute values.

Verify

When you insert an attribute, you get a prompt to verify the value. Use this option if you

 

have a preset default.

Preset

Automatically inserts a default value that you specify. For example, if the most common

 

manufacturer of a chair is American Interiors, you can specify this as a preset value. As you

 

insert the block, this default is inserted for you, and you have to type a value only if it

 

differs from the default. (You need to insert the attribute with the ATTDIA system variable

 

set to 1 to get a prompt allowing you to change the value. See the explanation of ATTDIA

 

later in this chapter.)

 

 

 

Attribute section

 

In the Attribute section of the dialog box, specify the Tag, which is the name of the attribute.

 

You use this tag when you extract the attributes. A tag is equivalent to a field in a database. If

 

you import the data into a spreadsheet, for example, the tags would be the column heads. The

 

tag name cannot include spaces or exclamation points (!) and is converted to uppercase letters.

 

The Prompt is simply a plain-English version of the tag. The prompt asks you for the value of

 

the attribute. If the tag is PUR_DATE, you could define the prompt as Date Purchased.

 

The Value is used for setting a default value. You can use this if the value is usually the same.

 

To insert a field, click the Insert Field button and choose a field from the Field dialog box, as I

 

explain in Chapter 13. When you insert the block and are prompted for a value, you can use

 

the field value or change it.

Tip

You can use the value to clarify a format that should be followed when entering information.

 

For example, you could set the value of a date to dd/mm/yy so that users know how to for-

 

mat the date.

 

Text Options section

Use the Text Options settings to format the text. Choose a justification and text style from the drop-down list boxes. When you set the height, be sure to take into account the scale factor. You can also set a rotation angle for the text.

514 Part III Working with Data

Insertion Point section

In the Insertion Point section, choose Pick Point to place the attribute. If you’re using the attributes to place text in a schedule or title block, obviously the placement is very important. If you’re inserting invisible attributes, simply place them near the block. If you’re creating more than one attribute for a block, place the attribute so there is room for the other attributes underneath. When you’ve placed the attribute and completed the entire dialog box, click OK to end the ATTDEF command. By default, the insertion point is 0,0.

Caution

If you’re creating an attribute for a table or an electrical symbol, you don’t want the insertion

 

point to be 0,0. Instead, you want an insertion point near the block. If you forget to pick a

 

point and click OK to close the dialog box, the default insertion point is at 0,0. If 0,0 isn’t vis-

 

ible on the screen, you don’t see the attribute — it seems to disappear! You can choose Undo

 

from the Standard toolbar and create a new attribute in the right location or move the

 

attribute as explained in the section on editing attributes later in this chapter.

After you define one attribute, the Align Below Previous Attribute Definition check box is active. Click this to line up succeeding attributes under the first one.

Now is the time to check that the attribute definitions are the way you want them. You can edit attribute definitions before they’ve been placed into a block in two ways:

Choose Properties on the Standard toolbar, select one attribute definition, and edit all its properties, such as the tag, value, prompt, and modes. You can also change properties such as the layer, text style, and so on.

Choose Modify Object Text Edit and change the tag, the prompt, and the default (DDEDIT command).

Tip

If you’re creating many blocks with similar attributes, you can copy just the attributes, mod-

 

ify them as just described, place them near other objects, and then create the blocks. This

 

way, you don’t have to define all the attributes from scratch.

Creating the block

After you create the objects and their attribute definitions, you generally create a block. Then choose Make Block from the Draw toolbar. Select the objects and the attributes in the block.

Tip If the order of the attribute prompts is important, don’t use a window to select the attributes — select them in the order in which you want the prompts to appear. You can then use a crossing or window box to select the rest of the objects to be included in the block. The order of the attribute prompts will be important if you’re taking the data for the attributes from a listing — perhaps a spreadsheet that you’ve printed out. Inserting the attribute values will be much easier if the prompts follow the order of the printed document you’re using.

Name the block and define the block’s insertion point as you would normally. Generally, you want to check Delete from Drawing because you have no need for the block with the attribute tags in your drawing.

Don’t forget to pay attention to the layer of the attributes just as you would the layer of the block objects. The same layer rules apply to attributes as to blocks.

Chapter 18 Working with Blocks and Attributes

515

Note If you want to insert the objects and the attributes as a file instead of as a block, you don’t need to create a block at all. Create a drawing containing just the objects and its attributes. Use the BASE command to change the base point of the drawing (usually 0,0) to the desired insertion point of the block. Then save the drawing. When you insert the drawing, you get prompted for the attributes as usual. Use this technique for blocks and attributes that you use for more than one drawing, such as a title block.

After you create the block, you cannot edit the attributes in the Properties palette. I cover other techniques for editing attributes later in this chapter.

On the

The drawing that you need for the following Step-by-Step exercise on creating attributes,

CD-ROM

ab18-g.dwg, is in the Drawings folder on the CD-ROM.

STEP-BY-STEP: Creating Attributes

1.Open ab18-g.dwg from the CD-ROM. This is a plan of an office building zoomed in to one office. A file containing one set of office furniture has been inserted, as shown in Figure 18-18.

2.Save the drawing as ab18-07.dwg in your AutoCAD Bible folder.

3.Choose Explode from the Modify toolbar, select the furniture in the office, and press Enter. This block has nested blocks. Choose the chair and explode it again to get its component objects.

4.Choose Draw Block Define Attributes. In the Attribute Definition dialog box, check Invisible in the Mode section.

5.In the Attribute section, enter the following:

Tag: mfr

Prompt: Manufacturer

Value: American Office Furniture

6.Click Pick Point to temporarily return to the drawing. Pick point 1 in Figure 18-18. Leave the Text Options as they are. Click OK to end the command.

7.Repeat the ATTDEF command. Click Align below previous attribute definition. Enter the following:

Tag: pur_date

Prompt: Date purchased

Value: 3/91

8.Click OK.

9.Choose Make Block from the Draw toolbar. In the Name text box, type armchair. Click Select Objects. Select the entire chair plus the two attributes. End selection. The dialog box shows that 18 objects are selected. Choose Pick Point. Use the Endpoint object snap to choose 2 as the base point. Check Delete. Click OK.

10.A message asks if you want to redefine the block because there is already a block definition with the same name in the drawing. Choose Yes.

11.Save your drawing. If you’re continuing on to the next Step-by-Step exercise, leave the drawing open.

516 Part III Working with Data

Figure 18-18: An office with a set of office furniture.

2

1

Note Redefining a block updates only block geometry, not attributes. Therefore, if you add attribute definitions to a block, only new blocks that you’ll insert include the attributes. Existing blocks don’t gain these new attribute definitions. To update existing blocks with their current attribute definitions, use the ATTSYNC command (AutoCAD only).

Inserting blocks with attributes

After you define a block with attributes, you insert it as you would any block. Your drawing automatically senses the existence of the attributes and prompts you for their values.

Note

You can insert attributes either in a dialog box or on the command line. By default, you insert

 

them on the command line. To use a dialog box, set the system variable ATTDIA to 1. You

 

would use the command line to automate the insertion of attributes using an AutoLISP rou-

 

tine, menu item, or script file. When you use a dialog box, the Verify and Constant modes are

 

not used. To skip all the prompts and automatically use default values that you have set, set

 

the ATTREQ system variable to 0.

On the

The drawing that you need for the following Step-by-Step exercise on inserting blocks with

CD-ROM

attributes, ab18-07.dwg, is in your AutoCAD Bible folder if you did the previous exercise.

 

Otherwise, you can find it in the Results folder on the CD-ROM.

STEP-BY-STEP: Inserting Blocks with Attributes

1.Use ab18-07.dwg if you have it open from the previous exercise. Otherwise, open it from the Results folder of the CD-ROM.

2.Save the drawing as ab18-08.dwg in your AutoCAD Bible folder.

3.Type attdia . If it’s currently set to 0, type 1 .

Chapter 18 Working with Blocks and Attributes

517

4.Choose Insert Block from the Draw toolbar. Chose ARMCHAIR from the Name drop-down list. Verify that Specify On-Screen is checked only for Insertion Point and click OK.

5.Pick a point in front of the desk (turn off OSNAP if necessary) to insert the armchair and open the Enter Attributes dialog box, as shown in Figure 18-19. The values that were entered when the attributes were defined are displayed, but you can change them.

Figure 18-19: The Enter Attributes dialog box.

6.The default values exist because most of the furniture was purchased at one time when the office was opened. However, let’s assume that this chair was purchased recently. Change the purchase date to 3/04. Click OK. Because the attributes are invisible, you see only the chair, but the values are there in the drawing database.

7.Save the drawing.

Editing attributes

You can edit the properties of the attribute tags before you create the block, using the Properties palette or DDEDIT (choose Modify Object Text Edit). After you create the block, if you have AutoCAD, use the Block Attribute Manager. The Block Attribute Manager manages all properties of block attributes in one place. Use the Block Attribute Manager and its Edit Attribute dialog box to edit any aspect of block attributes. If you have AutoCAD LT, use the Edit Attributes dialog box (ATTEDIT command).

Editing attribute properties in AutoCAD

After you insert a block and give values to its attributes, you can modify the following:

Attribute prompt order

Tag and prompt names

Attribute visibility

Text options

Properties (layer, linetype, color, lineweight, and plot style)

Value

518 Part III Working with Data

After you make your changes, you can update all the blocks in your drawing to reflect the changes.

Choose Modify Object Attribute Block Attribute Manager to start the BATTMAN command and open the Block Attribute Manager, shown in Figure 18-20.

Figure 18-20: The Block Attribute

Manager.

From the Block drop-down list in the Block Attribute Manager, choose the block whose attribute values you want to change. You can also click Select Block to select the block in your drawing. Use the Block Attribute Manager to:

Change the order of the attribute prompts when you insert a block with attributes.

Choose any attribute from the list in the Block Attribute Manager and click Move Down or Move Up. Continue to use this procedure until you have the order you want.

Delete an attribute. Choose it and click Remove.

Change which attribute properties are listed in the Block Attribute Manager. Click Settings. In the Settings dialog box, click all the properties you want to see listed. For example, you can include columns for layer, style (text style), and color. Click OK.

Tip

When you add properties to the listing in the Block Attribute Manager, resize the dialog box

 

so that you can see all the columns.

Edit the attributes, including prompt, default, text display, and properties. Click Edit to open the Edit Attribute dialog box, shown in Figure 18-21.

Update all the blocks in your drawing to reflect the changes you’ve made. Click Sync. Usually you do this after using the Edit Attribute dialog box. Because changes such as attribute order and mode affect only new insertions of the block, this update brings existing blocks into concordance with new blocks.

Use the Edit Attribute dialog box to edit all the properties of individual attributes. This dialog box has three tabs:

Attribute: Change the mode and attribute properties. For example, in the Mode section, you can change the visibility of attributes. In the Data section, change the tag, prompt, and default. You can right-click the Default text box and choose Insert Field to use a field. (See Chapter 13 for the discussion of fields.)

Text Options: Change text style, height, justification, and so on.

Properties: Change attribute layer, color, linetype, and so on.

Chapter 18 Working with Blocks and Attributes

519

Figure 18-21: The Edit Attribute dialog box.

After you finish making changes, click OK in the Edit Attribute dialog box to return to the Block Attribute Manager. Click OK to return to your drawing.

When you create invisible attributes, you can’t edit them because you can’t select them. The ATTDISP command controls attribute visibility globally, for all attributes in your drawing. Choose View Display Attribute Display and choose one of the following options. The currently active option is checked on the menu.

Normal: Attributes that were created as visible are visible. Attributes that were created as invisible are invisible. This option is the default.

On: All attributes are visible.

Off: All attributes are invisible.

Changing the current option causes your drawing to regenerate.

On the

Insrot is a program that inserts block at a specified rotation but keeps the attributes hori-

CD-ROM

zontal. Look in \Software\Chap18\Insrot.

You may need to change the values of an attribute. Perhaps you entered the wrong purchase date or a part number changes. Choose Modify Object Attribute Single to start the EATTEDIT command and select the block containing the attributes you want to change. You see the Enhanced Attribute Editor, shown in Figure 18-22.

Figure 18-22: The Enhanced Attribute

Editor.

520 Part III Working with Data

As you can see, the Enhanced Attribute Editor is similar to the Edit Attribute dialog box. It has the same three tabs. However, the Attribute tab enables you to change attribute values, something you can’t do in the Edit Attribute dialog box. To change an attribute’s value, select it and type a new value in the Value text box. In AutoCAD only, you can right-click the Value text box and choose Insert Field to use a field. (See Chapter 13 for more about fields.)

The Text Options and Properties tabs of the Enhanced Attribute Editor are the same as in the Edit Attributes dialog box.

Caution

If you explode a block with attribute values, you lose the attribute values.

Editing attribute properties in AutoCAD and AutoCAD LT

In both AutoCAD and AutoCAD LT, you can change attribute values using the ATTEDIT command to open the Edit Attributes dialog box, shown in Figure 18-23.

Figure 18-23: The Edit Attributes dialog box.

If a block has a number of attributes and you want to change them all in order, this dialog box makes it easy to go through all the attributes quickly. Press Tab to go to the next attribute.

In AutoCAD LT, one way to change attribute properties is to explode the block and doubleclick the attribute. This starts the DDEDIT command and opens the Edit Attribute Definition dialog box, where you can change the tag, prompt, and default value. You can then redefine the block. This method works in AutoCAD, but is not necessary if you use the Block Attribute Manager, as explained in the previous section.

To edit attributes on the command line, type -attedit. At the Edit attributes one at a time? [Yes/No] <Y>: prompt, use the Yes option. This command then prompts you for changes in attribute values and properties, such as position, text style, color, and so on.

Making global changes in attributes

In both AutoCAD and AutoCAD LT, you can also use the -ATTEDIT command on the command line to make global changes. If you answer No to the Edit attributes one at a time? [Yes/No] <Y>: prompt, you can make global changes to attribute values — for example,

Chapter 18 Working with Blocks and Attributes

521

change all instances of A- in your part numbers to B-. You can even change invisible attribute values.

To use -ATTEDIT to make global changes, follow these steps:

1. Choose Modify Object Attribute Global.

2. At the Edit attributes one at a time? [Yes/No] <Y>: prompt, type n .

3.At the Edit only attributes visible on screen? [Yes/No] <Y>: prompt, answer y or n , as desired. Answer n to edit invisible attributes, but you must know the attribute text string you want to change because it’s invisible.

4.At the Enter block name specification <*>: prompt, you can type a block name to limit the changes to one block or press Enter to include any block.

5.At the Enter attribute tag specification <*>: prompt, you can type a tag to limit the changes to one tag type or press Enter to include any tag.

6. At the Enter attribute value specification <*>: prompt, you can type a value to limit the changes to one value or press Enter to include any value.

7.If you chose to edit only attributes visible on-screen, you see with the Select Attributes: prompt. (If not, skip to Step 8.) Pick each attribute you wish to modify or use a window. Press Enter to end selection. If you include other objects or blocks that do not fit the block name, attribute tag, or attribute value specifications you made, these other objects are not selected. The command line informs you how many attributes were selected.

8.At the Enter string to change: prompt, type the text string (any consecutive text) you want to change.

9.At the Enter new string: prompt, type the text string that will replace the old string.

If you chose to edit attributes not visible on the screen, the drawing regenerates and the command line lists the changes it made.

Redefining attributes

AutoCAD LT does not include this feature. Instead, explode the block and start from scratch. You can also use the DDEDIT command to change attributes after you explode a block.

You can redefine a block with attributes to include different objects and attributes, using the ATTREDEF command. Redefining a block lets you add or delete attributes or redefine a block that contains attributes. Follow these steps:

1.Explode one of the blocks with attributes. If there are nested blocks that you want to change, explode them, too.

2.If you want to add attributes, define and place them. Delete unwanted attributes. Make any other changes you want to the objects.

3.Type attredef .

4.At the Enter name of Block you wish to redefine: prompt, type the name of the block.

522 Part III Working with Data

5.At the Select objects for new Block...: prompt, select the objects and the attributes you wish to include. Do not include any existing attributes that you want to delete.

6. At the Specify insertion base point of new Block: prompt, pick the base point for the block.

Here’s how your drawing handles the changes:

On the

CD-ROM

If you created new attributes, the command places them for all existing blocks and gives them their default values.

Any attributes that you did not change retain their old values for all existing blocks.

Any attributes that you did not include in the new block definition are deleted from existing blocks.

The drawing that you need for the following Step-by-Step exercise on editing attributes, ab18-h.dwg, is in the Drawings folder on the CD-ROM.

STEP-BY-STEP: Editing Attributes

1.Open ab18-h.dwg from the CD-ROM.

2.Save the file as ab18-09.dwg in your AutoCAD Bible folder. This is a portion of an office building plan layout, shown in Figure 18-24.

3.Choose Modify Object Attribute Single.

If you have AutoCAD: At the Select a block: prompt, In the Value text box of the Enhanced Attribute Editor, change the date purchased to 4/97.

If you have AutoCAD LT: At the Select block reference: prompt, pick the chair

at 1 in Figure 18-24. In the Edit Attributes dialog box, change the date purchased to 4/97.

Notice that the manufacturer is American Office Furniture. Because these attributes are invisible, you can’t see the result in the drawing. Click OK.

4.To see the attributes, choose View Display Attribute Display On. You can now see the attributes for the chair as well as nearby attributes for the desk. To turn off the attributes, repeat the process, this time choosing the Normal option.

5.Choose Modify Object Attribute Global. Follow the prompts:

Edit attributes one at a time? [Yes/No] <Y>: n

Performing global editing of attribute values.

Edit only attributes visible on screen? [Yes/No] <Y>: n

Drawing must be regenerated afterwards.

Enter block name specification <*>: armchair Enter attribute tag specification <*>: Enter attribute value specification <*>:

6 attributes selected.

Enter string to change: American

Enter new string: Acme (Press F2 to hide the text window if it is open.)

Chapter 18 Working with Blocks and Attributes

523

3

4

2 1

Figure 18-24: An office building plan layout.

6.Choose Explode from the Modify toolbar and select the chair at 1 in Figure 18-24. Press Enter to end selection. The attributes reappear but without their values. Choose Draw Block Define Attributes. Create an invisible attribute with a tag and prompt of Color and a value of Dusty Blue. Click OK and pick an insertion point underneath the other two attributes of the armchair. (You’ll need to pan down a little. Exact placement is not important.) Choose OK.

7.To redefine the block, do one of the following:

If you have AutoCAD: Type attredef . Follow the prompts:

Enter name of Block you wish to redefine: armchair

Select objects for new Block...Select objects: Use a window to select the chair and the three attributes. Press Enter to end selection.

Specify insertion base point of new Block: Use an endpoint object snap to pick the endpoint at 2.

If you have AutoCAD LT: Choose Make Block from the Draw toolbar. In the Name text box, enter armchair. Click the Pick Point button and use an endpoint object snap to pick the endpoint at 2. Click the Select Objects button and select all the objects that make up the chair and then the three attributes. Press Enter to end selection. In the Objects section, choose the Delete option. Click OK. Click Yes to redefine the block.

The armchair block disappears.

8.Choose Insert Block. In the Insert dialog box, choose armchair from the Name dropdown list. With Specify On-Screen checked only for Insertion Point, click OK. Insert the chair at 2. In the Enter Attributes dialog box, click OK to accept the values or press Enter to accept the values on the command line.

9.AutoCAD only: To verify that your drawing has redefined the block elsewhere, choose Modify Object Attribute Single. Select the block at 3. Notice that the Color tag has been added with a value of Dusty Blue. Click OK to accept the values. (In AutoCAD LT, the new attribute only appears in the block that you redefined and new blocks that you insert.)

524 Part III Working with Data

10.Use Zoom Window to zoom in closely to the telephone at 4 in Figure 18-24. The telephone has a visible attribute of the phone number. The number is so small that it cannot usually be seen and so does not interfere with the drawing.

11.To modify the properties of this attribute, do one of the following:

If you have AutoCAD: Choose Modify Object Attribute Block Attribute Manager. From the Block drop-down list, choose Phone. Click Edit. On the Attribute tab of the Edit Attribute dialog box, change the prompt to Extension. On the Text Options tab, choose Fit from the Justification drop-down list. On the Properties tab, choose Blue (if you’re using a white background) or Cyan (if you’re using a black background) from the Color drop-down list. Click OK twice to return to your drawing. The text of the phone extension is now blue and fills up the entire rectangle on the phone.

If you have AutoCAD LT: Choose Modify Object Attribute Global. Follow the prompts:

Edit attributes one at a time? [Yes/No] <Y>: Enter block name specification <*>:

Enter attribute tag specification <*>: Enter attribute value specification <*>:

Select Attributes: Select the phone number.

Select Attributes: 1 attributes selected.

Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>: c

Enter new color <BYLAYER>: blue (or enter cyan if you are using a black screen).

Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>:

The phone number is now blue.

12.Choose Zoom Previous from the Standard toolbar. Save the drawing.

The Express Tools command BURST (choose Express Blocks Explode Attributes to Text) converts attributes to text. ATTOUT and ATTIN (choose Express Blocks Export). Attribute Information and Import Attribute Information work together to enable you to edit attributes in another program. ATTOUT creates a tab-delimited file that you can open in Notepad or Excel, for example. When you use ATTIN, existing blocks are updated with the new attribute information.

Extracting a database from attributes

After you insert all your blocks and attributes, you can extract the data using the Attribute Extraction Wizard, shown in Figure 18-25. To start the wizard, choose Tools Attribute Extraction.

The Attribute Extraction Wizard exists only in AutoCAD. For AutoCAD LT, you need to use the method that I explain in the sidebar, “Creating a template file the old-fashioned way.”

Chapter 18 Working with Blocks and Attributes

525

Figure 18-25: The first screen of the Attribute Extraction Wizard.

On the Select Drawing screen of the wizard, choose where you want to extract attributes from. Most often, you want to keep the default of Current Drawing. However, you can select objects (blocks) within the drawing or choose an entirely different drawing. Then click Next.

On the Settings screen of the wizard are two check boxes:

Include xrefs: External references (covered in Chapter 19) can also contain attributes. Check this box if you want to extract attributes from external references that are attached to the drawing.

Include nested blocks: If you want to extract attributes from blocks inside of blocks, check this box.

Click Next to go to the next screen, Use Template. Choose either No Template or Use Template. If you choose Use Template, click the Use Template button to choose a template file. (Template files are covered in the next section.) After you’re done, click Next.

Note Although you can specify the tags and fields you want to extract directly in the Attribute Extraction Wizard and don’t need a template file, you can still create a template file to have more control over the results.

In the Select Attributes screen, shown in Figure 18-26, you choose the blocks you want to work with and their attributes. You can also choose from a number of standard data-extraction fields, such as the coordinates, scale, and layer of the block. These fields are described in the table in the sidebar “Creating a template file the old-fashioned way.”

First, select the blocks you want to work with. Choose Uncheck All or Check All if you only want to check or uncheck one or two from the list. The attributes you’ve created are at the bottom of the attributes list. Click Next after you’re done.

On the View Output screen, you can view the extracted attributes in two forms:

The horizontal view is like a spreadsheet, with a column for each tag and a row for each incident of the block.

The vertical view lists the attribute values vertically so that each value gets its own row.

526 Part III Working with Data

Figure 18-26: The Select Attributes screen of the Attribute Extraction

Wizard.

Click Alternate View to see each view. Click Copy to Clipboard to copy the data to the Clipboard. You can then paste it directly into your drawing or another application. To continue, click Next.

The Save Template screen creates and saves a template file for you. You can then use the template in the future to ensure that you extract attributes with the same settings. If you don’t want to save a template, just click Next. To save a template, click Save Template to open the Save As dialog box. Here you can specify the name and location of the template. The filename extension is .blk. Click Save. Then click Next.

Note Don’t confuse the template file used for extracting attributes with the template file (with a filename extension of .dwt) that you use as a basis for opening a drawing. Also, you can’t use ASCII template files with the Attribute Extraction Wizard, only the .blk templates that you create with the wizard.

In the Export screen, you name the file that will contain the extracted attributes. Click the Ellipsis button to specify the location and filename in a typical file dialog box.

From the File Type drop-down list, choose the type of file you want to create:

CSV (Comma Delimited) (*.csv): Lists its attribute values with a comma between each value. Most spreadsheets and databases can import this format.

Tab Delimited File (*.txt): Like a CSV file, except that there is a tab between each attribute value.

Microsoft Excel (*.xls): Creates an Excel spreadsheet.

Microsoft Access Database (*.mdb): Creates an Access database file.

To create the file, click Finish. A dialog box asks if you want to write to the file. Click Yes. The wizard closes.

Chapter 18 Working with Blocks and Attributes

527

Creating a template file the old-fashioned way

With AutoCAD’s Attribute Extraction Wizard, you don’t need to create templates “by hand.” You can still create templates on your own, but you must use the ATTEXT command to extract them. If you have AutoCAD LT, you must use this method.

Create the template file in a text editor such as Windows Notepad. The template file contains two columns. The first is the name of the attribute tag. The second is a format code that specifies whether the data is a character or number, how many spaces to allow for the data, and the decimal precision to use. The format code uses the following syntax:

TWWWPPP

where T is the data type (either N for numeral or C for character), WWW is the width including commas and decimal points, and PPP is the precision. For integers and all character data, use 000 as the precision.

For example, you would use N006002 for costs that range up to $999.99. The N means the data is numeric, 006 means that you will have up to six spaces including the decimal point, and the 002 means that you have precision of two decimal places.

In addition to information from your attributes, you can extract certain standard fields from the drawing’s database. The table that follows lists these fields and their formatting.

The block number is a number given to the blocks you select when extracting the data. The block handle is a unique alphanumeric code given to all objects in your drawing — to see a block’s handle, use the LIST command and select the block. Handles are used for referring to objects when you write AutoLISP or other programming code. The extrusion data is used for 3D drawing. See Chapter 24 for an explanation of extrusion.

Field

Format

Explanation

 

 

 

BL: LEVEL

NWWW000

Block nesting level

BL: NAME

CWWW000

Block name

BL: X

NWWWPPP

X coordinate of block insertion point

BL: Y

NWWWPPP

Y coordinate of block insertion point

BL: Z

NWWWPPP

Z coordinate of block insertion point

BL: NUMBER

NWWW000

Block counter

BL: HANDLE

CWWW000

Block handle

BL: LAYER

CWWW000

Block insertion layer name

BL: ORIENT

NWWWPPP

Block rotation angle

BL: XSCALE

NWWWPPP

X scale factor

BL: YSCALE

NWWWPPP

Y scale factor

BL: ZSCALE

NWWWPPP

Z scale factor

Continued

528 Part III Working with Data

Continued

Field

Format

Explanation

 

 

 

BL: XEXTRUDE

NWWWPPP

X component of Block’s extrusion direction

BL: YEXTRUDE

NWWWPPP

Y component of Block’s extrusion direction

BL: ZEXTRUDE

NWWWPPP

Z component of Block’s extrusion direction

 

 

 

Template files are quite finicky. Here are some of the rules:

You must include at least one attribute tag in your template.

Each row must be unique — don’t include the same attribute more than once.

You must use only spaces to line up the two columns — no tabs! (Lining up the two columns just makes it easier to read.)

End each line with a return, including the last line.

Don’t put any extra spaces after any line or any extra returns after the last return that is after the last line of text.

Each row in the template file becomes a column in the resulting output file. If you choose spacedelimited form for the output file, the columns don’t automatically have spaces between the columns, so the output files are hard to read. You can place dummy rows in the template file for the purpose of creating spaces in the resulting columns. A typical dummy row looks like this:

DUMMY1 C002000

Because each row must be unique, if you need another dummy row, call it DUMMY2. This row creates a blank column of two spaces in the output file.

The figure shows a typical template file that tracks the company division, as well as the furniture’s manufacturer, purchase date, cost, and color.

After you’re done, save the file with a filename extension of .txt. To use the file, you must use the ATTEXT command, which opens the Attribute Extraction dialog box. In this dialog box, click Template File and choose the file you created. Choose the file format you want to create and name the output file. Then click OK to extract the attributes.

Chapter 18 Working with Blocks and Attributes

529

Note

On the

CD-ROM

If you have AutoCAD LT, skip this Step-by-Step exercise and instead use the following exercise.

The drawing that you need for the following Step-by-Step exercise on extracting attribute data in AutoCAD, ab18-i.dwg, is in the Drawings folder on the CD-ROM.

STEP-BY-STEP: Extracting Attribute Data in AutoCAD

1.Open ab18-i.dwg from the CD-ROM. This is the same office building plan you used earlier in this chapter, shown in Figure 18-27.

2.Choose Tools Attribute Extraction to open the Attribute Extraction Wizard.

3.The Current Drawing option should be selected in the Drawings section of the first screen. Click Next.

4.Leave the Settings screen as is and click Next.

5.On the Use Template screen, choose No Template and click Next.

Figure 18-27: The office building plan 8 includes several blocks of armchairs with

invisible attributes.

67

5

43 2

1

6.On the Select Attributes screen, click Uncheck All on the Block list and then check Armchair. On the Attributes for Block <ARMCHAIR> list, click Uncheck All and then check the following:

X insertion point

Y insertion point

Orient

COLOR

PUR_DATE

MFR

7.Click Next.

530 Part III Working with Data

8.You should see a view that shows each attribute in its own column. If you see a list with only four columns, click Alternate View. Click Next.

9.On the Save Template screen, click Save Template. Save the file as ab18-02.blk in your AutoCAD Bible folder. Click Save. Click Next in the wizard.

10.On the Export screen, choose CSV (Comma Delimited) (*.csv) from the File Type dropdown list. (If you have Microsoft Excel or Access, you can choose the appropriate file type for one of those applications.)

11.Click the Ellipsis (...) button next to the File Name text box and navigate to your AutoCAD Bible folder. In the File Name text box, type ab18-02 and click Save.

12.Click Finish.

13.To view the output file, from the Windows task bar choose Start Run. Type Notepad and click Run. In Notepad, choose File Open and locate the ab18-02.csv file in your AutoCAD Bible folder. (Change the Files of Type drop-down list to All Files.) Click Open. It should look like Figure 18-28.

You can open this file in any spreadsheet program.

 

Figure 18-28: The output file that results from extracting the attributes in

 

the office building plan.

 

Do not save your drawing.

Tip

If you export attributes in tab delimited format, you can open the Multiline Text Editor and

 

click Import Text to import the output file into your drawing. You can also open the output

 

file, copy it to the Clipboard, and paste it into your drawing. The Import Text method enables

 

you to format the text as you would any multiline text but may take some experimenting to

 

align the columns. You cannot format the text you import using the Clipboard method, but

 

it’s nicely lined up in columns.

On the

The files that you need for the following Step-by-Step exercise on extracting attribute data in

CD-ROM

AutoCAD LT, ab18-i.dwg and ab18-i.txt, are in the Drawings folder on the CD-ROM.

STEP-BY-STEP: Extracting Attribute Data in AutoCAD LT

1.Open ab18-i.dwg from the CD-ROM. This is the same office building plan you used earlier in this chapter, shown in Figure 18-27.

2.Type attext to open the Attribute Extraction dialog box.