1. Trang chủ
  2. » Công Nghệ Thông Tin

autocad 2007 and autocad lt 2007 bible - phần 6 pot

130 416 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 130
Dung lượng 2,06 MB

Nội dung

608 Part III ✦ Working with Data DesignCenter As explained in earlier chapters, you can use the DesignCenter to move named objects, including xrefs, from one drawing to another. (I cover the DesignCenter in detail in Chapter 26.) To insert an xref from another drawing, press Ctrl+2. Navigate to the drawing and double- click it to open the list of named objects. Double-click Xrefs to see a list of xrefs in the right pane, as shown in Figure 19-14. Figure 19-14: You can use the DesignCenter to insert xrefs into your drawing. Double-click the xref that you want to insert. The External Reference dialog box opens (refer to Figure 19-1) so that you can insert the xref. The xref log file If you set the XREFCTL system variable to 1 (by default, it’s set to 0), a copy of all xref activity for your current drawing is saved in an ASCII text file. You can read the log to troubleshoot problems that may occur. Figure 19-15 shows part of an xref log file. The log file goes in the same folder as your drawing and uses your drawing name with the .xlg filename extension. This file can become long. Therefore, once in a while, you should delete all or part of the file. The Reference Manager is a stand-alone program that manages xrefs, images, fonts, and plot configurations, which are all outside files that are referenced in your drawing. See Chapter 26 for full coverage of the Reference Manager. The drawing used in the following exercise on managing xrefs, ab19-05.dwg, is in the Results folder on the CD-ROM. On the CD-ROM Cross- Reference 27_788864 ch19.qxp 5/22/06 7:40 PM Page 608 609 Chapter 19 ✦ Referencing Other Drawings Figure 19-15: An xref log file. STEPS: Managing Xrefs 1. Use ab19-05.dwg from your AutoCAD Bible folder if you did the previous exercise. Otherwise, open it from the Results folder of the CD-ROM. 2. Save it as ab19-06.dwg in your AutoCAD Bible folder. 3. Do one of the following: • If you have AutoCAD: Choose Modify ➪ Clip ➪ Xref. At the Select objects: prompt, pick the xref anywhere. Press Enter. At the Enter clipping option [ON/OFF/ Clipdepth/Delete/generate Polyline/New boundary] <New>: prompt, right-click and choose Delete to delete the clip and restore the entire view of both xrefs. • If you have AutoCAD LT: If you did the previous exercise and opened ab19-05 .dwg from your AutoCAD Bible folder, skip this step. If you opened ab19-05.dwg from the CD-ROM, you have opened an AutoCAD drawing with a clipped xref. Because AutoCAD LT doesn’t support clipping, you need to reattach the xref. Copy ab19-b.dwg from the \Drawings folder and ab19-01.dwg from the \Results folder (both on the CD-ROM) to your AutoCAD Bible folder. Choose Insert ➪ External References. Choose ab19-01 and click Detach. Click Attach. Select ab19-01.dwg from your AutoCAD Bible folder and click Open. In the External Reference dialog box, uncheck the Insertion Point, Scale, and Rotation Specify On-screen check boxes (if checked) and click OK to attach the xref. 27_788864 ch19.qxp 5/22/06 7:40 PM Page 609 610 Part III ✦ Working with Data 4. Choose Insert ➪ External References. Click the Tree View button. Right-click ab19-b, the nested xref, and choose Unload. 5. Right-click ab19-b again. Choose Reload to reload the xref. 6. This time right-click ab19-01. Choose Bind. In the Bind Xrefs dialog box, choose Insert and click OK. This action inserts both xrefs ( ab19-01 and ab19-b) as blocks. (Click the Layer Control drop-down list to see that there are no xref-type layer names.) 7. Save your drawing. Summary In this chapter, I covered the techniques that you need to know to work with xrefs. You read about: ✦ Attaching and overlaying xrefs ✦ Opening an xref in its own window ✦ Editing xrefs and blocks from within the drawing in which they appear ✦ Clipping xrefs so that only the portion you need to see is displayed ✦ Setting spatial and layer indexes to speed up the display of large xrefs ✦ Deleting, unloading, and reloading xrefs ✦ Binding an xref to make it part of your drawing In the next chapter, I cover database connectivity, which enables you to access outside databases. ✦✦✦ 27_788864 ch19.qxp 5/22/06 7:40 PM Page 610 20 20 CHAPTER Working with External Databases T he AutoCAD database connectivity feature enables you to com- municate with an external database from within AutoCAD. AutoCAD LT does not include the database connectivity feature. This entire chapter applies to AutoCAD only. Database connectivity is a powerful way to link drawing objects with data and is more flexible than using block attributes. With database connectivity, you can link data in an external database to any object in a drawing. In this chapter, I show you that database connectivity does not have to be as difficult as it often sounds. Many AutoCAD users maintain databases separately from their draw- ings. Now you can work directly with your data by linking the rows of the database tables to objects in your drawings. The drawing objects thus become intelligent and carry these links with them in the drawing. You can also change data, such as a price or a part number, from within AutoCAD and have that change automatically applied and available in all drawing objects that are linked to that database item. Finally, you can create labels in your drawing, based on the data in the database. Understanding External Database Access Many organizations maintain extensive databases of objects that are in your AutoCAD drawings. Manufacturers maintain databases of parts, offices maintain databases of furniture, and so on. You need to keep your drawings and the databases synchronized so that the information in the databases and in the drawings is always accurate and up to date. The linking of databases and AutoCAD drawings is referred to as external database access. External database access enables you to: ✦ Create links between AutoCAD drawing objects and the external data ✦ View data in external databases ✦ Edit data in external databases ✦ Display external database data in your drawing ✦✦✦✦ In This Chapter Understanding database connectivity Preparing for database connectivity Connecting to a database Linking data to drawing objects Creating labels Querying the database Working with query files ✦✦✦✦ 28_788864 ch20.qxp 5/22/06 7:32 PM Page 611 612 Part III ✦ Working with Data The database connectivity feature works with the following databases: ✦ Microsoft Access ✦ dBASE ✦ Microsoft Excel ✦ Oracle ✦ Paradox ✦ Microsoft Visual FoxPro ✦ SQL Server After you configure a database, as explained later in this chapter, you can access the data in the database even if you don’t have the database program that created the data. A database is a set of related information, usually maintained by a database management sys- tem (DBMS) — an application that manages databases. A database is stored in the form of a table that contains rows and columns. A row, also called a record, contains one element of data, such as the information for one desk. A column, also called a field, contains the attributes of the data, such as the price. Table 20-1 shows the first three rows of the database used as an example in this chapter. Table 20-1: A Simple Database Table Part Number Description Dwg Size Made/Purchased Units 8665-023-012 Welding Wire —0.030 StainlessB B P FT 8665-023-013 Weld Rod—0.045 Dia Stainless Steel B P FT 8665-023-014 Welding—Rod 0.045 Dia S.S. B P FT A relational database is a type of database that contains a collection of tables. Each table rep- resents a set of data for a defined use. Structured Query Language (SQL — pronounced sequel or S-Q-L) was created to provide users with a database language that would be applicable across multiple platforms and database- management programs. Some database systems use environments, catalogs, schemas, and tables to create a hierarchy of database objects. A database object is simply the term used to specify any of the following SQL2 objects: environment, catalog, schema, or table. ✦ The environment is the entire database system — the DBMS, the databases it can access, the users, and the programs that can access those databases. ✦ A catalog is a collection of schemas and has the same name as the folder where the database is located. ✦ A schema is a set of tables and other database components. It has the same name as the catalog subfolder where the database tables reside. 28_788864 ch20.qxp 5/22/06 7:32 PM Page 612 613 Chapter 20 ✦ Working with External Databases You don’t need to work with these concepts if your database system does not require or specify it. AutoCAD can connect to an individual table or to a collection of tables stored in an environment, catalog, or schema. Preparing for Database Connectivity Database connectivity involves several components that you need to prepare in advance. When they are in place, the connection should go smoothly. In this section, I explain the nec- essary preparation steps. The basic steps for starting to work with database connectivity are as follows: 1. Make sure that you have the ODBC Data Source program from Microsoft. 2. Arrange your database tables into catalogs (folders) and schemas (subfolders) appro- priate for your application, if necessary. 3. Configure the appropriate database driver using Microsoft’s ODBC (Open Database Connectivity) or OLE DB programs. 4. Configure your data source from within AutoCAD. 5. Start the dbCONNECT command. 6. Establish a user access name and password, if required by the database system. 7. Connect to your data source. 8. Open the Data View window containing your data table. 9. Edit the data, if desired. 10. Link database rows to objects in your drawing. 11. Create labels based on the data in your drawing, if desired. Organizing the database structure To connect to a database, you need to know the type of database-management system that created the database and the structure of the database itself, along with the folders that con- tain that structure. In the following exercise, you create a simple structure for a Microsoft Access database table. In this chapter, you cannot do the later exercises without doing the earlier ones. The later exercises depend on the setup and configuration that you create in the earlier exercises. The file used in the following exercise on creating the structure for the database, ab20-prt .mdb, is in the Drawings folder on the CD-ROM. On the CD-ROM Note 28_788864 ch20.qxp 5/22/06 7:32 PM Page 613 614 Part III ✦ Working with Data STEPS: Creating the Structure for the Database 1. Right-click Start on the task bar. Choose Explore to open Windows Explorer. 2. If your AutoCAD Bible folder is not displayed in the Folders window, click the plus sign (+) next to the drive containing the AutoCAD Bible folder. 3. Click the AutoCAD Bible folder and choose File ➪ New➪ Folder from the Explorer menu. A new folder appears in the right window, called New Folder. Type Databases ↵ to rename the folder. 4. If necessary, in the Folders window, click the plus sign to open the AutoCAD Bible folder. You should see the new Databases folder. (If not, press F5 to refresh the Explorer view.) 5. From the CD-ROM, copy ab20-prt.mdb to the Databases folder that you just created. (Be sure to choose the ab20-prt.mdb file, not the ab20-prt.xls file.) The .mdb file is a database of parts. Figure 20-1 shows this database. 6. Because this file is coming from a CD-ROM, you may need to change its read-only prop- erty. Still in Explorer, right-click ab20-prt.mdb and choose Properties from the menu. Uncheck Read-Only and click OK. 7. Click the Close button of Explorer to close it. Figure 20-1: The Microsoft Access database. Thanks to Gary Morris of the Dexter Company, Fairfield, Iowa, for this database. Configuring a data source To start working with external databases, you must tell AutoCAD how to communicate with your database, called a data source. AutoCAD uses ODBC and OLE DB for this communication. AutoCAD provides a sample Microsoft Access file, called db_samples.mdb in AutoCAD’s Sample folder, that you can work with to get started. 28_788864 ch20.qxp 5/22/06 7:32 PM Page 614 615 Chapter 20 ✦ Working with External Databases First, you must install and configure the ODBC Data Source Administrator. To check if the ODBC Data Source Administrator is installed on your computer, open the Control Panel by choosing Start ➪ Settings ➪ Control Panel (or as required by your operating system), and look for one of the following items: ✦ ODBC Data Sources (32-bit) or Data Sources (ODBC) ✦ Administrative Tools➪ Data Sources (ODBC) To check if you have the required drivers installed, double-click the ODBC item. In the ODBC Data Source Administrator dialog box, you’ll see a list of database application drivers. Check to see that your database application is listed. A database driver contains information about how to connect to your database. In most cases, your operating system will include the ODBC Administrator. If you don’t have the ODBC 32-bit Administrator, you need to install the Microsoft ODBC Driver Pack. The ODBC Driver Pack 3.0 (or later) is free from the Microsoft Web site at http://msdn.microsoft.com/data/mdac/downloads/default.aspx. The MDAC (Microsoft Data Access Components) 2.8 download should provide you with everything you need. The instructions to set up the database vary according to the drivers that you use. The AutoCAD online help contains help on all supported databases. Look in Help ➪ Help and click the Contents tab. Double-click Driver and Peripheral Guide and then Configure External Databases. Click the Procedures tab and choose the link for your database. To set up your database using ODBC, follow these steps: 1. From the Windows task bar, choose Start➪ Settings ➪ Control Panel (or Start ➪ Control Panel). 2. Double-click the Administrative Tools icon, then double-click the Data Sources (ODBC) item. Windows opens the ODBC Data Source Administrator dialog box, shown in Figure 20-2. 3. Click the User DSN tab if it isn’t already displayed. Choose Add. 4. In the Create New Data Source dialog box, choose the driver appropriate for your database and click Finish. Figure 20-2: Use the ODBC Data Source Administrator dialog box, accessed from the Windows Control Panel, to choose a database driver to connect to your database. 28_788864 ch20.qxp 5/22/06 7:32 PM Page 615 616 Part III ✦ Working with Data 5. In the ODBC Setup dialog box, which is now titled with the name of the driver that you chose (for example, ODBC Microsoft Access Setup), type a name for your data source in the Data Source Name text box. You can also add a description. In general, this name refers to your database program, not the individual database file. 6. Click Select and navigate to the folder containing your database. Choose the database file and click OK. 7. Click OK again in the Setup dialog box. 8. In the ODBC Administrator dialog box, your data source is listed with its appropriate driver. Click OK. Close the Administrative Tools window and the Control Panel. You’re now ready to configure your database from within AutoCAD. Follow these steps: 1. Choose Tools➪ Palettes➪ dbConnect to open the dbConnect Manager palette and dis- play the dbConnect menu. 2. From the menu, choose dbConnect➪ Data Sources➪Configure. (The dbConnect menu appears when you start dbConnect.) In the Configure a Data Source dialog box, type a name representing your database file. Click OK. 3. On the Provider tab of the Data Link Properties dialog box, choose Microsoft OLE DB Provider for ODBC drivers. Click Next. 4. From the drop-down list on the Connection tab, choose the name of the data source that you used in the ODBC Setup dialog box, as shown in Figure 20-3. Figure 20-3: Use the Data Link Properties dialog box to configure your data source within AutoCAD. 28_788864 ch20.qxp 5/22/06 7:32 PM Page 616 617 Chapter 20 ✦ Working with External Databases 5. For server-based databases, enter the user name and password. 6. Click Test Connection. You should see a message saying Test Connection Succeeded. (If not, check your settings as well as the spelling and case of the name of the data source.) Click OK. 7. Click OK in the Data Link Properties dialog box. You’re now ready to establish a connection between a database and an AutoCAD drawing. The drawing used in the following exercise on configuring a Microsoft Access database, ab20-a.dwg, is in the Drawings folder on the CD-ROM. This exercise requires that you have completed the steps in the previous exercises. STEPS: Configuring a Microsoft Access Database 1. From the task bar, choose Start➪ Settings➪ Control Panel (or Start ➪ Control Panel). Double-click the Administrative Tools icon, then double-click the Data Sources (ODBC) icon. (Your item may have a slightly different name.) 2. On the User DSN tab of the ODBC Data Source Administrator dialog box, choose Add. 3. In the Create New Data Source dialog box, choose Microsoft Access Driver. Choose Finish. 4. In the Data Source Name text box of the ODBC Microsoft Access Setup dialog box, type ab20-Access. 5. Click Select and navigate to your AutoCAD Bible\Databases folder (which you created in the previous exercise). Choose ab20-prt.mdb and click OK. 6. Click OK twice more to exit the ODBC Data Source Administrator. 7. Close the Administrative Tools and Control Panel windows. 8. Open AutoCAD. Open ab20-a.dwg from the CD-ROM. Save it as ab20-01.dwg in your AutoCAD Bible folder. 9. Choose Tools➪ Palettes➪ dbConnect to open the dbConnect Manager palette and dis- play the dbConnect menu. From the menu, choose dbConnect➪ Data Sources➪ Configure. In the Configure a Data Source dialog box, type ab20-prt. Click OK. 10. On the Provider tab of the Data Link Properties dialog box (which opens automati- cally), choose Microsoft OLE DB Provider for ODBC Drivers. Click Next. 11. From the upper drop-down list, choose ab20-Access. 12. Click Test Connection. You see a message saying Test Connection Succeeded. Click OK. 13. Click OK in the Data Link Properties dialog box. 14. Keep ab20-01.dwg open for the next exercise. On the CD-ROM 28_788864 ch20.qxp 5/22/06 7:32 PM Page 617 [...]... UNITS column and shrink the Data View window to fit Your Data View table should look like Figure 2 0-9 Figure 2 0-9 : The Data View table after some formatting 62 3 28_788 864 ch20.qxp 62 4 5/22/ 06 7:32 PM Page 62 4 Part III ✦ Working with Data 5 Right-click the PART_NO column’s header and choose Align ➪ Right to right-align the first column 6 To practice moving around the table, click the right-most arrow... data table, AutoCAD opens the Select Data Object dialog box Choose a table and click Continue 62 5 28_788 864 ch20.qxp 62 6 5/22/ 06 7:32 PM Page 62 6 Part III ✦ Working with Data 3 In the New Link Template Name text box of the New Link Template dialog box, shown in Figure 2 0-1 0, type a name for the link template AutoCAD assigns an automatic name using the name of the data source and Link1, Link2, and so on... PART_NO field Figure 2 0-1 6: Use the Label Template dialog box to format and define label templates Note If you add text before or after the field, don’t forget to add a space between the text and the field so that the result is Part No: 900 3-2 4 2-0 01 rather than Part No:900 3-2 4 2-0 01, for example 6 Click the Label Offset tab, shown in Figure 2 0-1 7 This tab defines the placement of the label and the leader that... column and choose Freeze To return the column to its original location, right-click and choose Unfreeze All ✦ Align text: You can align text in a column or columns By default, columns use the Standard alignment, which right-aligns numbers and left-aligns everything else Select a column or columns by clicking the column header(s), right-click any column header, and choose Align Then choose Standard,... dialog box, type ab Excel as the Data Source Name (If you want, type a description.) 6 Click Select Workbook Use the dialog box to choose the AutoCAD Bible\ databases\ab20-prt.xls worksheet Click OK three times and close the Control Panel 7 Open AutoCAD Open ab20-a.dwg from the CD-ROM Save it as ab2 0-0 1.dwg in your AutoCAD Bible folder Choose Tools ➪ dbConnect 8 Choose dbConnect ➪ Data Sources ➪ Configure... 28_788 864 ch20.qxp 5/22/ 06 7:32 PM Page 63 5 Chapter 20 ✦ Working with External Databases 4 At the Specify point for label: prompt, pick a point in your drawing AutoCAD places the freestanding label and displays this message on the command line: 1 Record(s) linked with 1 Label(s) When you create a freestanding label, the row and the label are linked If you select a row linked to a freestanding label and. .. object In the Start drop-down list, choose a justification This defines where on the object AutoCAD places the tip of the leader Figure 2 0-1 7: The Label Offset tab of the Label Template dialog box 63 3 28_788 864 ch20.qxp 63 4 5/22/ 06 7:32 PM Page 63 4 Part III ✦ Working with Data 7 In the Leader Offset text boxes, type an X and Y offset (in units) This offset represents the X and Y distances between the... choose PART_NO in the Then By drop-down list, which should also be sorted in ascending order Click OK AutoCAD sorts the data by description, and then by part number 8 Say that you want to find part number 900 3-2 4 2-0 01 Right-click the top cell in the PART_NO column Choose Find In the Find dialog box, type 900 3-2 4 2-0 01 and choose Down in the Direction section Click Find Next AutoCAD highlights the cell containing... gather more information about the elements in the drawing and database files SQL is the language used by almost all database-management systems for refining the information that you get from a database AutoCAD uses the Query Editor to enable you to design queries For example, you can do the following: 63 5 28_788 864 ch20.qxp 63 6 5/22/ 06 7:32 PM Page 63 6 Part III ✦ Working with Data ✦ Query the contents of... insert the And operator Clicking again changes the operator to Or 5 Move to the second line and create the next row of criteria Continue until you’ve specified all of the criteria that you want 63 9 28_788 864 ch20.qxp 64 0 5/22/ 06 7:32 PM Page 64 0 Part III ✦ Working with Data 6 Add parenthetical grouping Click to the left of the Field column of a row to insert a left parenthesis and between the Value and Logical . xrefs, ab1 9-0 5.dwg, is in the Results folder on the CD-ROM. On the CD-ROM Cross- Reference 27_788 864 ch19.qxp 5/22/ 06 7:40 PM Page 60 8 60 9 Chapter 19 ✦ Referencing Other Drawings Figure 1 9-1 5: An. AutoCAD Bible databasesab20-prt.xls worksheet. Click OK three times and close the Control Panel. 7. Open AutoCAD. Open ab20-a.dwg from the CD-ROM. Save it as ab2 0-0 1.dwg in your AutoCAD Bible. xref. Copy ab19-b.dwg from the Drawings folder and ab1 9-0 1.dwg from the Results folder (both on the CD-ROM) to your AutoCAD Bible folder. Choose Insert ➪ External References. Choose ab1 9-0 1 and click

Ngày đăng: 08/08/2014, 23:20

TỪ KHÓA LIÊN QUAN