1 第 1 部 controlling autocad lt on access vba

41
1 第1部 Controlling AutoCAD LT on Access VBA Map Management Chapter 1 Land deals ・ Link figure information of AutoCAD LT and Access data base using public land survey map. Chapter 2 Real estate information ・ ・ Link figure information of AutoCAD LT and Access database to the latest map information on website. Facility Management Chapter 3 Changing object manes of Facility appliances ・ ・ Figure information of AutoCAD LT and Access database are revised simul taneously. Chapter 4 Maintenance of facility appliances e.g.: Auto display the names, number and price of the facility appliances which need to be placed after 2 years. Database management Chapter 5 Parts management Ⅰ ・ ・ Revising parts of AutoCAD LT drawing on Ac cess. Chapter 6 Parts management Ⅱ ・ ・ Auto inventory components of the drawing by a single click. frm_Main.bmp

Upload: dangnguyet

Post on 10-Feb-2017

237 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 1 第 1 部 Controlling AutoCAD LT on Access VBA

1

第 1部 Controlling AutoCAD LT on Access VBA

● Map Management

Chapter 1 Land deals ・ ・ ・ Link figure information of AutoCAD LT and Access data

base using public land survey map.

 

  Chapter 2 Real estate information ・ ・ ・ Link figure information of AutoCAD LT and

Access database to the latest map information

on website.

● Facility Management

Chapter 3 Changing object manes of Facility appliances ・ ・ ・ Figure information of

AutoCAD LT and Access

database are revised simul

taneously.

Chapter 4 Maintenance of facility appliances e.g.: Auto display the names, number and

price of the facility appliances which

need to be placed after 2 years.

● Database management

Chapter 5 Parts management Ⅰ ・ ・ ・ Revising parts of AutoCAD LT drawing on Ac

cess.

Chapter 6 Parts management Ⅱ ・ ・ ・ Auto inventory components of the drawing by a

single click.

frm_Main.bmp

Page 2: 1 第 1 部 Controlling AutoCAD LT on Access VBA

32

1. Narrow your search on an Access table (e.g. a closed deal /forest)

2.The land number which corresponds to your search on AutoCAD LT map will turn into a

different color.

3.Sekect the land number on AutoCAD LT map to display the details of the record on

Access.

1.Narrow your search on Access table.(e.g. places within 10 min of a station.)

2.The land number which corresponds to your search on AutoCAD LT map turns into

different color.

3.Select the land number on AutoCAD LT map to display the details of the record on

Access.

map1-02.bmp

map1-01-2.bmp

map2-01.bmp

map1-01-5.bmp

map2-02.bmp

map2-01-5.bmp

Map Management Ⅰ (Land deals) Map Management Ⅱ (real estate in formation)

Page 3: 1 第 1 部 Controlling AutoCAD LT on Access VBA

54

1.Select components on Auto CAD LT drawing to redefine the object data.

2.Redefined object data on Auto CAD LT drawing is exported to Access table.

3.Redefinition of object data on Access is exported to AutoCAD LT in the same

manner.

3.Redefined of object data on Access is exported to Auto CAD LT in the same manner.

1.Facility appliances (lights)are placed on Auto CAD LT drawing.

2.Search for appliances needed to be replaced in 3 years on Access database.

3.The corresponding lights turn from black to yellow and blink on Auto CAD LT drawing..

Fa1-02.bmp

F a1-02-1. F a1-02-2.

F a1-02-3.

Fa2-02.bmp

F a2-03-1.

Fa2-04.bmp

Facility management・・・Rearranging facility appli-

ances

management ・ ・ ・ maintenance of facility appliances Facility

Page 4: 1 第 1 部 Controlling AutoCAD LT on Access VBA

76

1.Comporents are placed on Auto CAD LT drawing.

2.Select other components from Access database.

3.The new components are placed on Auto CAD LT drawing.

Dat1-03.bmp

Dat1-03-3.bmp

Dat1-03-4.bmp

Dat2-04.bmp

Dat2-05.bmp

Dat2-05-1.bmp

1.Components are placed on Auto CAD LT drawing.

2.Names and numbers of parts are on Access database table.

Database management ・ ・ ・ parts management Ⅰ Database management ・ ・ ・ parts management Ⅱ

3.When the record of the parts is modified on Auto CAD LT drawing, Access database is au-

tomatically revised with the new data.

Page 5: 1 第 1 部 Controlling AutoCAD LT on Access VBA

98

Chaptr1 Map management (Land deals)

Aim ・ ・ ・ Link Auto CAD LT drawing in formation to Access database.

Select a record of a drawing locaed in Access database on Auto

CAD LT

and details of that drawing are also displayed on Access detail

from window.

Sample fine:

 ・Folder name:    c:\LT2MDB\Map1

 ・Auto CAD LT file: Map1.dwg

 ・Access 2000 file: Map1.mdb

・Text file:       Map1.txt Map1_temp.txt

Tip

① Access program: select "Land Deals" from the main from.

or: choose c:\LT2MDB. MDB and select F-Map, then open the file.

frm_Main.bmp

map1-01.bmp

map1-01-2.bmp

② Auto CAD LT drawing : Open Map 1. dwg

AutoCAD LT drawing should be already opened.

map1-01- 3.bmp

map1-00.bmp

①②

③ Chose "Unclosed deal " "Forest form Access form and click "Record search"

When the matched data is shown on a table, click "LT search"

(Check either "closed "or "un closed" box.)

Page 6: 1 第 1 部 Controlling AutoCAD LT on Access VBA

1110

map1-01-5.bmp

map1-01-6.bmp

④ Switch to Auto CAD LT window and corresponding land numbers turn into red.

(It takes a Few moments)

⑤ Switch to Access form window and click "detail data"

⑥ Go back to Auto CAD LT window to choose one of the red land umbers.

(A-10 is picked in the example below.)

map1-01-4.bmp

⑦ Click " Write object data "on Access form window.

(Access database and Auto CAD LT object data become linked )

⑧ Click "detail "on Access form window to display the data as below.

(I comment) this

( 注)写真が人では都合が悪いので、動物の写真に入れ替えています。

map1-01-07.bmp

map1-01-6-1.bmp

④⑤

Page 7: 1 第 1 部 Controlling AutoCAD LT on Access VBA

1312

Block insert the land number in "Map1.dwg"drawing and apply the object definition to the

land number.

③ Select "Create " → "Block " → "Object definitions."

Object definition dialogue is displayed.

Check "preset"

④ "name" and < A-1 > for "Value"

⑤ Set text height to < 6000.000 >

(It can be charged)

The scale of this drawing is not the actual size,

so the text is set on the bigger value.

⑥ Click the point where information insertion is desired.

⑦ Left click any point on the screen.

⑧ "Object definition" dialogue is displayed again and in formation of the insertion point is

displayed.

⑨ Click "OK" to insert "land number "as below.

The text can be resized and repositioned.

map1-02-3.bmp

map1-02-4.bmp

map1-02-5.bmp

Use "By block "to create,

NOT "By Layer." Only the

land number created by "By

block" can turn into a dif-

ferent color.

Procedure on Auto CAD LT Convert any publicly available data into data for use on CAD .

In this chapter, we use the government issued "Data map 2500" (space database )to create

CAD data.

① this is a picture of a block of [ Data map 2500 ]

② "Data map "is not based on CAD data, so this needs to be converted into CAD data (dwg

file)

map1-02-1.bmp

map1-02-2.bmp

Chubu interna-

tional airport

Chita peninsula

(Tokoname City )

The data used here is based on the image of the planned Chubu International Air port to

be located. off the coast of Tokoname city. The landscape of the tokoname city and sur-

roundings have been made by combining approximately 10 segments of "data map 2500 "

To refer to this information on the last page of this book..

“Data map 2500” is a

government map based on

1/2500 city planning base map.

Page 8: 1 第 1 部 Controlling AutoCAD LT on Access VBA

1514

Enter object data of the land number using “block insert “ command.

⑮ Select “Insert” → ”Block”

⑯ Select “land number “from “mane “ of “Block insert “ dialogue click “OK”

⑰ Left click at the place you want to insert the block.

The land number (A-01 as the number in the map below ) will be inserted immediately.

⑱ Copy and paste the land number (30 copies of the A-01 are pasted in the map)

map1-02-9.bmp

map1-02-10.bmp

map1-02-11.bmp

To block define the field as “land number “ using the “block definition “command.

⑩ Select “Create” → ”Block definition “

⑪ Enter “land number” in the name box and click “choose object”

⑫ Select “land number” and press “Enter “

⑬ ”block definition “ dialogue will reappear

Select “indicate the insertion point “ and click the center of “land number “

⑭ ”Block definition “ dialogue will appear again, chick “OK” to confirm.

map1-02-6.bmp

map1-02-7.bmp

map1-02-8.bmp

Page 9: 1 第 1 部 Controlling AutoCAD LT on Access VBA

1716

map1-02-16.bmp

map1-02-17.bmpmap1-02-11.bmp

⑲ Click “EDIT” → ”Object “ → ”EDIT Object “ ?

to edit the copied land number them from A-2 to A-30 )

In the version later than LT 2000i it can be edited by double clicking the number.

Give group names A-1 to A-30 to drawings.(A-1 is group named as A-1, A-2 is as

A-2)

⑳キーボードから [G] と入力しますと、下記のダイアログが表示されます。

21.[ グループを作成 ]ボタンを押して、左のグループの欄に <A-1> と入力します。

22.Choose land number A-1 and, click “add to the group “

So, A-1, the group name was given to the block, A-1.

map1-02-13.bmp

map1-02-14.bmp

map1-02-15.bmp

Grouping name each block of the drawing to match and Auto CAD LT drawing are

linked.

Here is a drawing numbered 1 to 30 as group names.

Auto CAD LT and Access are bonded by being given group names.

Block definitions make searching by land number equal block definitions.

Page 10: 1 第 1 部 Controlling AutoCAD LT on Access VBA

1918

④ Define table name as “T-Map1”and go back to “Object” in the form window.

⑤ Create “Criteria query” to set search criteria.

⑥ Place fields as below and set “kind of land” and “deal conditions” as search criteria to

narrow the search.

map1-03-6.bmp

Procedure on Access ① Choose “blank data base “ from Microsoft Access and name that file <Map 1.mdb> The file

is stored in “My document “in this example.

② Choose “Table” from “Object” then click “Design”

③Create database fields of “ID” “land number” ”owner” “current address” “kind of land” “land

address” “deal conditions” “photo” and set ID key.

map1-03-1.bmp map1-03-2.bmp

map1-03-4.bmp

map1-03-5.bmp

map1-03-6-1.bmp

map1-03-6-2.bmp

Table Name:T_map1 Query Name:Q_Map1

Page 11: 1 第 1 部 Controlling AutoCAD LT on Access VBA

2120

map1-03-9.bmp

map1-03-11.bmp

map1-03-8.bmp

map1-03-7.bmp

map1-03-8-1.bmp

⑤ Create a sub from as below to list marched records.

⑥ Create a main form, then place sub from in the main form and position command buttons

at the same time.

To create command buttons, click “create” new forms. “and position command buttons and

fields as below.

⑦ Create a detail information form to display a selected record from matched search re-

cords on AutoCAD LT window.

You can set “OLE size” to “Stretch” to fit the photo perfectly in to the box.

⑧ Choose “Command buttons” from “Tool Box “and re title this property “Closed forms”.

Procedure of the program

① Display the data (e.g. unclosed forest)

In Access form on the sub form by clicking “Record search”

② The land number of the matched data on AutoCAD LT becomes a different color

by clicking “LT search” on the form.

③ Switch to the Access form and click “Detail to AutoCAD LT for selecting a land

number from all the matched ones.

④ Select on, then chick “Write object” “Detail” from Access form.

Form Name:F_Map1

Sub Form Name :F_Map1_SubForm Name:F_Map1_ 詳細

Page 12: 1 第 1 部 Controlling AutoCAD LT on Access VBA

2322

[Summary for Form-F-Map1]Dim T _ file As String

Dim TP _ file As String

Option Compare Database

-----------------------------------

Private Sub LT Search _ Click ()

Read M _ MAP1 of Module.

Call

End Sub

-----------------------------------

Private Sub Data Query _Click()

App Activate “AutoCAD “ ‘Activate AutoCAD LT

Send keys “select” & Chr (13) & “si” & Chi (13),True’ Go to AutoCAD LT to search.

End Sub

-----------------------------------

Private Sub Record out _Click()

Do Cmd. Requery “F_MAP1_SUB”End

-----------------------------------

Private Sub send out _ Click()

App Activate “AutoCAD “ ‘ AutoCAD Activate AutoCAD LT Send out objects.

Send Key “filedia O” & Chr (13)_

& “-attext “ & Chr (13) & “op” & Chr (13) & “c” & Chr (13) & TP _ file & Chr(13)_

& T _ file & Chr (13) & “Y” & Chr (13) _

&” filedia O” & Chr (13), True

App Activate “access” ‘ Activate Access

End Snb

Private Sub closed deal _ Click ()

If Un closed =True Then

Un closed = False

Un closed YN = 1

End If

End Sub

Private Sub Unclosed _ Click ()

If Closed deal=True Then

Closed deal = False

Closed deal YN = 0

End if

End Sub

Private Sub Detail display _ Click ()

On Error GoTo Err _ Detail display _ Click

Dim stDocName As String

Dim stLnkCriteria As String

Tp _ file =” c:/LT2MDB/MAP1\MAP1 _ tenp. txt” ‘Create a fine to define object by memo first

T _ file =” c:/LT2MDB\MAP1/MAP1. txt” ‘Crate a file to send out object data by memo first.

Pick object data sent out from AutoCAD LT

Open T _ file For Input As #1 ‘Open a sending out file.

Fsize = LOF (1)

Do While Not EOF (1) ‘Repeat the procedure until the file.

Input #1, Zoku ‘Read the data

If Mid (Zoku, 1, 1) = ” ’ ” Then

Zoku = Mid (Zoku, 2, Len (Zoku) -2) ‘Deleting unnecessary commas

End if

Loop

Close #1

Store a form number for a detail display

Text land number

“sub form of kind of land “land number “From this point, the definition is automatically made by creating detail buttons

stDocName = ” F _ MAP1 _ Detail

stLnkCriteria = “[ land number ] = “ & “ ‘ “ & Me! [ Text land umber ] & “ ‘ “ DoCmd. OpenForm stDocName, , , stLnkCriteria

Exit _ Detail display _ Click :

Exit Sub

Err _ Detail display _ Click :

MsgBox Err. Descriptin

Resume Exit _ Detail display _ Click

End Sub

Page 13: 1 第 1 部 Controlling AutoCAD LT on Access VBA

2524

[Summary for Form _ Map1]

Private Sub Unclosed _ Click ()

On Error GoTo Err_ End _Click

DoCmd.Close

Exit_ End _Click:

Exit Sub

Err_ End _Click:

MsgBox Err.Description

Resume Exit_ End _Click

End Sub

Standard module [Summary for M Map1] public Sub land deal

Dim s _ sql As String

Dim chimoku As String

Dim baisyuu As String

chimoku = [Forms] ! [F _ MAP1] . [Kind of land ] ’ Criteria entered

baisyuu = [Forms] ! [F _ MAP1] . [ Closed YN] ‘ Criteria entered

Narrow the search to meet the criteria entered

s_sql = “ SELECT ID, Land number, owner, current address Kind of land, land size,deal conditions , FORM T _

MAP1 WHERE Kind of land = ‘ “ & chimol “ ‘ AND ((T _ MAP1.deal conditions = ‘ “

& baisyuu & “ ‘ ) “

DATABASE SET

Dim rs As New ADODB. Recorbset ‘ new recordset Replace the reference to the object

rs. Open s _ sql, CurrentProject. Connection, adOpenKeyset, adLockOptimisitic ‘ Refer

to the table of the data base or narrowed search

Set the number

Dim T_ban As String

Dim count As Long

Dim lp As Long

Open the data base

count = rs.RecordCount ' The number of record which meets the criteria

If count <> 0 Then

For lp = 1 To count ‘ Make sure this is the end of the fine

If lp = 1 Then

T_ban = rs! Land number ‘ No comma is used at the front

    Else

T_ban = T_ban & "," & rs! Land number       ’ Read data

End If

rs.MoveNext ' Next record

Next lp

rs.Close ' Close a searched file

Activate AutoCAD

Change all the data in the data in the AutoCAD LT drawing to “By layer” and turn matched

one red.

SendKeys “ ^ C ^ C” & “filedia 0” & Chr (13) & “chprop all C bylayer “ & Chr (13) _

& “ chprop g” & Chr (13) & T_ban & Chr (13) _

& Chr (13) & “ C red “ & Chr (13) & “ filedia 1” & Chr (13) , True

End if

End Sub

Page 14: 1 第 1 部 Controlling AutoCAD LT on Access VBA

2726

③ Enter the criteria from Access form window (e.g. 10 min. from a station)

Click “Search records” to display the matched records on a table, then switch to the Auto-

CAD LT window clicking “LT search”

④ The land number marking the criteria, appears in a different color.

map2-01-2.bmp

map2-01-3.bmp

Chapter 2 Map Management (Real estate in formation)

Aim・・・ Search and find the data to match criteria from.

AutoCAD LT map information using Access data base.

Sample file to

・Folder name :   c:/LT2MDB/Map2

 ・AutoCAD LT file: Map2.dwg

 ・Access 2000 file: Map2.mdb

・Text file:        Map2.txt Map2_temp.txt

Tip

① Access program : Choose [ Real estate info] from the main form.

Or ; choose c:\LT2MDB\LT2MDB.mdb and select. F_Map2, then open the file.

② AutoCAD LT drawing: Open Map 2. dwg

AutoCAD LT drawing should be already opened.

frm_Main.bmp

map2-01.bmp

map2-01-1.bmp

Page 15: 1 第 1 部 Controlling AutoCAD LT on Access VBA

2928

map2-02.bmp

⑤ Switch to the Access window and click “Details data”

⑥ Switch, again to AutoCAD LT to pick the place on a map to display details.

⑦ Select “Write Object “ of a form on Access window, then “Details”

The pictures of the room are displayed as below.

map2-01-4.bmp

map2-01-5.bmp

This 3D picture of the room is created by AutoCAD LT and AutoCAD 2000.

Use “Change the thickness “ and “Region” of AutoCAD LT to create such a picture.

30 of these 3D pictures are stored in C:\LT2MBD\Map2

Page 16: 1 第 1 部 Controlling AutoCAD LT on Access VBA

3130

③ Lock the picture so that if is stable when you use the mouse to draw.

Right click the bit map shortcut menu appears.

Uncheck “choosable” .

(This is to stablize the picture for working on)

④ Create a new graphic (name : polygon )and switch to this one.

Then, create streets and blocks, clicking “create”-“poly line”Group the houses and buildings to make blocks one by one.

⑤ Hatch the area you want to use.

map2-05.bmp

map2-06.bmp

map2-06-2.bmp

Procedure on AutoCAD LTConvert any publicly available map into one usable on CAD

We use “Map Fan VO” of increment P inc. to build the CAD data.

① This is a picture of shibuya station area in Tokyo in ported from Map Fan V digital map.

Create the bit map file based on this picture to insert in to AutoCAD LT.

Or you can paste the picture on AutoCAD LT window.

② Digital maps are actual photo maps, so they need to be converted to be a useable CAD

data map.

map2-03.bmp

map2-04.bmp

Map Fan V is the digital map cre-

ated by increment P Inc. This

Internet is internet linkable, so the

information of the data base is

revisable to reflect the latest map

information.

Page 17: 1 第 1 部 Controlling AutoCAD LT on Access VBA

3332

Register the hatched blocks by giving them definitions

⑦ Click “create” → ”Block “ → ”Object definition “Object definition dialogue is displayed.

Click “un display”

⑧ Enter “NO” for “name” and “1” for “value”

⑨ Set text height to <5> (It can be changeable)

⑩ Click “indicate the point “for the point of

insertion.

⑪ Left click at any point on the screen

⑫ ”Object definition “ dialogue is displayed again and the in formation of the inserting point

is input.

⑬ Click “OK” to insert “NO” as below. It is OK to resize and re position the text.

map2-06-8.bmp

map2-06-9.bmp

map2-06-10.bmp

⑤ This is the drawing with poly lining and hatching (bit map is displayed)

Separating the drawing of bit map from the hatched one makes “display / un display” switch

easier (In this example, the bit map is on <0> layer , and the drawing of street and blocks is

on <polygon >layer.

⑥ Bit map drawing and CAD drawing can be switch able.

On AutoCAD LT. Right click the bit map and select “switch to under “to layer CAD data

drawing on top of bit map drawing.

Right click the bit map and select “Switch to top “to layer CAD data drawing under the bit

map drawing.

map2-07.bmp

map2-06-3.bmp

map2-06-4.bmp

map2-06-5.bmp map2-06-6.bmp

Use “By block “ to create,

NOT “By layer” Only the

land number created by “By

block” can turn into a dif-

ferent color.

Page 18: 1 第 1 部 Controlling AutoCAD LT on Access VBA

3534

Give all the hatched drawings group names. (1 to )

Link the group names and Access keys)

⑦ Enter “G” to display the dialogue below.

⑧ Click “name the group” and enter “1” in “group” box, then pick a hatched drawing.

⑨ Click “add to group” This hatched drawing is defined as “1”.

⑩ Repeat steps to name all the drawing (30 drawing to total)

In the picture, the names of the groups are not visible.

map2-07.bmp

map2-08.bmp

map2-09.bmp

map2-10.bmp

To block define the item and the hatched drawing as [1] using block definition command.

⑩ Select “create “ → ”Block” → ”Block definition”

⑪ Enter [1] in the name box and chick “Choose Object”

⑫ Select “NO” and the hatched drawing, then “Enter”

⑬ Block definition dialogue will reappear, chick “indicate the insertion point “ and click the

center of “NO”

⑭ Block definition dialogue will show again .

check “change to block “ and click “OK” to confirm.

map2-06-11.bmp

map2-06-12.bmp

map2-06-13.bmp

The reason for using “ group

name” is to link.

AutoCAD LT and Access

2000. [Block definition] makes

it possible to search the

record by land number on

AutoCAD LT, when you want

the details of the data.

Page 19: 1 第 1 部 Controlling AutoCAD LT on Access VBA

3736

map3-04.bmp

map3-05.bmp

④ Create “Criteria query “to set search criteria.

Set a search criteria <min. from a station>

⑤ Create a sub from as below to list matched records.

⑥ Create a main form then place. A sub form in the main from and position command

buttons.

map3-05-1.bmp

Procedure on Access

① Select “Blank database from Microsoft.

Access and name that file <Map 2. mab> and store in <My document> in this example.

② Select “Table” from “Object” then click “Design”.

③ Create database fields of <number>

<name of the building> <address> <monthly rent> <size> <min. from a station> <photo A>

<photo B> and set <min. from a station>

map1-03-1.bmp

map2-03-1.bmp

map3-03.bmp

Query Name:Q_Map2

Sub Form Name:F_Map2_Sub

Form Name:F_Map2

Table Name:T_Map2

Page 20: 1 第 1 部 Controlling AutoCAD LT on Access VBA

3938

map3-06.bmp

⑦ Create a detail in formation form to display a selected record from matched search re-

cords. on AutoCAD LT window.

You can set [OLE size] to <stretch> to fit the photo in perfectly.

⑧ Select “command buttons” from “Tool Box “ and re title this property “Close forms”.

map1-03-8-1.bmp

Procedure of the program

① Display the typed data (e.g. 10min. from a station) in Access form on the sub form by

clicking “Record search”

② The land number of the matched data on AutoCAD LT becomes a different color by

clicking “LT search” on the form.

③ Switch to the Access form and click “Detail data” the window automatically changes

to AutoCAD LT to select a land number from all the matched one.

④ Choose one first, then “write object” → ”Detail” from Access form.

[Summary for Form _F_Map2]

Dim T_file As String

Dim TP_file As String

Option Compare Database

----------------------------------------------------------------------

Private Sub Form_Activate()

TP_file = "C:\LT2MDB\MAP2\MAP2_temp.txt" 'Create the file by MEMO first

T_file = "C:\LT2MDB\MAP2\MAP2.txt" 'Create the file by MEMO first

End Sub

----------------------------------------------------------------------

Private Sub LT_Click()

Call the distance from a station

End Sub

----------------------------------------------------------------------

Private Sub Command 8_Click()

DoCmd.Requery "F_MAP2_SUB"

End Sub

----------------------------------------------------------------------

Private Sub data selection_Click()

AppActivate "AutoCAD" 'Activate AutoCAD

SendKeys "filedia 0" & Chr(13) & "draworder" & Chr(13) & "g * " & Chr(13) & "f" & Chr(13) _

& "select" & Chr(13) & "si" & Chr(13), True

End Sub

----------------------------------------------------------------------

Private Sub details 2_Click()

On Error GoTo Err_ details 2_Click

Dim stDocName As String

Dim stLinkCriteria As String

Open T_file For Input As #1 'Open a send file.

'Fsize = LOF(1)

Do While Not EOF(1) 'Repeat the procedure until the file becomes empty

Input #1, Zoku2 'Read the data

If Mid(Zoku2, 1, 1) = "'" Then

Zoku2 = Mid(Zoku2, 2, Len(Zoku2) - 2) 'Deleting unnecessary commas.

End If

Loop

Close #1

'Store a form number for a detail display

Text land number = Zoku2

'zoku = Forms! [Sub form of kind of land ] [land number]

Form Name Details:F_Map2_ Details

Page 21: 1 第 1 部 Controlling AutoCAD LT on Access VBA

4140

'From this point, the definition is automatically made by creating detail buttons.

stDocName = "F_MAP2_ Details "

stLinkCriteria = "[Number ]=" & Me![Text number]

DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_ Details 2_Click:

Exit Sub

Err_ Details 2_Click:

MsgBox Err.Description

Resume Exit_ Details 2_Click

End Sub

----------------------------------------------------------------------------------

Private Sub Send _Click()

AppActivate "AutoCAD" ' Activate AutoCAD

'Send the AutoCAD LT data object

SendKeys "filedia 0" & Chr(13) _

& "-attext" & Chr(13) & "o p " & Chr(13) & "c" & Chr(13) & TP_file & Chr(13) _

& T_file & Chr(13) & "Y" & Chr(13) _

& "filedia 1" & Chr(13), True

AppActivate "access" ' Activate Access

End Sub

Private Sub command 13_Click()

On Error GoTo Err_ command13_Click

DoCmd.Close

Exit_ command 13_Click:

Exit Sub

Err_ command13_Click:

MsgBox Err.Description

Resume Exit_ command13_Click

End Sub

Standard Module [Summary for M _ Map _2]Public Sub The distance from a station ()

Dim s_sql As String

Dim fun As Integer

fun = [Forms]![F_MAP2]![Min] 'Criteria entered

'Narrow the search to meet the criteria entered

s_sql = "SELECT Number, name of the house and the building, address, size, min. FROM T_MAP2 WHERE

Min<= " & fun

'DATABASE SET

Dim rs As New ADODB.Recordset 'New recordset Replace the reference to the Object

rs.Open s_sql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic 'Refer to the table of

the data base or narrowed search

'Set the number

Dim No_1 As String

Dim count As Long

Dim lp As Long

'Open the database

count = rs.RecordCount 'The number of records which meet the criteria

If count <> 0 Then

For lp = 1 To count ' To make sure that this is the end of the file

If lp = 1 Then

No_1 = rs! Number ' No comma is used at the front

Else

No_1 = No_1 & "," & CStr(rs! Number) ' Read number

End If

rs.MoveNext

Next lp

rs.Close 'Close a searched file

AppActivate "AutoCAD" ' Activate AutoCAD LT.

'Change the order of the data, set all data back to “By layer”and turn matched one red.

SendKeys "^C^C" & "filedia 0" & Chr(13) _

& "draworder" & Chr(13) & "g * " & Chr(13) & "f" & Chr(13) _

& "chprop all C bylayer " & Chr(13) _

& "chprop g" & Chr(13) & No_1 & Chr(13) _

& Chr(13) & "C red " & Chr(13) & "filedia 1" & Chr(13), True

'AppActivate "access"

End If

End Sub

[Detailed summary for Form _ F _ Map2]

Page 22: 1 第 1 部 Controlling AutoCAD LT on Access VBA

4342

② AutoCAD LT drawing: Open Fa1. dwg.

AutoCAD LT drawing should be already opened.

③ In the drawing select the square in the click using “Object Edit” command.

Edit the item’s “serial number “ from “lata1” to “AAA” and click OK.

④ Switch to the form on Access window and click “LT receive” the serial number of the top

record is changed to “AAA”

Fa1-02.bmp

F a1-02-1. F a1-02-2.

F a1-02-3.

Chapter 3 Facility Management (Change object names of fa-

cility appliance)

AIM ・ ・ ・ *Link the chair name on AutoCAD LT and the information on Access

data base. (Import and revise the data in both AutoCAD LT and Access data

base)

Sample file to use

・Folder name:   c:/LT2MDB/Fa1

 ・Auto CAD LT file : Fa1.dwg

 ・Access 2000 file : Fa1.mdb

・Text file :        Fa1.txt Fa1_temp.txt

・Script file:           Fa1.scr

TIP

① Access program: Select “change facility appliances “from the main form.

Or select c: \LT2MDB\LT2MDB and click “Fa1.mdb”-“Form”-“open”

frm_Main.bmp

Fa1-01.bmp

Fa1-01-1.bmp

Page 23: 1 第 1 部 Controlling AutoCAD LT on Access VBA

4544

F a1-02-6.

F a1-02-7.

F a1-02-8.

F a1-02-9.

F a1-02-4.

⑤ Perform the same step on Access to import the revision to AutoCAD LT

Change “AAA” to “BBB” , click “send “

⑥ Switch to AutoCAD LT window and see the chair’s data number has changed to “BBB”

F a1-02-5.

This program is very useful to check the names and the numbers of items in a

drawing on AutoCAD LT.

It makers it easier to locate items in both AutoCAD LT and Access and to send

data between the two.

Procedure on AutoCAD LTCreate a block with an object’ s data on “Fa1.dwg

Draw a chair first.

③ Select “create” →” Block” →” Object

definition” . Object definition dialogue is

displayed.

Check “un display

④ Enter “number “for “name” and “1” for

“value” .

⑤ Set the text height to 2 (It is change-

able)

⑥ Chick “indicate the point” of insertion.

⑦ Left click anywhere on the screen.

“Object definition “dialogue is displayed

again and the information of the insertion

point is input.

⑧ Enter the rest of the objects using

To block define 4 items (the drawing

of chairs) as “chair1 “using the block

definition command.

⑨ Click “char” →” Block” →” Block

definiton” . Enter “Chair” in the name

box and click “Choose Object”

Page 24: 1 第 1 部 Controlling AutoCAD LT on Access VBA

4746

map1-03-1.bmpFa1-03.bmp

Fa1-04.bmp

Fa1-05.bmp

Fa1-02-10.bmp

Fa1-02-11.bmp

Table Name:T_Fa1

⑥ Repeat same steps to create other blocks. (Chair 1, Chair2, Chair3)

Place chair’s object data using block insert commands.

⑦ Click “Insert” →”Block”

⑧ Select “Chair from “name” of Block insert . dialogue, click “OK”

Procedure on Access

① Select “Blank database “ from Microsoft. Access and name that file “Map2.

mdb” then store in My documents, in this example.

⑨ Left click at the point to insert a block (a chair)

After the block is inserted, object data will be asked in order

(chairs are displayed, but their object data is nor visible)

⑩ Place blocks (Chair, Chari2 and Chair3) as below.

② Select “Table” from “Object” then click “Design”

③ Create data base fields of number / Style number / name / block name / com-

ments / x-axis / Y-axis

Page 25: 1 第 1 部 Controlling AutoCAD LT on Access VBA

4948

Fa1-06.bmp

Fa1-07.bmp

Sub form name:F_Fa1_Sub

Form name:F_

⑥ Create an “LT receive” button in the main form.

Describe receiving commands for object data of AutoCAD LT, here.

⑦ Create “LT send” button “in the same way.

Describe sending commands for the Access data to AutoCAD LT and editing com-

mands to edit the object data.

[Summary for Form _ F _ Fa1]④ To summarize the data object of AutoCAD LT, create a sub form as below.

⑤ Create a main form (F_FA1) and place a sub form in the main form.

Dim T _ file As String

Dim TP _ file As String

Dim S _ file As String

Option Compare Database

-----------------------------------

Private Sub LT receive _ Click ()

Dim Bangou As String

Dim Kataban As String

Dim Name As String

Dim Bname As String

Dim Setumei As String

Dim X As Double

Dim Y As Double

TP _ file = “c:/LT2mdb/FA1/FA1_temp.txt” ‘create the file by MEMO first.

T _ file = “c:/lt2mdb/FA1/FA1.txt” ‘create the file by MEMO first.

S _ file = “c:/lt2mdb/FA1/FA1.Scr” ‘create the file by MEMO first.

App Activate “AutoCAD “ ‘ Activate AutoCAD LT

Send out object data.

Send Keys “filedia O” & “-attext “ & Chr (13) & “o all c ” & TP _ file & Chr(13) &T _ file & Chr (13) & ” y” & Chr (13) ,True

Dim rs As New ADODB. Recordset ‘new recordset Replace the reference to the object.

rs. Open “T_FA1” , CurrentProject. Connection, adOpenKeyset, adLockOptimistic’ Refer to the table of the

data base or narrowed search.

‘Delete all the data.

Do Until rs.EOF

rs.Delete

rs.MoveNext

Loop

‘rs. MoveFirst ‘The top of the record.

Open T_file For Input As #1 ‘ Open a sending file

‘Fsize = LOF(1)

Do While Not EOF(1) ‘Repeat the procedure until the file becomes empty.

Input #1, Bangou

Input #1, Kataban

Page 26: 1 第 1 部 Controlling AutoCAD LT on Access VBA

5150

rs! Block name = Bname

rs! Comments = Setumei

rs! X-axis = X

rs! Y-axis = Y

rs. Update ‘Save

Loop

Close #1 ‘ Close a sending file

rs. Close ‘ Close a searched file

“ Redisplay the form

DoCmd. Close

DoCmd. OpenForm “F_FA1” , ac normal

DoCmd. GoToRecord , , acNewRec

AppActivate “access”

‘DoCmd. OpenForm

End Sub

Input #1, Name

Name = Mid(Name, 2, Len(Name) - 2)

Input #1, Bname

Bname = Mid(Bname, 2, Len(Bname) - 2)

Input #1, Setumei

Setumei = Mid(Setumei, 2, Len(Setumei) - 2)

Input #1, X

Input #1, Y

rs. AddNew ‘ New record

rs! Number = Bangou

rs! Style number = Ktaban

rs! Name = Name

Private Sub LT Send _ Click ()

Dim Bangou As String

Dim Kataban As String

Dim Name As String

Dim Bname As String

Dim Setumei As String

Dim XY As String

Dim X As Double

Dim Y As Double

TP _ file = “c:/LT2mdb/FA1/FA1_temp.txt” ‘create the file by MEMO first.

T _ file = “c:/lt2mdb/FA1/FA1.txt” ‘create the file by MEMO first.

S _ file = “c:/lt2mdb/FA1/FA1.Scr” ‘create the file by MEMO first.

Dim rs As New ADODB. Recordset

rs. Open “T_FA1” , CurrentProject. Connection, adOpenKeyset, adLockOptimistic

rs.MoveFirst

Open S_file For Input As #1 ‘Write in a script file

print #1, “clayer 0” ‘Make current layer “0”

print #1, “-layer F * T chair” Chr (13) ‘ Anchor other layers except for the one for a chair

print #1, “erase all” & Chr (13) ‘ Erase chair layer

print #1, “-layer T *” & Chr (13) ‘Display all the layer

Input data into unstable number value

Do Until rs.EOF

Bangou = rs! Number

Kataban = rs! Style number

Name = rs! Name

Bname = rs! Block name

Setumei = rs! Comments

X = rs! X-axis

y = rs! Y- axis

‘Y = Mid (Y, 1, Len(Y))

XY = Mid (Str(X), 1, 12) & “ ,“ & Mid(Str(Y), 2, 12)

Page 27: 1 第 1 部 Controlling AutoCAD LT on Access VBA

5352

frm_Main.bmp

Fa1-01-1.bmp

Fa2-01.bmp

Chapter 4 Facility management (Estimate the facil-

ity appliances)

Aim・・・ Import the maintenance information on Access data base

to the time object and price object of AutoCAD LT

Sample file to use

・Folder name:     c:/LT2MDB/Fa2

 ・AutoCAD LT file: Fa2.dwg

 ・Access file: Fa2.mdb

 ・Text file: Fa2.txt Fa2_temp.txt

TIP

① Access program ; select “Estimate facility appliances “ from the main form.

Or : choose c: \LT2MDB\LT2MDB and select Fa2. mdb. click “Form“ - “ open”

‘Print #1, “erase” & XY & Chr (13)

Re-enter X-Y axis valuesPrint #1, “-insert” & Name & Chr (13)_

& Setumei

Loop

rs. Chlose

Print #1, “filedia 1” & Chr (13)

Chlose #1

AppActivate “AutoCAD” Activate AutoCAD LT

‘ Send commands to AutoCAD LT

SendKeys “filedia 0” & Chr (13) & “ script” & Chr (13) & S_file & Chr (13), True

End Sub

Page 28: 1 第 1 部 Controlling AutoCAD LT on Access VBA

5554

Fa2-04.bmp

Fa2-06.bmp

Fa2-02.bmp

Fa2-03.bmp

F a2-03-1.

② AutoCAD LT drawing: Open Fa2. dwg.

AutoCAD LT drawing should be already opened.

④ Clicking “LT search” in the form of the Access window automatically switch-

es to the AutoCAD LT window to show the corresponding lights in yellow.(The

Original color of the lights is black.)

③ Enter “5” for “life” in the form on Access window and click “search”

④ Matched record is searched and listed on the table.

Page 29: 1 第 1 部 Controlling AutoCAD LT on Access VBA

5756

Fa2-17.bmp

Fa2-14.bmp

Fa2-15.bmp

Fa2-16.bmp

④ Enter “style number for “name” and “AAA”

for “value”

⑤ Set text height to 160 (In is changeable)

⑥ Enter other object data

Enter “life” for “name” and 2 for “value”

⑦ Chick “ indicate the point “for insertion

point

⑧ Left click anywhere on the screen object

definition dialogue is displayed again and the

information of the inserting point is input.

⑨ Enter the other objects using the same

steps.

To block define 2 items and the drawing of the

light bulb as “light bulb” using the block

definition command.

⑨ Click “Create” →“Block” →“Block defini-

tion”

Enter “Light bulb” in the name box and click

Place light bulbs with object data using block insert commands.

⑦ Select “Insert” →”Block”

⑧ Select “light bulb” from “name “ of Block Insert dialogue. Click “OK”

⑨ Left click at the point to insert a block (a light bulb)

After the blocks are inserted, object data will be asked in order.

(Light bulbs are displayed, but their object data are not visible)

⑩ Place blocks as below

Procedure on AutoCADCreate a block with the object data on a drawing of [Fa2. dwg]

Draw a light first

③ Click “Create “→“Block” →”Object definition” object definition

dialogue is displayed.

check”undisplay”

Page 30: 1 第 1 部 Controlling AutoCAD LT on Access VBA

5958

Fa2-20.bmp

Fa2-21.bmp

Fa2-22.bmp

map1-03-1.bmp

Fa2-08.bmp

Fa2-09.bmp

Table Name:T_

Fa2

Query Name:Q_Fa2

Form Name:F_

Sub Form Name:F_Fa2_

Procedure on Access

① Select Blank database “from Microsoft Access and name that file “Fa2. mdb”,

then store in <My documents> in this example.

④ Create “Criteria query “ to set search criteria .

Set search criteria “life left”

② Select “Table” from “object” then click “design”.

③ Create database fields of number / style number / block name / life left /

price / X‐axis / Y‐axis.

⑤ Create a sub form as below to list matched records.

⑥ Create a main form, then place a sub form in the main form and position

command buttons.

Page 31: 1 第 1 部 Controlling AutoCAD LT on Access VBA

6160 Fa2-10.bmp

[Summary for form _ F _ Map 2]

rivate Sub LTSearch_Click()

Call Facility

End Sub

---------------------------------------------------------------------

Private Sub LTreceive_Click()

Dim Kataban, Bname, Nokori As String

Dim i As Integer

Dim XY As String

Dim X As Double

Dim Y As Double

TP_file = "C:/LT2MDB/FA2/FA2_temp.txt" ' Create the file by MEMO First

T_file = "C:/LT2MDB/FA2/FA2.txt" ' Create the file by MEMO First

AppActivate "AutoCAD"

'Write object data

SendKeys "filedia 0 " & "-attext" & Chr(13) & "o all c " & TP_file & Chr(13) & T_file & Chr(13)

& "y" & Chr(13), True

Dim rs As New ADODB.Recordset 'New recordset Replace the reference to the object

rs.Open "T_FA2", CurrentProject.Connection, adOpenKeyset, adLockOptimistic 'Refer to the ta-

ble of the database or narrowed search

'Write the object of the data sent from the file

'Delete all the records

Do Until rs.EOF 'Repeat the procedure until the file becomes empty

rs.Delete 'Delete

rs.MoveNext 'Next record

Loop

'rs.MoveFirst 'The top of the record

Open T_file For Input As #1

Fsize = LOF(1)

Do While Not EOF(1)

Input #1, Kataban

Kataban = Mid(Kataban, 2, Len(Kataban) - 2) 'Read style number

Input #1, Bname

Bname = Mid(Bname, 2, Len(Bname) - 2) 'Read block name

Input #1, Nokori

Input #1, X

Input #1, Y

i = i + 1

rs.AddNew 'Add new record

rs!Number = i

rs!Style number = Kataban

rs!Block name = Bname

rs!Life left = Int(Nokori)

rs!X‐axis = X

rs!Y‐axis = Y

rs.Update 'Save edited data

Loop

Close #1

rs.Close

'Redisplay the form

DoCmd.Close 'Close the form

DoCmd.OpenForm "F_FA2", acNormal 'Open the form

DoCmd.GoToRecord , , acNewRec 'Relocate the record

AppActivate "access" 'Activate Access

'DoCmd.OpenForm

End Sub

---------------------------------------------------------------------------

Private Sub Search data_Click()

DoCmd.Requery "F_FA2_SUB"

End Sub

[Summary for form _ F _ Fa2 Sub ]

Private Sub Form_Activate()

Numbers.Value = Kosuu2

Grand total.Value = Goukei

End Sub

Private Sub Form_Load()

End Sub

Private Sub Commands8_Click()

On Error GoTo Err_Commands8_Click

DoCmd.Close

Exit_Commands8_Click:

Exit Sub

Err_Commands8_Click:

MsgBox Err.Description

Resume Exit_Commands8_Click

End Sub

Page 32: 1 第 1 部 Controlling AutoCAD LT on Access VBA

6362

Standard Module [ Summary for M‐Fa2]

Public Goukei As Integer

Public Kosuu2 As String

Public T_file As String

Public TP_file As String

Public S_file As String

Option Compare Database

Public Sub Facility()

'Set the numerical value

Dim s_sql As String

Dim Nen As Integer

Dim No As String

Dim count As Long

Dim lp As Long

Dim XY As String

Dim X As Double

Dim Y As Double

S_file = "c:/LT2mdb/FA2/FA2.scr" 'Crete the file by MEMO first

T_file = "c:/LT2mdb/FA2/FA2.txt" 'Crete the file by MEMO first

Nen = [Forms]![F_FA2]![ 年 ] 'Criteria entered

'Narrow the search to meet the criteria entered

s_sql = "SELECT Number, style number, block name, Life left, x‐axis x‐axis FROM T_FA2 WHERE

life left = " & Nen

'DATABASE SET 'Open data base

Dim rs As New ADODB.Recordset 'New recordset Replace the reference to the object

rs.Open s_sql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic 'Refer to the ta-

ble of the data base or narrowed search

Open S_file For Output As #1 'Write into script file

Print #1, "zoom e" 'Zoom the drawing

Print #1, "chprop all C bylayer" & Chr(13) 'Set every item [By layer]

Print #1, "clayer light bulbs " 'Set current layer to light bulbs

Print #1, "-layer f * " 'Anchor other layers except for light bulbs

count = rs.RecordCount 'Number of the record matched

For lp = 1 To count ' Make sure that this is the end of the file

X = rs!X-axis 'Read the data

Y = rs!Y-axis

XY = Mid(Str(X), 1, 12) & "," & Mid(Str(Y), 2, 12)

XY = LTrim(XY) 'Erase the space on top

rs.MoveNext

Print #1, "chprop " & XY & Chr(13) & Chr(13) & "C yellow " 'Turn only matched data yellow

using X‐Y axis values

Next lp

rs.Close ' Close searched file

Print #1, "-layer t * "

Print #1, "filedia 1 " & Chr(13)

Close #1 'Close file

AppActivate "AutoCAD" ' Activate AutoCAD LT

'Send commands to AutoCAD LT

SendKeys "filedia 0" & Chr(13) & "script" & Chr(13) & S_file & Chr(13), True

End Sub

Page 33: 1 第 1 部 Controlling AutoCAD LT on Access VBA

6564

Dat1-03.bmp

Dat1-03-1.bmp

Dat1-03-2.bmp

frm_Main.bmp

Dat1-01.bmp

Dat1-00.bmp

Chapter 5 Database Management (parts Management1)

Aim * Replace parts on AutoCAD LT drawing quickly and easily by

Access data input.

Sample file to use

Folder name c:/LT2MDB/Dat1

AutoCAD LT file Dat1.dwg

Access 2000 file Dat1.mdb

Text file Dat1.txt Dat1_temp.tx

Script file Dat1.scr

② AutoCAD LT drawing : Open Map 1.dwg.

AutoCAD LT drawing should be already opened

Tip

Access program Select “Parts Management 1.”from the main form or: choose c:\

LT2MDB\LT2MDB and select Dat1.mdb click “form”―”open” ③ Click “pars to replace “in the form of the Access window

④ The window automatically switches to AutoCAD LT for selecting parts to re-

place. The parts in a circle is the one to be replaced.

(The name of this block is pump3A)

Page 34: 1 第 1 部 Controlling AutoCAD LT on Access VBA

6766

Dat1-10.bmp

Dat1-11.bmp

Dat1-12.bmp

Dat1-03-3.bmp

Dat1-03-4.bmp

⑥ In the AutoCAD LT drawing window, all the pump3A blocks are replaced to

Procedure on AutoCADCreate a block with the object data on

[Dat1 dwg]

Draw w ring first

③ Click “Create” → ”Block” → “object

definition” object definition dialogue is

displayed.

Check “un display”

④ Enter “number” for “name” and “1” for

“value”

⑤ Set the text height to 10

(It is changeable)

⑥ Press [indicate the point ] for a in-

serting point.

⑦ Left click anywhere on the screen ob-

ject definition dialogue is displayed

again and the information on of the in-

sertion point is input.

⑤ Go back to the form on Access window, select pump1A from New block name

“Send” to LT

To block define on item and the drawing of rings as “pump1A” using the block

definition command.

⑨ Click “Create” → “Block ” → “Block definition”

Enter “Pump1A” in the name box and click “Choose Object”

Page 35: 1 第 1 部 Controlling AutoCAD LT on Access VBA

6968

map1-03-1.bmp

Dat1-04.bmp

Dat1-15.bmp

Dat1-13.bmp

Dat1-14.bmp

Place rings with object data using block insert commands

⑦ Click “Insert” → “Block ”

⑧ Select “Pump3A “ from “name” of Block insert dialogue, Click “OK”

 Procedure on Access

① Choose “Blank data base” form Microsoft Access and name that file “Dat1.

mdb” then store in My documents in this example.

⑨ Left click at the point to insert a block (a ring)

After the block is inserted, object data will be asked in order.

(Rings are displayed, but the object data is not visible)

⑩ Place clocks as below

⑪ Group name the blocks to bind.

 The group name for blocks of Pnmp1A is “Pump1”

 The group name for blocks of Pump2A is “Pump2A”

 The group name for blocks of Pump3A is “pump3A”

 

 

Binding the blocks and naming each group is to link.

 AutoCAD LT drawing and Access key of the data base.

③ Create data base fields of <NO> <Style number> <name> <block name> <com

-ments>.

② Click “table” from “Object” click “ design”

Table name:T_Dat1

Page 36: 1 第 1 部 Controlling AutoCAD LT on Access VBA

7170

Dat1-16.bmp

Dat1-17.bmp

Sub from name:F_Dat1_

f o r m n a m:F _

⑤ Place a Sub form into the main form and position other items as below.

④ To summarize the block, create a sub form as below

Sub form name.

[Summary for Form _ F _ Dat1]

DDim T_file As String

Dim TP_file As String

Dim S_file As String

Dim henkou As String

Dim Bname As String

Option Compare Database

--------------------------------------------------------------------------------

Private Sub LT_Click()

Dim Bangou As String

Dim X As Double

Dim Y As Double

Dim ret As Integer

Dim i As Integer

TP_file = "C:/LT2mdb/DAT1/DAT1_temp.txt" 'create the file by MEMO first

T_file = "C:/LT2mdb/DAT1/DAT1.txt" 'create the file by MEMO first

S_file = "c:/LT2mdb/DAT1/DAT1.Scr" 'create the file by MEMO first

AppActivate "AutoCAD" ' Activate AutoCAD.

'Send object data

SendKeys "filedia 0" & Chr(13) & "-attext" & Chr(13) & "o p " & Chr(13) & "c" & Chr(13) & TP_

file & Chr(13) _

& T_file & Chr(13) & "Y" & Chr(13), True

AppActivate "Access" ' Activate Access

If henkou = "" Then

ret = MsgBox("Block name has not been started !", vbOKOnly, Warnning")

Exit Sub

End If

'Create script file while reading records.

'Create 「Selection set 」using select command and group them at the end.

'rs.MoveFirst 'Top of the record

Open T_file For Input As #1 'Open a send file

Open S_file For Output As #2 'Write into a script file.

Print #2, "clayer Buhin" 'Set to parts layer

Print #2, "select R " 'Unlock all the selection set

i = 1

'Fsize = LOF(1)

Page 37: 1 第 1 部 Controlling AutoCAD LT on Access VBA

7372

Dat2-03.bmp

frm_Main.bmp

Chapter 6 Data base Management (Parts Management 2)

Aim Import the block names and numbers on AutoCAD LT drawing quick-

ly and easihp for revising the.

Access data base.

Sample file to use

Folder name: c:/LT2MDB/Dat2

Auto CAD LT file: Dat2.dwg

Access 2000 file: Dat2.mdb

Text file: Dat2.txt Dat2_temp.txt

Script file: Dat2.scr

Tip

① Access program : Choose [Parts management2] from the main

form.

Do While Not EOF(1) 'Repeat the procedure until the file becomes empty.

Input #1, Bangou

Input #1, X

Input #1, Y

If i = 1 Then

Delete the previous block (delete blocks by group name, the procedure

has to be done at this point other wise [select] command can not be

valid . later in the program [select] command is necessary to group

the block.

Select Case Bangou

Case "1"

Bname = "Pump1A"

Case "2"

Bname = "Pump2A"

Case "3"

Bname = "Pump3A"

End Select

Print #2, "erase g " & Bname & Chr(13) 'Delete the previous grouped data.

i = 2

End If

XY = Mid(Str(X), 1, 12) & "," & Mid(Str(Y), 2, 12) 'String X and Y.

Print #2, "-insert" & Chr(13) & henkou & XY & " 1 1 0" 'Insert the selected block.

Print #2, "select l p " 'Create select set

Loop

Close #1

'Group the blocks using select set

Print #2, "-pkfstgroup c " & henkou & Chr(13) & "y * " & Chr(13) & "P " 'Group command

Print #2, "filedia 1 " & Chr(13)

Close #2 'Close the file

AppActivate "AutoCAD" ' Activate AutoCAD

'Send command to AutoCAD LT

SendKeys "filedia 0" & Chr(13) & "script" & Chr(13) & S_file & Chr(13), True

End Sub

-----------------------------------------------------------------------------------

Private Sub Select_Click()

AppActivate "AutoCAD" ' Activate AutoCAD

'Click the block to change

SendKeys "select" & Chr(13) & "si" & Chr(13), True

End Sub

-----------------------------------------------------------------------------------

Private Sub Change_Change()

henkou = Change.Value

End Sub

Page 38: 1 第 1 部 Controlling AutoCAD LT on Access VBA

7574

Dat2-13.bmp

Dat2-14.bmp

Dat2-15.bmp

Dat2-04.bmp

Dat2-05.bmp

Dat2-05-1.bmp

② AutoCAD LT drawing: Open dat2. dwg.

AutoCAD LT drawing should be already opened.Procedure on AutoCAD Create a block with the object data on a

drawing of [Dat2. dwg]

Draw a ring first

The case of Pump1A

③ Select “Create “ →”Block” →”Object

definition” Object definition dialogue is

displayed.

Check “un display”

④ Enter “parts name” for “name” and “PC1A “

for “value”

⑤ Set the text definition to 10.

(It is change able )

⑥ Click “indicate the point” for inser-

tion point

⑦ Left click anywhere on the screen.

Object definition dialogue in displayed

again and the information of the insertion

point is input.

⑧ Enter the remaining objects using the

same steps.

The value for (Pump2A ) is (Pc2A), the

value for (Pump3A ) is (Pc3A) and the one

for (Pump4A ) is (Pc4A).

④ When the number of the block in changed on AutoCAD LT, just click “revise”

in the form of Access window to revise the data base.

③ Click “send” in the form of the Access window, then “revise”

The block names, its number and the price in the drawing file are displayed on

a table.

To block define an item and the drawing of rings as [Pump1A] using the block

definition command;

⑨ Choose “Create” → ”Block “ → ”Block definition”

Enter “Pump1A “ for the name box and click “Choose object”

Page 39: 1 第 1 部 Controlling AutoCAD LT on Access VBA

7776

map1-03-1.bmp

Dat2-06.bmp

Dat2-07.bmp

Dat2-18.bmp

Dat2-16.bmp

Dat2-17.bmp

Table name:T_Dat2

Place rings with object data using block insert commands.

⑩ Choose [Insert] → [ Block]

⑪ Choose [Pump1A] from [name] of [Block insert] dialogue, then press [OK]

Procedure on Access① Choose <Blank data base> from Microsoft/

Access and name that file <Dat2, mdb> then, Store in <My documents> in this ex-

ample.

⑫ Left click at the point to insert a block (Pump1A)

After the blocks are inserted, object data will be asked in order.

(Rings are displayed, but its object data are set to be invisible)

⑬ Place blocks as below.

② Choose <Table> from [Object] then press [Design]

③ Table name.

Create data base fields of <parts name> <number> <price> <total>

Page 40: 1 第 1 部 Controlling AutoCAD LT on Access VBA

7978

Dat2-19.bmp

Dat2-20.bmp

Sub form name:F_Dat2_Sub

form name:F_Dat2

⑤ Place a sub form into the main form and position other items as below.

Form name

④ Create a sub form to add up the blocks

Sub form.

[Summary for Form _ F _ Dat1]

Dim T_file As String

Dim TP_file As String

Dim S_file As String

Dim Cnt(3) As Integer 'Declare the order

Dim Tan, Goukei, i As Integer

Option Compare Database

-----------------------------------------------------------------------------

Private Sub list_Click()

TP_file = "c:/Lt2mdb/DAT2_temp.txt" 'Create the file by MEMO first

T_file = "c:/LT2mdb/DAT2\DAT2.txt" 'Create the file by MEMO first

'Dim stDocName As String

'Dim stLinkCriteria As String

Dim rs As New ADODB.Recordset

'Open the table

rs.Open "T_DAT2", CurrentProject.Connection, adOpenKeyset, adLockOptimistic

'Delete all the records

Do Until rs.EOF

rs.Delete 'Delete

rs.MoveNext 'Next record

Loop

'Read the object data sent from the file and count them

Open T_file For Input As #1

Do While Not EOF(1) 'Repeat the procedure until the file becomes empty

Input #1, Bname

Bname = Mid(Bname, 2, Len(Bname) - 2)

Select Case Bname

Case "PC1A"

Cnt(0) = Cnt(0) + 1 'Input the value into land number 0

Case "PC2A"

Cnt(1) = Cnt(1) + 1 'Input the value into land number 1

Case "PC3A"

Cnt(2) = Cnt(2) + 1 'Input the value into land number 2

Case "PC4A"

Cnt(3) = Cnt(3) + 1 'Input the value into land number 3

End Select

Loop

Page 41: 1 第 1 部 Controlling AutoCAD LT on Access VBA

80

'Set block names and price using [Array]

Bname = Array("PC1A", "PC2A", "PC3A", "PC4A")

Tan = Array(100, 200, 300, 400)

i = 0

Do While 4 > i

rs.AddNew

rs!Parts name = Bname(i)

rs!Number = Cnt(i)

rs!Price = Tan(i)

rs!Total = (Cnt(i) * Tan(i))

rs.Update

i = i + 1

Loop

rs.Close

'Redisplay the form

DoCmd.Close

DoCmd.OpenForm "F_DAT2", acNormal

DoCmd.GoToRecord , , acNewRec

Close #1

End Sub

-----------------------------------------------------------------------------------

Private Sub Send out the data_Click()

S_file = "C:/LT2mdb/DAT2/DAT2.Scr" 'Create the file by MEMO first

TP_file = "C:/Lt2mdb/DAT2/DAT2_temp.txt" 'Create the file by MEMO first

Open S_file For Output As #1 'Write into a script file

Print #1, "filedia 1 " & Chr(13) 'Make the dialogue invisible

'Send out the object data

Print #1, "-attext" & Chr(13) & "o All " & Chr(13) & "c " & TP_file & Chr(13) & T_file

Close #1

AppActivate "AutoCAD" ' Activate AutoCAD

'Send commands to AutoCAD LT

SendKeys "filedia 0" & Chr(13) & "script" & Chr(13) & S_file & Chr(13), True

AppActivate "access" 'Activate Access

End Sub