Use Access database to implement AutoCAD system electrical components management Source: Power World
Li Tianke, Li Tianke, 105 Mailbox Technology, Nanjing, Li Tianke Summary: Introduced in the AutoCAD 2002 environment, using VBA development applications, in the AutoCAD electrical schematic, automatically extract the properties of the electrical component tile, generate an Access database, formation The method of electrical component chart, it can greatly improve the management of electrical components. Keywords: Block Access Block AutoCAD database attributes VBA Abstract: A method using the VBA to develop the application procedure under the AutoCAD environment, automatically collect the attribute of the electricity pieces block, form the list, build the Access Database, is Introducted. Keywords: Database AutoCAD BLOCK Access Attribute VBA [Map Category] TP274 [Documentation ID] B Article No. 1606-5123 (2003) -01-0048-04 1 Overview In recent years, AutoCAD It has been widely used in electrical design, while designers have facilitated AutoCAD, often encountering how to quickly and accurately statistize electrical components in a large number of drawings, especially a complex electrical system containing a large number of electrical components. When the electrical schematic design is completed, print each page drawing, relying on the electrical components of the artificial statistics to fill in the database, the workload is large and easy to make mistakes, and the device is installed, discovers missing or multi-electrical components. It is unnecessary losses to enterprises, and designers are distressed. If you can automatically manage the electrical components with a database, it is undoubtedly very beneficial to the management of electrical components. The method described in this article is to establish a tile for each electrical component. When the electrical system schematic is drawn, the electrical components are inserted in the way, and then use the VBA development application to access the electrical system schematic, automatically extract the electrical components. The properties information of the tile can generate the Access database. The Access database is because AutoCAD is best compatible with it, and designers are familiar with the Access database, thereby avoiding human error and improving efficiency. 2 Design and Production Electrical Components Access Database For management, it is necessary to design the electrical component database structure according to the information of the required statistics, and the performance and specifications of the electrical components that our company often use are shown in Table 1, from 4 Field consists. Table 1 Electrical Components Database Structure Field Name Code Name Model Manufacturer Field Type Text Text Text 3 Establishment Electrical Components Table Library To achieve automatic generation of electrical components database, first establish a piece of property with attributes for each electrical component, thus Form an electrical component diagram library. The specific steps of establishing the electrical component diagram library are as follows: (1) Draw the national standard graphics of each electrical component first, Figure 1 is a proximity switch pattern. (2) Use the ATTDEF command to define each electrical component properties, as shown in Figure 2, the proximity switch name property, other attributes (model, manufacturers) are defined as the same method as in Figure 2, pay attention to the definition approaching the switching agent attribute because Each electrical component code attribute is unique, so when inserting the tile, you should enter the correct code attribute according to the "Please enter the code" prompt, and the data structure corresponding to the attribute structure is shown in Table 2.
Table 2 Data Structure Tag (T) prompt (P) value (L) code of the electrical component attribute structure, please enter the code name proximity switch model BIL-Q06-AN6X2 manufacturer TURCK Company (3) Define each electrical component with the Block directive The tile, the tile includes the graphics drawn by step (1), the graphical properties structure drawn step (2), the proximity switch tile is shown in Figure 3. (4) When you edit the electrical component tile properties, first use the evode instruction, blow the tile, and use the DDEDIT command to modify the corresponding attribute, repeat the above step (3) to complete the task of editing the tile. Similarly, all other electrical component tiles such as buttons, stop buttons, stroke switches, etc. are established according to the above steps (1) to (3), and the electrical component library is formed. 4 Write VBA applications Util VBA visual programming technology, conveniently establish an electrical component Access database. The idea of building a database is: first establish a new database, in the electrical system schematic, automatically look up attribute information of the electrical component tile, write the properties of each electrical component as a record database. In the AutoCAD 2002 environment, allow VBA developers to connect to databases (such as Visual Fox, Access, SQL, etc.) via ODBC objects, this article connects the Access table, constructs the Access type database, so that the database is convenient, it is also further developed and managed the database. Create favorable conditions.
Sub list () Dim work As Workspace Dim new As Database Dim elem As Object Dim rs As Recordset Dim RowNum As Integer Set work = DBEngine.Workspaces (0) Dim dbs As Database Dim tdfNew As TableDef Dim tdf As TableDef Dim dbsname As String Dim array1 As Variant Dim array2 As Variant 'declare the required variables and type dbsname = "D: / materials table .mdb"' where a written statement Access database file On Error Resume Next Set dbs = work.CreateDatabase (dbsname, _ dbLangGeneral IF Err THEN KILL (DBSNAME) 'Discovering the Access Database file to be written to delete the set dbs = work.createdatabase (dbsname, _ dblangGGneral) end if set tdfnew = dbs.createtablededef ("Electrical _ material chart ") 'Establish a table ROWNUM = 0 DIM header as boolean header = false for easy elem in thisdrawing.modelspace' in CAD model space, look for all graphics object with elem if strcomp (.entityName, _" 'array1 set point attribute of a graphic object' AcDbBlockReference ", 1) = 0 Then If .HasAttributes Then array1 = .GetAttributes array2 = .GetConstantAttributes fixing property For array2 set point of the graphic object Count = LBound (array2) to _ UBound (array2) If Header = false theen if strcomp (count (count) .entityname, _ "acdbat Tributedefinition ", 1) = 0 THEN TDFNEW._ CREATEFIELD (array2 (count) .tagstring, dbtext) end if 'reads out the attribute value read, the title of the Access database table end if Next Count for count = lbound (array1) To _ UBound (array1) If Header = False Then If StrComp (array1 (Count) .EntityName, _ "AcDbAttribute", 1) = 0 Then tdfNew.Fields.Append tdfNew. _ CreateField (array1 (Count) .TagString , DBText) end if End if Next = false then dbs.tabledefs.append TDFNEW SET RS = dbs.openRecordset ("Electrical Materials_Lumming Table", Dbopentable) 'Open Record End if Rownum = ROWNUM 1 RS.AddNew 'Add a new record for count = lbound (array2) _ to ubound (array2) rs (count) .value =