Professional Documents
Culture Documents
Autocad Vba-1
Autocad Vba-1
VBA
VBA Editor VB .
VBA(Visual Basic Application) VB(Visual Basic) AutoCAD 2000 .
, VBA AutoCAD , ,
AutoCAD 2000 AutoCAD R14 InteliCAD .
, , , , .
VBA
, VBA
, AutoCAD
VB VB AutoCAD
AutoCAD .
.
VBA Lisp ObjectARX
VBA Editor
AutoCAD 2000 VBA Editor Tools\Macro
\Visual Basic Editor ALT+F11 .
VBA (, , )
AutoCAD Object
Forms
Standard modules
Class modules
References
Project Explorer
Project Explorer Window Forms, Code
Modules, Class Modules . < 2>
Project .
2. Project Explorer
138 3 2000/8
AUTOCAD
Code Window
Code Window VBA Editor
Code Widow . Code
. View\Code F7 .
3. Code Window
Properties Window
. Form , ,
.
4. Propeties Window
Standard Modules
Standard Modules
, , Data Type, .
. Degrees Radians
, .
Class Modules
Class Modules ,
Method, Property, Events .
Code , Line
Property Code Line .
2000/8 3139
AutoCAD
Property
Object Property .
Line StartPoint Property Position
dblStartPoint = objLine.StartPoint
MsgBoxThe Line begins as & dblStartPoint(0) &, &
dblStartPoint(1) & _
. 5
, & dblStartPoint(2)
dbjLine.Color = acRed
Methods
Object ,
Property Object Method
. AddCircle method ModelSpace
Circle object .
.
dblCenterPoint (0) = 0#
dblCenterPoint (0) = 0#
dblCenterPoint (0) = 0#
dblRadius = 2#
Set objcircle=ThisDrawing.ModelSpace.AddCircle(dblCenterPoint,
dblRadius)
Events
Event , , .
If
If <> then
. a=1 b=0.
Select case
If a=1 then b=0
Select case a a ,
If a=1 then
b=0
case 1
b=1
case 2
End if
b=2
.
.
.
If a=1 then
b=0
case else
b=3
End select
esle
b=1
end if
a 1 b=1, 2 b=2, a b
3. case else .
140 3 2000/8
AUTOCAD
(Loop)
For Next
Do
For a=1 To 10 Step 2
b=a+b
Next a
<>
Loop <>
<> .
a 1 10 2 10
.
Do Until a>=10
a=a+1
Do Loop
b=a+b
Do Loop 2 .
Do <>
<>
Loop
, a 10 , b=55
. Until Loop Do
. If Do Loop .
For Next
: Dim, Static
: Dim, Private, Public
Dim Data1 As Integer
Data1 () .
Dim Data1 As Integer
Data1 , Data1
.
Static Data1 As Integer
Data1 (
.
Private Data1 As Integer( )
Dim Public .
Public Data1 As Integer
Data1 () .
.
) .
, 0 100
. , 0 100
, ,
2000/8 3141
AutoCAD
< 1> VB
Byte
0255
Boolean
True False
Integer
-32,76832,767
Long
-2,147,483,648 ~2,147,483,647
&
Single
Double
Currency
-922,337,203,685,477.5808922,337,203,685,477.5807
Date
: -3.402823E38-1.401298E-45
: 1.451298E-453.402823E38
:-1.79769313486232E308-4.94065645841247E-324
:4.94065645841247E-3241.79769313486232E308
Object
String
1- 65,400
Variant
: Double
: 22 +
A .
,
1
. A .
A(0)=1
A(1)=2
A(2)=3
A(3)=4
,
A(1,1)=2
A(1,2)=4
A(2,1)=3
, .
A , 4 5
, 3 6
, 3 , 5 2 7
, Single. A(0,0) .
Dim A(3 , 4) As Integer
Dim A(3 to 5, 2 to 7) As Single
.
Dim A(0 To 3, 0 To 4) As Single
VBA VB .
AutoCAD Object ,
AutoCAD .
142 3 2000/8
1 VBA
5 Drawing Objects
6 VBA Project
3 AutoCAD
7 Excel VBA
4 Layers Linetypes