Connect Databases to AutoCAD with dbconnect Nate Bartley Test Development Engineer autodesk, inc. GD22-4 1
2 Agenda Introduction Overview of dbconnect Configure a data source Connect database to AutoCAD drawing Create a link template Create links between drawing objects and rows in the database Create labels in drawing Queries Link Select Share link and label templates and queries with others Overview AutoCAD database connectivity feature dbconnect Little to no database knowledge required Intelligent objects Access a database from within AutoCAD without having database software Only available if Database feature of AutoCAD is installed (part of typical installation). Not covering the creation of databases or database design
3 Overview 5 main features of external database access Linking of AutoCAD objects to external data View data in external database Edit data in external database Display external database data in drawing Creating queries Terms Environment = file cabinet Catalog = drawers Schema = folders Table = paper Records = Rows Fields = Columns Cells = Individual fields Data Source = individual table or a collection of tables
4 dbconnect Database feature of AutoCAD Drawing node Data Source node Associate links Associate labels Associate queries All from within AutoCAD Data View Displays records from a database table within an AutoCAD session
5 Demo First Look at Data View window Grid, Column, Record header Actions Resize, Move, Hide, Freeze Columns Sort records Ascending (low to high) Descending (high to low) Align text Format text Configuring a data source Microsoft ODBC (Open Database Connectivity) OLE DB Format independent Points to collection of data and provides information about the drivers necessary to access the data Varies depending on the database Server-based File-based
6 Supported databases Microsoft Access dbase Microsoft Excel Oracle Paradox Microsoft Visual FoxPro SQL Server See acad_dpg.chm for configuring specific databases for use with AutoCAD Demo - Configuring Data source
7 Connecting database to AutoCAD drawing Data View window View database View objects View records AutoView Edit database In place Change notification Commit/Restore Connects to parent database Demo more Data View window View table Edit table Notes: Be sure to turn AutoView off when performing other tasks other then viewing. Customize how AutoCAD displays linked rows and how AutoCAD pans (AutoPan) and zooms (AutoZoom). Changes have to be committed to the database. AutoCAD automatically commits change if AutoCAD closed
8 Creating a link template 2 main purposes Identifies which fields are associated with link between the data and drawing object Identifies the database being used Rules Associates an object or objects with a row in database Provide a field that does not contain duplicate data Uses first row found first Can open data directly from Link template Multiple link templates to associate data from more than one database to a single object Only change key fields of link templates that do not have any links defined in associated drawing. Implies links must first be deleted Demo - Creating a Link Template Steps for creating link template 1. dbconnect > Template > New Link Template 2. AutoCAD opens the Select Data Object dialog if a data table is not already open 3. New Link Template dialog Provide a name Start with an existing template (optional) 4. Link Template dialog check Key field Link Template is created
9 Linking drawing objects to rows in the database Link drawing object to many records in a database Link one database record to many drawing objects Cannot link to nongraphical objects AutoCAD provides a message on command about the success or failure of providing link Links follow the object when edited Demo Linking objects and rows Steps for creating links 1. Open Data View window 2. Select one or more records 3. Choose Data View > Link and Label Settings > Create Links 4. Choose Data View > Link 5. Select drawing objects to link AutoCAD returns results
10 Editing Links Link Manager Enables you to edit key values for linked objects Demo Link Manager Steps for using link manager 1. Choose dbconnect > Links > Link Manager 2. Select a drawing object 3. In Link Manager, choose the Link Template 4. In the Value column, type a new value 5. OK to close. AutoCAD updates the link.
11 Exporting Links Exports a list of links Exports handle of the associated links objects Exports results in the same format as the database or in spaceor comma-delimited formats A handle is a unique name that AutoCAD gives to each object in the drawing. Recommend synchronizing links in drawing periodically Updates or deletes broken links Demo Exporting link information Steps for using link manager 1. Choose dbconnect > Links > Export Links 2. Choose objects whose links are to be exported 3. Select the fields to included in the Include Fields section 4. Navigate to the location to save 5. Choose Save-as file type 6. Enter filename 7. Save AutoCAD creates the file
12 Creating labels in drawing Label is multiline text (Mtext) Choose which fields are to be displayed Two types of labels Attached labels attached to objects and displays a leader pointing to object Freestanding labels independent of any object Both are pointers to external database table Must first create a Label Template Creating labels in drawing Label is multiline text (Mtext) Choose which fields are to be displayed Two types of labels Attached labels attached to objects and displays a leader pointing to object Freestanding labels independent of any object Must first create a Label Template
13 Creating Label Template Label Template specifies Which fields to include in label Text formatting Label offsets (Attached labels only) Demo Creating a Label Template Steps for creating label template 1. Choose dbconnect > Template > New Label Template 2. Choose a link template to use with the label template in Select a Database Object dialog 3. New Label Template dialog Provide template name Start with existing template (optional) 4. AutoCAD opens the Label Template editor with Label Fields tab displayed. Add fields. 5. Format label text and configure offsets as needed.
14 Demo Creating Labels Must have a table open with a link and label templates defined Steps for attached labels Select record in Data View window Choose Data View > Link and Label Settings > Create Attached Labels (for freestanding labels choose Create Freestanding Labels) Choose Data View > Link Select drawing objects AutoCAD automatically places label. More than one object can be done at a time. Using Queries Query editor to define queries such as: View a specified subset of the data View a subset that falls within a specified range of values Access all the tables in one data source with a series of SQL commands Link Select dialog creates a selection set of objects by combining selected objects with SQL queries
15 Queries Four types of queries Quick Query Range Query Query Builder SQL Query (SQL 92 standard) Queries are case sensitive Each tab in the Query Editor builds on the previous tab Query Operators Equal (=) Not Equal (<>) Greater than (>) Less than (<) Greater than or equal (>=) Less than or equal (<=) Like (%) In Is null Is not null
16 Demo - Queries Four types of queries Quick Query Range Query Query Builder SQL Query (SQL 92 standard) Link Select Enables selection sets to be created by the Query Editor or by selecting objects, or a combination of both methods As you work, the status area at the bottom of dialog displays results. Results are displayed in terms of the number of linked objects and the number of records that meet specification
17 Demo - Link Select Steps for using link select 1. Choose dbconnect > Links > Link Select 2. Link Select dialog Choose either Use Query or Select In Drawing Use Query uses the Query Editor Select In Drawing prompts for object selection 3. Execute to add query or selection to the Link Select operation 4. Create a second selection set 5. Choose logical operator from Do drop-down list 6. Create additional selection sets as needed 7. Finish to complete process Sharing link and label templates and queries Link templates, label templates, and queries are stored under the Drawing node in dbconnect. Queries and can be exported and imported. Queries are stored in the location specified Tools > Options > Files tab > Data Sources Location
18 How to configure data source How to view and edit databases through Data View window How to connect database table with a drawing How to create a link template How to create links between drawing objects and database rows How to create labels containing information from database How to define and execute queries Thank You