Vba for Autocad by Na!
-
Upload
dejan-drumac -
Category
Documents
-
view
342 -
download
15
Transcript of Vba for Autocad by Na!
-
7/27/2019 Vba for Autocad by Na!
1/83
-
7/27/2019 Vba for Autocad by Na!
2/83
..
BA AutoCAD LISP rograming
a Programmer VBA
a VBA
2005Na
-
7/27/2019 Vba for Autocad by Na!
3/83
Visual Basic for Application (VBA) 1
VBA 1 Visual Basic 3 Visual Basic 4
4 Event/ Object/ Method/ Property 4
MODULE I - Hello~ World! 5
VBA Code 5 6 7
4 Hello~ World 7
MODULE II - CAD Entity : Add~ 9
CAD 92 Line 93 Circle 104 Poly Line 115 DTEXT 136 LAYER 167 STYLE 188 Block 209 Hatch 22
MODULE III - : Utility.Get~ 24
Utility Get~ 242 GetPoint 253 GetReal / GetInteger / GetString 264 GetDistance 275 GetAngle 28
MODULE IV - : IF ~ THEN 29
1 If Then Else 292 Select Case 303 GoTo 31
-
7/27/2019 Vba for Autocad by Na!
4/83
MODULE V - : Do ~ Loop 33
1 Do Loop 332 For Next 353 For Each Next 35
MODULE VI : - SelectionSet 37
1 SelectionSet 372 Select 383 Copy / Move / Mirror / Rotate 43
Property 465 Select Filter 47
FORM: User Interface - UserForm1.~ 51
1 Design Mode 512 Control 52
Control 524 Label / TextBox /CommendButton 535 CheckBox / OptionButton / Frame 55
PROGRAM I : Program
- Photo Numbering 58
Program 58 59 59 62 66 67
Form 68 PROGRAM II : Excel - ToExcel 74
RUN : DVB - Lisp 78
DESCRIPTION : - 79
-
7/27/2019 Vba for Autocad by Na!
5/83
Visual Basic for Application (VBA)
Visual Basic for Application ( VBA)
Visual Basic- .
VBA AutoCAD Microsoft Office VBA .
1 : VBA
Na! .. .
DATA ..
Active-X . VBA AutoCAD .
1. BA VBA DVB .
2 : Windows DVB
-
7/27/2019 Vba for Autocad by Na!
6/83
DVB LISP CAD
. AutoCAD (T) (A) VBA
< 1> .
BA VBAMAN /
VBA
VBARUN + VBAisual Basic + VBA
VBA
1 : AutoCAD VBA
< 3> .
3 : VBA
.. LISP
. LISP ..
..
.. ...
-
7/27/2019 Vba for Autocad by Na!
7/83
2. isual Basic VB + < 4> .
VBA + .
4 : Visual Basic
Visual Basic ( VB ) .
. : VB .
.. VB VBA
.
. :
.
. : .
. : Form Form .
. : VB .
. : VB VB
.
5 : VB
-
7/27/2019 Vba for Autocad by Na!
8/83
3. isual Basic VBA < 6> .
6 : VBA
User Interface Module
User Interface . User Interface AutoCAD VBA
Form .
VBA Form Module
.
..
...
= Form, = Module ..
4. Event/ Object/ Method/ Property Visual Basic
.
Na! .. ..
Event CAD
.
.
VBA .
Object VBA .Method VBA .Property (0, 0)
100
VBA (Object)
.
2 : Event/ Object/ Method/ Property
...
Method Property
-
7/27/2019 Vba for Autocad by Na!
9/83
MODULE I - Hello~ World!
1. BA Code. VBA Code < 3> .
utoCAD VBAMachine Pentium 4 -OperatingSystem Windows XP -
Application AutoCAD Application ( : CAD Excel)
Object Document (*.dwg) /Entity (Line)
CAD
Property (AutoCAD Line )Start Point / End Point
CAD
3 : VBA /
. VBA Form Module Module
Procedure . < 7> .
7 : VBA
. Procedure Sub - Eed Sub
.
Procedure [ ], [ ], [ ] .
VBA Module Module
Procedure ..
[ VBA Module Procedure ] .
...
-
7/27/2019 Vba for Autocad by Na!
10/83
2. - .
. .
... X2 +1 X 3 ?..
X .. .
.
Dim [ : Test] As [ : Integer]
Code 1 :
[Dim] [As] .
"Test" (Integer) .
.
< 4> .
Public Program .Dim Module .
Private Module .Static Procedure .
4 :
[Dim] ..
Module Program .
.
< 5> .
Byte 0 255
Boolean True False Integer -32,768 32,767 Long -2,147,483,648 2,147,483,647Single Double Single Date 100 1 1 9999 10 31Object String Varian
5 :
. .. [ ] .
. Option Explicit
VBA .
[Option Explicit] Error .
Option Explicit ..
-
7/27/2019 Vba for Autocad by Na!
11/83
3. CAD VBA Application -> Object 1 -> Object 1-1 -> Method ->
Entity Property [ . ] .
Property . CAD
.
Thisdrawing.Modelspace.AddLine(StartPoint, EndPoint)
Code 2 : VBA
Code 2 .
Application - AutoCAD .
AutoCAD
..
Object 1 Thisdrawing .Object 1-1 Modelspace CAD Model( ) .Method AddLine CAD Line .Property StartPoint, EndPoint .
6 :
4. Hello~ World .
Sub Hello()
Dim Text_P(0 To 2) As Double 'TEXT .
Dim Text_H As Double 'TEXT .
Dim Text_St As String 'TEXT .
Dim Text_T As AcadText ' TEXT .
Text_P(0) = 0 'TEXT .
Text_P(1) = 0
Text_P(2) = 0
Text_H = 10 'TEXT .
Text_St = "Hello~ World!" 'TEXT .
'TEXT .
Set Text_T = ThisDrawing.ModelSpace.AddText (Text_St, Text_P, Text_H)
End Sub
Code 3 : Hello~ World
-
7/27/2019 Vba for Autocad by Na!
12/83
[Hello~ Word!] .
[Hello~ World!] CAD
Text(Object) (Property) Text .
AutoCAD .
[Hello World!] .
Na! [Hello Word!] .
. .
-
7/27/2019 Vba for Autocad by Na!
13/83
MODULE II - CAD Entity : Add~
CAD .
1. AD CAD VBA .
( ) .
. Dim / As
. . .Add~
.
7 :
.. ..
2. Line CAD .
Sub Ex_Line()
Dim Ex_Line As AcadLine ' Line (Ex_line) .
Dim P1(0 To 2) As Double ' Line (P1) .
Dim P2(0 To 2) As Double ' Line (P2) .
P1(0) = 0 'P1(0) X . .
P1(1) = 0 'P1(1) Y . .
P1(2) = 0 'P1(2) Z . .
P2(0) = 100 'P2(0) X . .
P2(1) = 200 'P2(1) Y . . P2(2) = 0 'P2(2) Z . .
'Model( ) Line .
Set Ex_Line = ThisDrawing.ModelSpace.AddLine(P1, P2)
End Sub
Code 4 : Lien
(0,0) (100,200) .
-
7/27/2019 Vba for Autocad by Na!
14/83
.
. Sub Ex_Line()
Line Procedure . .
AutoCAD Error .
Error
Error .
.
. Dim P1(0 to 2) As Double
. P1 X,Y,Z P1
P1(0), P1(1), P1(2) 3 P1
. -> .
Point .. 2 X,Y,X-[P1(0), P1(1), P1(2)] .
Error . .. VBA 0 .
. Set Ex_Line = ThisDrawing.ModelSpace.AddLine([ : P1], [ : P2])
Line . [SET] .
. ['] Program .
3. Circle (0, 0) 100 Model .
Sub Ex_Circle()
Dim Ex_Circle As AcadCircle ' Circle (EX_Circle) .
Dim P1(0 To 2) As Double ' Circle (P1) .
Dim R1 As Double ' Circle (R1) .
P1(0) = 0 'P1(0) X . .
P1(1) = 0 'P1(1) Y . .
P1(2) = 0 'P1(2) Z . .
R1 = 100 'R1 .. .
'Model( ) Cercle .
Set Ex_Circle = ThisDrawing.ModelSpace.AddCircle(P1, R1)
End Sub
Code 5 : Circle
Line [Add~] Method Property [P1], [R1] .
-
7/27/2019 Vba for Autocad by Na!
15/83
4. Poly Line 2D Polyline .
Sub EX_Polyline()
Dim EX_PL As AcadLWPolyline '2 PolyLine .
Dim PT(0 To 9) As Double ' PolyLine .
' PolyLine .
PT(0) = 1: PT(1) = 1
PT(2) = 1: PT(3) = 2
PT(4) = 2: PT(5) = 2
PT(6) = 3: PT(7) = 2
PT(8) = 4: PT(9) = 4
' PolyLine .
Set EX_PL = ThisDrawing.ModelSpace.AddLightWeightPolyline(PT)
'4 .
EX_PL.SetBulge 3, -0.5
' .
Dim newPT(0 To 1) As Double ' .
newPT(0) = 4: newPT(1) = 1 ' .
EX_PL.AddVertex 5, newPT '6 .
'5 .
EX_PL.SetWidth 4, 0.1, 0.5
EX_PL.Closed = True 'Polyline .
EX_PL.Update 'Polyline .
End Sub
Code 6 : Polyline
VBA PolyLine AcadPolyline, AcadLWPolyline, Acad3DPolyline
3 ...
AcadPolyline : . 2 (X,Y) .
AcadLWPolyline : 2D .
2 (X,Y) .
Acad3DPolyline : 3 ..
2 .. ..
-
7/27/2019 Vba for Autocad by Na!
16/83
.
. Set EX_PL = ThisDrawing.ModelSpace.AddLightWeightPolyline([ : PT])
Polyline .
[PT] 5 2 .
. EX_PL.SetBulge [ : 3],[ : -0.5]
[SetBulge] AutoCAD PL / (A) .
. [SetBulge]
.
[SetBulge] .
. EX_PL.AddVertex 5[ ], newPT[ 2 ]
.
. EX_PL.SetWidth 4[ ], 0.1[ ], 0.5[ ]
[SetWidth] AutoCAD PL / (H) .
[SetWidth] .
. EX_PL.Closed = True
[Closed = True] AutoCAD PL / (C) .
< 8> .
8 : EX_PolyLine
Polyline < 8> .
[1] VBA [0] ..
.. VBA 0 ..
-
7/27/2019 Vba for Autocad by Na!
17/83
5. DTEXT DTEXT Hello~ World .
DTEXT .
-Line / Circle / Poly line Hello~World ...
...
Sub Ex_Dtext_1()
Dim Text_P(0 To 2) As Double 'TEXT .
Dim Text_H As Double 'TEXT .
Dim Text_St As String 'TEXT .
Dim Text_St01 As String 'TEXT .
Dim Text_St02 As String 'TEXT .
Dim Text_T As AcadText ' TEXT .
'TEXT .
Text_P(0) = 100
Text_P(1) = 100
Text_P(2) = 0
'TEXT .
Text_H = 2
'TEXT .Text_St01 = "Ex"
Text_St02 = "Dtext"
' TEXT . [+] [&] .
Text_St = Text_St01 + " " & Text_St02
'TEXT .
Set Text_T = ThisDrawing.ModelSpace.AddText(Text_St, Text_P, Text_H)
'TEXT .
Text_T.Alignment = acAlignmentCenter
'TEXT .
Text_T.TextAlignmentPoint = Text_P
End Sub
Code 7 : Text
"Ex" "Dtext" [Text_P]
.
-
7/27/2019 Vba for Autocad by Na!
18/83
.
. Text_St = Text_St01 + " " & Text_St02
VBA String( ) [+] [&] . [" "]
.
String .
. Text_T.Alignment = acAlignmentCenter[ ]
Text [Alignment] Property .
[Alignment] < 8> .
acAlignmentTopLeft acAlignmentTopCenter acAlignmentTopRight acAlignmentMiddleLeft acAlignmentMiddleCenter acAlignmentMiddleRight
- acAlignmentLeft acAlignmentCenter acAlignmentRight acAlignmentBottomLeft acAlignmentBottomCenter acAlignmentBottomRight acAlignmentAligned acAlignmentMiddle acAlignmentFit
8 : Text
< 9> .
9 : Text
. Text_T.TextAlignmentPoint = Text_P
Text (0, 0) . Text Text
.
Text [TextAlignmentPoint] Property
.
(- []) (0,0) Ex_DText
. Text_P = (100,100) .
Text .
-
7/27/2019 Vba for Autocad by Na!
19/83
.
Sub Ex_Dtext_02()
' .
Dim A1 As Double
Dim Text_T As AcadText
Dim Text_S As String
Dim Text_P1(0 To 2) As Double
Dim Text_P2(0 To 2) As Double
Dim Text_H As Double
' Text .
Text_P1(0) = 100
Text_P1(1) = 100
Text_P1(2) = 0
'Text .
Text_H = 2
' .
A1 = 10000 / 3
'Text .
Text_S = A1
' Text .
Set Text_T = ThisDrawing.ModelSpace.AddText(Text_S, Text_P1, Text_H)
' Text .
Text_P2(0) = Text_P1(0)
Text_P2(1) = Text_P1(1) - 5
Text_P2(2) = Text_P1(2)
' .
Text_S = Format(A1, "#,##0.00")
' Text .
Set Text_T = ThisDrawing.ModelSpace.AddText(Text_S, Text_P2, Text_H)
End Sub
Code 8 : Text
-
7/27/2019 Vba for Autocad by Na!
20/83
. [A1] Double [Text_S]
11 . Format
.
.
. Text_P2(1) = Text_P1(0) - 5
Y Y .
Code .
Text_P1(1) = Text_P1(1) - 5 .
Text_P1(1) 95 ..
. Text_S = Format(A1[ ], "#,##0.00"[ ])
[Format] , , . Code 8
3 [,] .
< 9> [Format] .
Format
5459.4 "#,##0.00" 5,459.40 [0] [#] .
[0] 0
[#] .5459.4 "####.##" 5459.4
5 "0.00%" 500.00% [%]
100 % .
"HELLO" "" THIS IS IT [>]
.
9 : Format
6. LAYER (Active Layer) . .
"Ex_Layer"
.
Sub Ex_Layer_01()
Dim Ex_Lay As AcadLayer ' Layer .
Dim Name_Lay As String ' Layer .
Name_Lay = "Ex_Layer" ' Layer .
-
7/27/2019 Vba for Autocad by Na!
21/83
'Layer .
Set Ex_Lay = ThisDrawing.Layers.Add(Name_Lay)
Ex_Lay.Color = acGreen 'Layer
'Layer .
MsgBox (Ex_Lay.Name & " .")
' Layer Layer .
ThisDrawing.ActiveLayer = ThisDrawing.Layers(Name_Lay)
End Sub
Code 9 : Layer
.
. Set Ex_Lay = ThisDrawing.Layers.Add([Layer : Name_Lay])
Layer . CAD [ModelSpace](
[PaperSpace] ) [Layers] . [Layers] Layer
Collection VBA [ModelSpace] .
Block, Style, Linetype ..
Collection.. ..
. Ex_Lay.Color = acGreen Layer . VBA ACI 0 ~
256 VBA .
BA ACI BA ACI BA ACIacByBlock (0) acGreen (3) acMagenta (6)
acRed (1) acCyan (4) acWhite (7)
acYellow (2) acBlue (5) acLayer (256)
10 : Color Property
[~.Color] Property Layer CAD
.
.
< >
Set Ex_Circle = ThisDrawing.ModelSpace.AddCircle(P1, R1)
Ex_Ciecle.Color = acRed
< >
Code 10 : CAD
-
7/27/2019 Vba for Autocad by Na!
22/83
. MsgBox (Ex_Lay.Name & " .")
[MsgBox] . [ ]
. Code [Ex_lay.Name] [Ex_lay]
CAD Property .
10 : MsgBox
Layer Ex _Layer" MsgBox
. Layer Test ..
. ThisDrawing.ActiveLayer = ThisDrawing.Layers(Name_Lay)
Layer . Layer VBA Code [ActiveLayer] CAD Layer .
Layer
ThisDrawing.Layers([Layer / INDEX ]) .
INDEX Layer 0 .
7. STYLE TEXT STYLE . TEXT STYLE
.
Layer .
Sub Ex_Style()
' .
Dim Name_ST As String
Dim Name_F As String
Dim Obj_ST As AcadTextStyle
'InputBox Style .
Name_ST = InputBox(" TEXT Style : ")
' Font .
Name_F = "HY "
'Style .
Set Obj_ST = ThisDrawing.TextStyles.Add(Name_ST)
'Font .
Obj_ST.SetFont Name_F, False, False, 1, 0
-
7/27/2019 Vba for Autocad by Na!
23/83
' Style .
ThisDrawing.ActiveTextStyle = ThisDrawing.TextStyles(Name_ST)
End Sub
Code 11 : Style
.
. Name_ST = InputBox(" TEXT Style : ")
[InputBox] . [InputBox]
Module .
[String : ] Style
.
11 : InputBox
. Name_F = "HY
[SetFont] Font .
Font File .
. Set Obj_ST = ThisDrawing.TextStyles.Add([Style : Name_ST])
Style . Style [InputBox] .
Layer [TextStyles] Collection .
. Obj_ST.SetFont Name_F, False, False, 1, 0
Style Font Code
Obj.ST.SetFont [Font ], [Bold ], [Italic ], [CharSet], [PitchAndFamily]
.
[ ] : Font . ( : String)
[Bold ] : . ( : Boolean)
[Italic ] : . ( : Boolean)
[Charset] : Font . ( :
[PichAndFamily] : Font . ( : 0)
Font [FontFile], [BigFont] [*.shx] .
True Type Font(Windows : [*.TTF] ) SetFont .
..[charset] [PichAndFamily] ..
Font . ...--;
-
7/27/2019 Vba for Autocad by Na!
24/83
. ThisDrawing.ActiveTextStyle = ThisDrawing.TextStyles(Name_ST)
Style . Layer [TEXT] Style
.
Style [StyleName] Property .
Style
.
< >
'Text .
Set Text_T = ThisDrawing.ModelSpace.AddText(Text_St, Text_P, Text_H)
'Text Style .
Text_T.StyleName = "Ex_Style"
End Sub Code 12 : Text Style
[Ex_Style] Style ..
8. Block Block Layer Style [BLocks] Collection . Block
[InsertBlock] Method . Block
.
Sub Ex_Block()
'
Dim Ex_Block As AcadBlock
Dim Name_B As String
Dim Bbp(0 To 2) As Double
Bbp(0) = 0: Bbp(1) = 0: Bbp(2) = 0 'Block
Name_B = "Ex_Block_Name" 'Bock
'Block .
Set Ex_Block = ThisDrawing.Blocks.Add(Bbp, Name_B)
'
Dim B_PL01 As AcadLWPolyline
Dim B_PL02 As AcadLWPolyline
Dim PL_dH As Double
Dim PL_dV As Double
Dim BPL1_p(0 To 3) As Double
Dim BPL2_p(0 To 3) As Double
-
7/27/2019 Vba for Autocad by Na!
25/83
' PolyLine
PL_dH = 5
PL_dV = 5
BPL1_p(0) = Bbp(0) - PL_dH: BPL1_p(1) = Bbp(1)
BPL1_p(2) = Bbp(0) + PL_dH: BPL1_p(3) = Bbp(1)
BPL2_p(0) = Bbp(0): BPL2_p(1) = Bbp(1) - PL_dV
BPL2_p(2) = Bbp(0): BPL2_p(3) = Bbp(1) + PL_dV
'Polyline
Set B_PL01 = Ex_Block.AddLightWeightPolyline(BPL1_p)
B_PL01.ConstantWidth = 1
Set B_PL02 = Ex_Block.AddLightWeightPolyline(BPL2_p)
B_PL02.ConstantWidth = 1
' Block
Dim EX_iBlock As Object ' Block
Dim B_IP(0 To 2) As Double 'Block
Dim Sx As Double 'Block X
Dim Sy As Double 'Block Y
Dim Sz As Double 'Block ZDim RA As Double ' Block
B_IP(0) = 100: B_IP(1) = 100: B_IP(2) = 0 'Block
Sx = 1: Sy = 1: Sz = 1 'Block
RA = 0.7853 'Block
'Block
Set EX_iBlock = ThisDrawing.ModelSpace.InsertBlock(B_IP, Name_B, Sx, Sy, Sz, RA)
End Sub
Code 13 : Ex_Block
1 [X] 100,100 Block
.
Block , Block , Block
.
.... Code ..
.. .
-
7/27/2019 Vba for Autocad by Na!
26/83
. Set Ex_Block = ThisDrawing.Blocks.Add(Bbp[ ], Name_B[Block ])
Block Code [Blocks] [Collection] . Code
.
[ ] : Block InsertPoint .
Txet [InsertPoint] [TextAlignmentPoint] ..
. Set B_PL01 = Ex_Block.AddLightWeightPolyline(BPL1_p)
Block PolyLine Code . PolyLine
[ModelSpace] Block [Ex_Block] .
. B_PL01.ConstantWidth = 1
Code PolyLine .
PllyLine ..
[SetWidth] . [ConstantWide] .
. Set EX_iBlock = ThisDrawing.ModelSpace.InsertBlock _
([ : B_IP], [ : Name_B], [ X,Y,Z: Sx, Sy, Sz], [ :RA])
Block Code Code .
[ ] : Block Block[ ] . - ( : Point /3 )
[ ] : Block . - ( : String)
[ X, Y, Z] : Block 3 . - ( :Double)
[ ] : Block .
Block Radian . - ( :Double)
9. Hatch Hatch [Collection] .
[AppendOuterLoop] . Hatch .
Sub Ex_Hatch()
'Hatch
Dim Ex_Hc As AcadCircle
Dim P_Cen(0 To 2) As Double
Dim C_R As Double
P_Cen(0) = 0: P_Cen(1) = 0: P_Cen(2) = 0
C_R = 10
'Hatch
Dim H_obj As AcadHatch
Dim H_Name As String
Dim H_Type As Long
Dim H_ass As Boolean
Dim H_OL(0 To 0) As AcadEntity
-
7/27/2019 Vba for Autocad by Na!
27/83
H_Type = 0
H_Name = "solid"
H_ass = True
'Hatch
Set Ex_Hc = ThisDrawing.ModelSpace.AddCircle(P_Cen, C_R)
'Hatch
Set H_obj = ThisDrawing.ModelSpace.AddHatch(H_Type, H_Name, H_ass)
Set H_OL(0) = Ex_Hc 'Hatch
H_obj.AppendOuterLoop (H_OL)
H_obj.Evaluate ' Hatch
H_obj.Color = acCyan 'Hatch
End Sub
Code 14 : Hatch
.
. Set H_obj = ThisDrawing.ModelSpace.AddHatch _ ([Hatch : H_Type], [Hatch : H_Name], [ Hatch : H_ass])
Hatch . ModelSpace Layer Block
.
[Hatch ] : Hatch [0] .
[Hatch ] : Hatch . - ( : String)
[ Hatch ] : Hatch . - ( : Boolean)
[Hatch ] .. .. ...
.. ... Na! .. ..
. Set H_OL(0) = Ex_Hc / H_obj.AppendOuterLoop (H_OL)
Hatch . [Ex_Hc]
[H_OL(0)] .
[AppendOuterLoop] .
[H_OL(0)] . .. ..
.. .. OuterLoop .
. H_obj.Evaluate
Hatch . Hatch .
Block [InsertBlock] ..
-
7/27/2019 Vba for Autocad by Na!
28/83
MODULE III - : Utility.Get~
MODULE II CAD .MODULE II Code .MODULE III . VBA [InputBox]
[From] [Form] [Modul]e
Data [Utility.Get~] .
1. tility.Get~ [Utiltyt.Get~] .
Ex_Get = ThisDrawing.Utility.GetPoint(, " : )
Code 15 : Utility.Get~
Data < 11> .
DATA Utility GetAngle .
ANGBASE .
GetCorner .GetDistance
.
GetInput .GetInteger (Integer) . GetKeyword .GetOrientation .
ANGBASE .
GetPoint AutoCAD . GetReal (double) . GetString (String) . GetSubEntity .InitializeUserInput GetKeyword .
11 : Utility.Get~ DATA
.
.. ..
.. ..
-
7/27/2019 Vba for Autocad by Na!
29/83
2. GetPoint AutoCAD .
[GetPoint]
X 100, Y 100 .
Sub Ex_GetPoint()
' .
Dim Ex_L As AcadLine
Dim SP As ACAD_POINT ' Point .
Dim EP(0 To 2) As Double ' 3 .
' .
SP = ThisDrawing.Utility.GetPoint(, " : ")
' .EP(0) = SP(0) + 100: EP(1) = SP(1) + 100: EP(2) = SP(2)
' .
Set Ex_L = ThisDrawing.ModelSpace.AddLine(SP, EP)
End Sub
Code 16 : GetPoint
.. Dim SP As ACAD_POINT
[GetPoint] [ACAD_POINT] .
. SP = ThisDrawing.Utility.GetPoint([Pont: ], [Prompt: " : "])
[GetPoint] .
Prompt .
[GetPoint] .
. .
[GetPoint] Na! ..
. EP(0) = SP(0) + 100: EP(1) = SP(1) + 100: EP(2) = SP(2)
[GetPoint] [ACAD_POINT] 3 .
3 [GetPoint] .
[SP] 'DIM SP(0 to 2) As Double'
.. .. ..
... .. ..
-
7/27/2019 Vba for Autocad by Na!
30/83
3. GetReal / GetInteger / GetString -[GetReal], -[GetInteger], -[GetString]
.
Sub Ex_Get_Re_In_St()
'
Dim G_Real As Double
Dim G_Integer As Integer
Dim G_String As String
'
G_Real = ThisDrawing.Utility.GetReal("GetReal :")
G_Integer = ThisDrawing.Utility.GetInteger("GetInteger :")
G_String = ThisDrawing.Utility.GetString(0, "GetString :")
'
MsgBox ("Real : " & G_Real & vbCrLf & _
"Integer : " & G_Integer & vbCrLf & _
"String : " & G_String)
End Sub
Code 17 : GetReal / GetInteger /GetString
.. G_Real = GetReal( [Prompt : "GetReal :] )
DATA AutoCAD .
. G_Integer = ThisDrawing.Utility.GetInteger([Prompt :"GetInteger :"])
[GetReal] . AutoCAD DATA .
.
. G_String = ThisDrawing.Utility.GetString ([HasSpaces :0], [Prompt : "GetString :"])
[GetString] AutoCAD DATA .
[GetRea]l [GetIneger] [HasSpaces] .
(Spaces) Boolean
[True : 1] [False : 0]
.
Space Enter .
[GetString] [0] [1] Space Enter .
-
7/27/2019 Vba for Autocad by Na!
31/83
4. GetDistance .
(0, 0) [MsgBox] .
Sub Ex_GetDistance()
' .
Dim Ex_L As AcadLine
Dim Dist As Double
Dim SP(0 To 2) As Double
' .
SP(0) = 0: SP(1) = 0: SP(2) = 0
' .
Dist = ThisDrawing.Utility.GetDistance(SP, " ")
' MsgBox .
MsgBox (" " & vbCrLf & Dist & " .")
End Sub
Code 18 : Ex_GetDistance
.
. Dist = ThisDrawing.Utility.GetDistance([Point : SP], [Prompt :" "]) [GetDistance] [GetPoint] .
[GetPoint] [SP] .
.
.
. MsgBox (~ & vbCrLf & ~)
[MsgBox] . [vbCrLf] .
[vbCrLf] VBA < > < > .
[MsgBox] .
< 12> .
BA Chr vbCr Chr 13 ( )vbLf Chr 10 ( )
vbCrLf Chr 13 + Chr 10 vbTab Chr 9 vbBack Chr 8
12 : VBA
-
7/27/2019 Vba for Autocad by Na!
32/83
5. GetAngle [GetAngle] Radian .
Sub Ex_GetAngle()
' .
Dim Get_A As Double
Dim SP(0 To 2) As Double
' .
SP(0) = 0: SP(1) = 0: SP(2) = 0
' .
Get_A = ThisDrawing.Utility.GetAngle(SP, " : ")
' . MsgBox (" Radian " & vbCrLf & _
Get_A & " .")
End Sub
Code 19 : GetAngle
.
. Get_A = ThisDrawing.Utility.GetAngle([Point : SP], [Prompt : " : "] )
[GetDistance] . . Radian .
3 0 + .
GetOrientation .. [O]
.. .. .. Angle ..
-
7/27/2019 Vba for Autocad by Na!
33/83
MODULE IV - : IF ~ THEN
MODULE III .MODULE II AutoCAD VBA Code .
MODULE IV Code .
AutoCAD Programing .
Coding ..
1. If - Then - Else [If - Then - Else] .
12 : IF
< 12> IF .
IF
.
Program .
.. .. Program ..
0 ~ 10 5
.
Sub Ex_if()
'
Dim Get_I As Integer
'
Get_I = ThisDrawing.Utility.GetInteger("0 10 : ")
-
7/27/2019 Vba for Autocad by Na!
34/83
'
If Get_I > 10 Then
Debug.Print " ."
ElseIf Get_I < 0 Then Debug.Print Get_I & " ."
ElseIf Get_I < 5 Then Debug.Print Get_I & " [5] ."
ElseIf Get_I > 5 Then Debug.Print Get_I & " [5] ."
Else
Debug.Print Get_I & " [5] ."
End If
End Sub
Code 20 : IF / THEN /ELSE
.
. If / Then / Else /End If
.
If :
Then : True . Else : False .
- ElseIf : False .
End If : .
If[ ] Then[ ]
... [ ]
. Debug.Print(" ~)
[Debug.Print] [MsgBox] .
VBA .
Na! [Debug.Print] Code Test ..
2. Select Case [Select Case] [If-Then-Else] [If] True False
[Select Case] .
[Select Case] [If]
.
Sub Ex_Select_Case()
'
-
7/27/2019 Vba for Autocad by Na!
35/83
Dim Get_I As Integer
Get_I = ThisDrawing.Utility.GetInteger("0 10 : ")
'
Select Case Get_I
Case Is < 0
Debug.Print (Get_I & " _ .")
Case Is > 10
Debug.Print (Get_I & " .")
Case Is < 5
Debug.Print (Get_I & " [5] .")
Case Is > 5
Debug.Print (Get_I & " [5] .")Case 5
Debug.Print (Get_I & " [5] .")
End Select
End Sub
Code 21 : Select Case
. Select Case [ : Get_I]
Code .
. Case [ : ]
[Select Case] [Case] .
[Select] .
.. [Case is < 5] [Case is < 0]
-10 ~[5] . ..
[If] .. ..
..
. End Select
[Select] .
3. GoTo [GoTo] Label .
.
[If] [GoTo] .
-
7/27/2019 Vba for Autocad by Na!
36/83
Sub Ex_GoTo()
'
Dim Get_I As Integer
Get_I = ThisDrawing.Utility.GetInteger("1 MsgBox . :")
' Label_01
If Get_I = 1 Then GoTo LB_01
MsgBox (" GoTo .")
'Goto Label
LB_01:
MsgBox (" GoTo Label .")
End Sub
Code 22 : GoTo
[GoTo] [MsgBox] .
1 [MagBox] .
1 1 ..
. GoTo [Label : LB_01]
Label .
. LB_01:
[GoTo] .
[Label] [GoTo] [:] .
[GoTo] [GoTo] [Label] Code .
[GoTo] code .. .. ..
Code ..
-
7/27/2019 Vba for Autocad by Na!
37/83
MODULE V - : Do ~ Loop
MODULE V Programing . Code .
. .. Na! VBA . ..
.. ..
1. Do - Loop [Do - Loop] [Do] [Loop] Code
.
[Do - Loop] .
Sub Ex_Do()
'
Dim I01 As Integer '
I01 = 0 '
Do While I01 < 10 '
I01 = I01 + 1 '
'
MsgBox " DO " & I01 & " ."
Loop '
'
Dim I02 As Integer '
I02 = 1 '
Do Until I02 > 10 '
'
MsgBox " DO " & I02 & " ."
I02 = I02 + 1 '
Loop '
'
Dim I03 As Integer '
-
7/27/2019 Vba for Autocad by Na!
38/83
I03 = 1 '
Do '
'
MsgBox " DO " & I03 & " ."
If I03 = 10 Then Exit Do '
I03 = I03 + 1 '
Loop '
End SubCode 23 : Do - Loop
[I0#]
[MsgBox] 10
. .
. Do While [ : I01 < 10] ~ Loop
.
[I01] 10 .
. Do Until [ : I02 > 10] ~ Loop
.
[I01] 10 .
. Do ~ [ : If / Exit Do] ~ Loop
.
[Do - Loop] .
[Exit Do] .
Na! " ." [Do ~ [ : If / Exit Do] ~ Loop]
. [For - Next]
[Do ~ [ : If / Exit Do] ~ Loop]
.
. : I01 = I01 + 1
.
.
[For - Next]
. Na! --;
-
7/27/2019 Vba for Autocad by Na!
39/83
2. For - Next [For - Next] [Do - Loop]
. [Step] .
[For - Next] .
Sub Ex_For_Next()
'
Dim Cnt As Integer
'
For Cnt = 10 To 1 Step -2
'
MsgBox " For - Next " & vbCrLf & _
" =" & Cnt
Next '
End Sub
Code 24 : For - Next
. For [ : Cnt] = [ :10] To [ :1] Step [ :-2]
For .
[1] . [While / Until] Do [Step]
.
. Next
[Do] [Loop] .
3. For Each - Next [For Each -Next] Collection .
Collection .
Layer Collection [For Each - Next] .
Collection MODULE II Layer, Style
Sub Ex_For_Fach_Next()
'
Dim Lay_C As AcadLayers 'Layer Collection
Dim F_Lay As AcadLayer ' Layer
Dim Name_Lay As String ' Layer
Dim Cnt As Integer '
-
7/27/2019 Vba for Autocad by Na!
40/83
' Layer Collection
Set Lay_C = ThisDrawing.Layers
'
Cnt = 0
'
For Each F_Lay In Lay_C
Cnt = Cnt + 1 '
Name_Lay = F_Lay.Name 'Layer
'Layer
MsgBox " " & Name_Lay & " Layer ."
'
Next F_Lay
'
MsgBox " " & Cnt & " Layer ."
End Sub
Code 25 : For Each - Next
Layer .
.
Layer .
. Set Lay_C = ThisDrawing.Layers
[For Each] Layer Collection . [For Each]
[Layers],[Styles] Collection
[SelectionSet] .
[SelectionSet] . ..
. For Each [Collection : F_Lay] In [Collection : Lay_C]
Code Collection .
Collection . Collection
.
-
7/27/2019 Vba for Autocad by Na!
41/83
MODULE VI : - SelectionSet
MODULE VI .MODULE II CAD [.Add~] Method . Property .
Method Property Page 4 < 2> ..
1. SelectionSet [SelectionSet] [SelectionSets] Collection
. [SelectionSet] .
Sub Ex_SelectionSet()
'
Dim SsetObj As AcadSelectionSet
'SelectonSet
Set SsetObj = ThisDrawing.SelectionSets.Add("S01")
MsgBox "[" & SsetObj.Name & "]" & "SelectionSet ."
End Sub
Code 26 : SelectionSet
[SelectionSet] Collection
.
[Set SetObj = ThisDrawing.~] [Error] .
[SelectionSet] .
Code "S01" [SelectionSet] S01"
[Error] . [Error] ..
.
Sub Ex_SelectionSet()
'
Dim SsetObj As AcadSelectionSet
'SeletionSet Error
On Error Resume Next
If ThisDrawing.SelectionSets.Item("S01") Then _
ThisDrawing.SelectionSets.Item("S01").Delete
On Error GoTo 0
-
7/27/2019 Vba for Autocad by Na!
42/83
'SelectonSet
Set SsetObj = ThisDrawing.SelectionSets.Add("S01")
MsgBox "[" & SsetObj.Name & "]" & "SelectionSet ."
' SelectionSet
ThisDrawing.SelectionSet.Item("S01").Delete
End Sub
Code 27 : Error SelectionSet
[SelectionSet] [Error]
. .
. Dim [ :SsetObj] As [ :AcadSelectionSet]
[SelectionSet] . [SelectionSet] [SelectionSets] Collection
[AcadSelectionSet] .
. On Error Resume Next
If ThisDrawing.SelectionSets.Item("S01") Then _
ThisDrawing.SelectionSets.Item("S01").Delete
On Error GoTo 0
[SelectionSet] .
On Error Resume Next : [Error] .If Thisdrawing. ~ Then Thisdrawing.~ ("S01").Delete
: [SelectionSet] - S01 .
On Error GoTo 0 : [Error] Code .
. Set SsetObj = ThisDrawing.SelectionSets.Add("S01")
"S01" [SelectionSet] .
Collection [.Add] .
. ThisDrawing.SelectionSet.Item("S01").Delete
[SelectionSet] . Error .
2. Select [Select] [SelectionSet] < 13> .
Select SelectAtPoint SelectByPolygon SelectOnScreen
13 : Select
-
7/27/2019 Vba for Autocad by Na!
43/83
[Select] .
(0,0) (100,100) [MsgBox]
.
Sub Ex_Select()
'
Dim SsetObj As AcadSelectionSet 'SelectionSet
Dim P1(0 To 2) As Double 'Point 1
Dim P2(0 To 2) As Double 'Point 2
Dim Ca As Integer '
Dim obj As Variant '
P1(0) = 0: P1(1) = 0: P1(2) = 0 'Point 1
P2(0) = 100: P2(1) = 100: P2(2) = 0 'Point 2
Ca = 0 'Counter
' Error
On Error Resume Next
If ThisDrawing.SelectionSets.Item("S01") Then ThisDrawing.SelectionSets.Item("S01").Delete
On Error GoTo 0
'SelectionSet
Set SsetObj = ThisDrawing.SelectionSets.Add("S01")
'
SsetObj.Select acSelectionSetCrossing, P1, P2
'
For Each obj In SsetObj
MsgBox "[" & SsetObj.Name & "]" & " SelectionSet " & vbCrLf & _
"[" & obj.ObjectName & "]" & " ."
C a = C a + 1
Next obj
MsgBox " " & Ca & " "
End Sub
Code 28 : Select
[Select] 4 . [Select]
.
.. ..
-
7/27/2019 Vba for Autocad by Na!
44/83
. SsetObj.Select [ Mode : acSelectionSetCrossing], [Point1 : P1], [Point2 : P2]
[Select] < 13>
[SelectionSet : SsetObj] .
< 14> .
Mode acSelectionSetWindow 0
. Select
acSelectionSetCrossing 1
.
Select
acSelectionSetFence 2 .
SelectByPolygon
acSelectionSetPrevious 3 .
Select
acSelectionSetLast 4 .
Select
acSelectionSetAll 5 . SelectacSelectionSetWindowPolygon 6 Polygon
. SelectByPolygon
acSelectionSetCrossingPolygon 7 Polygon
.
SelectByPolygon
14 : Select Mode
Mode .
. .
.. --; ..
Sub Ex_SelectAtPoint()
'
Dim SsetObj As AcadSelectionSet 'SelectionSet
Dim P1(0 To 2) As Double 'Point
Dim Ca As Integer 'Counter
Dim obj As Variant '
P1(0) = 0: P1(1) = 0: P1(2) = 0 'Point
Ca = 0 'Counter
' Error
On Error Resume Next
If ThisDrawing.SelectionSets.Item("S01") Then ThisDrawing.SelectionSets.Item("S01").Delete
On Error GoTo 0
-
7/27/2019 Vba for Autocad by Na!
45/83
'SelectionSet
Set SsetObj = ThisDrawing.SelectionSets.Add("S01")
'
SsetObj.SelectAtPoint (P1)
'
Ca = SsetObj.Count 'SelectionSet
Set obj = SsetObj.Item(0) 'SelectionSet
MsgBox "[" & SsetObj.Name & "]" & " SelectionSet " & vbCrLf &
"[" & obj.ObjectName & "]" & " ."
MsgBox " " & Ca & " "
End Sub
Code 29 : SelectionAtPoint
[SelectAtPoint] .
[SelectAtPoint] .
. SsetObj.SelectAtPoint [Point : P1]
[SelectAtPoint] .
. Ca = SsetObj.Count
[SelectionSet : SsetObj] .
. Set obj = SsetObj.Item(0)
[SelectionSet : SsetObj] .
VBA 0 .. .
Index 0 .
[~.Count] -1 .
[Set obj = SsetObj.Item(Ca-1)] .
.. ..
Sub Ex_SelectByPolygon()
'
Dim SsetObj As AcadSelectionSet 'SelectionSet
Dim P1(0 To 11) As Double 'Point List
Dim Ca As Integer 'Counter
Dim obj As Variant '
-
7/27/2019 Vba for Autocad by Na!
46/83
'Point List
P1(0) = 0: P1(1) = 0: P1(2) = 0
P1(3) = 100: P1(4) = 0: P1(5) = 0
P1(6) = 100: P1(7) = 100: P1(8) = 0
P1(9) = 0: P1(10) = 100: P1(11) = 0
Ca = 0 'Counter
' Error
On Error Resume Next
If ThisDrawing.SelectionSets.Item("S01") Then ThisDrawing.SelectionSets.Item("S01").Delete
On Error GoTo 0
'SelectionSetSet SsetObj = ThisDrawing.SelectionSets.Add("S01")
'
SsetObj.SelectByPolygon 6, P1
'
For Each obj In SsetObj
MsgBox "[" & SsetObj.Name & "]" & " SelectionSet " & vbCrLf & _
"[" & obj.ObjectName & "]" & " ."C a = C a + 1
Next obj
MsgBox " " & Ca & " "
End Sub
Code 30 : SelectByPolygon
SelectByPolygon .
. SsetObj.SelectByPolygon [ : 6], [Point List : P1]
[SelectbyPolygon] Point List Polygon .
.
< 14> .
Sub Ex_SelectOnScreen()
'
Dim SsetObj As AcadSelectionSet 'SelectionSet
Dim Ca As Integer '
-
7/27/2019 Vba for Autocad by Na!
47/83
Dim obj As Variant '
Ca = 0 'Counter
' Error
On Error Resume Next
If ThisDrawing.SelectionSets.Item("S01") Then ThisDrawing.SelectionSets.Item("S01").Delete
On Error GoTo 0
'SelectionSet
Set SsetObj = ThisDrawing.SelectionSets.Add("S01")
'
SsetObj.SelectOnScreen
'
For Each obj In SsetObj
MsgBox "[" & SsetObj.Name & "]" & " SelectionSet " & vbCrLf & _
"[" & obj.ObjectName & "]" & " ."
C a = C a + 1
Next obj
MsgBox " " & Ca & " "
End Sub
Code 31 : SelectOnScreen
[SelectOnScreen] .
. SsetObj.SelectOnScreen
[SelectOnScreen] .
Enter .
3. Copy / Move / Mirror / Rotate .... , , .
[SelectionSet] [Select] .. ..
Sub Ex_Edit()
'
Dim Sset As AcadSelectionSet 'SelectionSet
Dim Obj As Variant '
Dim Po01(0 To 2) As Double 'Move Mirror Point 1
-
7/27/2019 Vba for Autocad by Na!
48/83
Dim Po02(0 To 2) As Double 'Move Mirror Point 2
Dim R_Ag As Double 'Rotate
Dim I_No As Integer ' Id
' Error
On Error Resume Next
If ThisDrawing.SelectionSets.Item("S01") Then ThisDrawing.SelectionSets.Item("S01").Delete
On Error GoTo 0
'SelectionSet
Set Sset = ThisDrawing.SelectionSets.Add("S01")
Sset.SelectOnScreen
' Po01(0) = 0: Po01(1) = 0: Po01(2) = 0 'Move Mirror Point 1
Po02(0) = 100: Po02(1) = 0: Po02(2) = 0 'Move Mirror Point 2
R_Ag = 0.7853981 'Rotate (45 Radian )
'
For Each Obj In Sset
'
Obj.CopyThisDrawing.Application.Update 'CAD
MsgBox "[" & Obj.ObjectName & "]" & " Copy ."
'
Obj.Move Po01, Po02
ThisDrawing.Application.Update
MsgBox "[" & Obj.ObjectName & "]" & " Move ."
'
Obj.Mirror Po01, Po02
ThisDrawing.Application.Update
MsgBox "[" & Obj.ObjectName & "]" & " Mirror ."
'
Obj.Rotate Po02, R_Ag
ThisDrawing.Application.Update
MsgBox "[" & Obj.ObjectName & "]" & " Rotate ."
Next Obj
-
7/27/2019 Vba for Autocad by Na!
49/83
'
I_No = ThisDrawing.ModelSpace.Count
ThisDrawing.ModelSpace.Item(I_No - 1).Color = acRed
ThisDrawing.Application.Update
MsgBox " " & vbCrLf & _
" ."
ThisDrawing.ModelSpace.Item(0).Color = acGreen
ThisDrawing.Application.Update
MsgBox " " & vbCrLf & _
" ."
End SubCode 32 : Ex_Edit
.
Code [Select] ..
Code . ..
. Obj.Copy
.
VBA [Copy] . [Move] .
. Obj.Move [ : Po01], [ : Po02]
.
[ : Po01] [ : Po02] .
. Obj.Mirror[ 1 : Po01], [ : Po02]
.
.
Code .
. Obj.Rotate [ : Po02], [ : R_Ag]
[ : Po02] [ : R_Ag] .
. ThisDrawing.Application.Update
Program .
Code .
Code . RE
. Code . [~.Count], [~.Color]..
-
7/27/2019 Vba for Autocad by Na!
50/83
4. ropertyMODULE II CAD Property . CAD Property .
Sub Ex_Edit_Property()
'
Dim Sset As AcadSelectionSet
Dim Obj As AcadLine
Dim P01(0 To 2) As Double
Dim Cnt As Integer
'
P01(0) = 0: P01(1) = 0: P01(2) = 0
Cnt = 0
' Error
On Error Resume Next
If ThisDrawing.SelectionSets("S01") Then ThisDrawing.SelectionSets("S01").Delete
On Error GoTo 0
'SelectionSet
Set Sset = ThisDrawing.SelectionSets.Add("S01")
Sset.SelectOnScreen
' Property
For Each Obj In Sset
Obj.StartPoint = P01
ThisDrawing.Application.Update
Cnt = Cnt + 1
Next Obj
MsgBox Cnt & " ."
End Sub
Code 33 : Line Property
[Line] .
. Obj.StartPoint = [Property : P01]
Line [StrtPoint] Code .
[Obj] [AcadLine] VBA
. [AcadLine] Property [StartPoint] Property
[Error] .
-
7/27/2019 Vba for Autocad by Na!
51/83
5. Select Filter Code
[Error] . [Error]
Select Filter .
[Select] . ..
Sub Ex_Select_Filter()
'
Dim Sset As AcadSelectionSet
Dim DG_code(0) As Integer 'DXF Group Code
Dim DG_Data(0) As Variant 'DXF Group Code
Dim Cnt As Integer
' ErrorOn Error Resume Next
If ThisDrawing.SelectionSets("S01") Then ThisDrawing.SelectionSets("S01").Delete
On Error GoTo 0
'Filter
DG_code(0) = 0
DG_Data(0) = "Line"
'SelectionSetSet Sset = ThisDrawing.SelectionSets.Add("S01")
Sset.SelectOnScreen DG_code, DG_Data
'
Cnt = Sset.Count
'
Sset.Erase
ThisDrawing.Application.Update
MsgBox Cnt & " " & DG_Data(0) & " ."
End Sub
Code 34 : Select Filter
DXF Group Code .
DXF(Drawing Exchange Format) Code
. Select Filer .
.. .. .
-
7/27/2019 Vba for Autocad by Na!
52/83
. Dim DG_code(0) As Integer : Dim DG_Data(0) As Variant
Code Filter DXF Group Code .
DXF Group Code .
. DG_code(0) = 0 : DG_Data(0) = "Line"
DXF Group Code Code .
0 "Line" .
DXF Croup Code < 15> .
DXF Group Code -4
0
8 Layer
40 (Circle) (Arc) / Text /PolyLine
62
15 : DXF Group Code
. Sset.Erase
.
[Erase] [Copy] [Move] [SelectionSet] .
. [For Each ~ Next]
. Sset.SelectOnScreen [Filter : DG_code], [ : DG_Data] [SelectOnScreen] Filter .
.
[DG_Code(0) = 0] Line [DG_Data="Line"] .
.
Filter .
3 Select Filter .
Sub Multi_Select_Filter()
'
Dim Sset As AcadSelectionSet
Dim DG_Code(4) As Integer
Dim DG_Data(4) As Variant
Dim Cnt As Integer
' Error
On Error Resume Next
If ThisDrawing.SelectionSets("S01") Then ThisDrawing.SelectionSets("S01").Delete
On Error GoTo 0
-
7/27/2019 Vba for Autocad by Na!
53/83
'Filter
DG_Code(0) = -4: DG_Data(0) = "" 'And
'SelectionSet
Set Sset = ThisDrawing.SelectionSets.Add("S01")
Sset.SelectOnScreen DG_Code, DG_Data
Cnt = Sset.Count
MsgBox " " & Cnt & " "
End Sub
Code 35 : Multi - Select Filter
Text 20 .
. DG_Code(0) = -4: DG_Data(0) = ""
Filter DXF Group Code (-4) Filter .
. DXF Group Code .. .
DXF Group Code Filter . DXF Group Code .
/ Filter .
Sub If_Multi_Select_Filter()
'
Dim Sset As AcadSelectionSet
Dim DG_Code(4) As Integer
Dim DG_Data(4) As Variant
Dim Obj As AcadText
Dim Cnt As Integer
' Error
On Error Resume Next
If ThisDrawing.SelectionSets("S01") Then ThisDrawing.SelectionSets("S01").Delete
On Error GoTo 0
'Filter
DG_Code(0) = -4: DG_Data(0) = "
-
7/27/2019 Vba for Autocad by Na!
54/83
DG_Code(3) = 62: DG_Data(3) = 1 ' Filter => RED
DG_Code(4) = -4: DG_Data(4) = "and>" 'And
Cnt = 0
'SelectionSet
Set Sset = ThisDrawing.SelectionSets.Add("S01")
Sset.SelectOnScreen DG_Code, DG_Data
' , Filter
For Each Obj In Sset
If Obj.TextString = "VBA" Then
Obj.Height = 40 : Obj.Color = acMagenta
Cnt = Cnt + 1Else
End If
Next Obj
MsgBox " " & Cnt & " "
End Sub
Code 36 : / Select Filter
DXF Group Code Filter [SelectionSet] [For Each -
Next] [TextString] .
Code ..
. If Obj.TextString = "VBA" Then ~ End If
Property( ) Property( )
Code Cad Property .
..
..
-
7/27/2019 Vba for Autocad by Na!
55/83
FORM: User Interface - UserForm1.~
MODULE I ~ VI VBA Code . FORM Module Interface . Form Code .
MODULE
. .
1. Design Mode Form VBA Design Mode .
Design Mode [ ( I ) >> ( U )]
Design Mode Icon( ) . < > VBA Deisgn Mode .
13 : VBA Design Mode
Design Mode .
. - UserForm1 : Design Mode [Form]
Control User Interface .
. - Control : [Form] .
.
. - : .
-
7/27/2019 Vba for Autocad by Na!
56/83
2. Control [Form] Control VBA 15
< 16> .
ICON ontrol Select Object [Form] . Label [Fom] . TextBox . ComboBox .ListBox .CheckBox . OptionButton . ToggleButton On/Off .Frame . CommendButten . TabStrip .MutiPage [TabStrip] .ScrollBar [ScrollBar] .SpinButten [ScrolBar] .ImageBox [Form] Image .
16 : Control
3. ontrol Control .
< 13> - .
Control
.
.
. : .
Code .
. TabIndex : Control Tab .
Tab . .
. Value :[CheckBox] [OptionButton] True False .
.. .. ....
-
7/27/2019 Vba for Autocad by Na!
57/83
4. Label / TextBox /CommendButton [Label], [TextBox] [CommendButton] [Form] Program .
Form < 14> .
14 : Ex_TextBox Form
[Form] , [Label], [CommandButton] Caption . [Form] Select Object( ) .
< 14> [Form] Program .
[Module] Code
Sub Ex_TextBox()
'
Dim TBox01 As String 'TextBox1
Dim Tbox02 As Double 'TextBox2
Dim Tb02X As Double 'TextBox2
'Form .
UserForm1.Show
'Form
TBox01 = UserForm1.TextBox1
Tbox02 = UserForm1.TextBox2
'Form
Tb02X = Tbox02 * 2
'
MsgBox TBox01 & " " & vbCrLf & _
Tbox02 & " 2 " & vbCrLf & _
Tb02X & " ."
End Sub
-
7/27/2019 Vba for Autocad by Na!
58/83
[Form - CommendButton1] Code
Private Sub CommandButton1_Click()
'Form .
Me.Hide
End Sub [Form - CommendButton2] Code
Private Sub CommandButton2_Click()
'Program ..
End
End Sub
Code 37 : Ex_TextBox
[Model] [Form] .
[Form] Control Double-Click
.
. .
. UserForm1.Show
Design Mode [UserForm1] .
[Form] [Module] .
[Form] [UserForm1] Code
. Design Mode [Form] .. .
. Private Sub CommandButton1_Click() ~ End Sub
[CommandButton1] Click Code .
Desing Mode [CommandButton1] Double-Click .
. [CommandButton1] - Me.Hide
[Form] Code .
. [CommandButton2] - End
.
. TBox01 = UserForm1.TextBox1 : Tbox02 = UserForm1.TextBox2
[Form] [TextBox] .
[TextBox] [UserForm1.TextBox1] . .. .
.
[TextBox1] [String] [TextBox2] [Double] ..
. < 15> .
15 : Ex_TextBox
-
7/27/2019 Vba for Autocad by Na!
59/83
5. CheckBox / OptionButton / Frame [CheckBox] [OptionButton] [True / False] .
[CheckBox] [OptionButton] [Form] [Frame]
. < 16> [CheckBox] [OptionButton] [Form] .
16 Ex_Check & Option
.
[Form]
[OptionButton1 : ] [Value] [True] .
[OptionButton2 : ] [OptionButton1 : ] .
< 16> [Form] Program .
[Module] Code
Sub Ex_Check_Option()
'
Dim Sex As String
Dim Pro As String
'From
UserForm1.Show
'OptionButton
If UserForm1.OptionButton1 = True Then Sex = " "
If UserForm1.OptionButton2 = True Then Sex = " "
'CheckBox
If UserForm1.CheckBox1 = True Then Pro = Pro + "AutoCAD, " & vbCrLf
If UserForm1.CheckBox2 = True Then Pro = Pro + "VBA, " & vbCrLf
If UserForm1.CheckBox3 = True Then _
Pro = Pro + UserForm1.CheckBox3.Caption & ", " & vbCrLf
If UserForm1.CheckBox4 = True Then _
Pro = Pro + UserForm1.CheckBox4.Caption & ", " & vbCrLf
-
7/27/2019 Vba for Autocad by Na!
60/83
'
MsgBox " " & Sex & " " & vbCrLf & _
Pro & " ." & vbCrLf & _
" ."
End Sub
[Form - CommendButton1] Code
Private Sub CommandButton1_Click()
'Form .
Me.Hide
End Sub
[Form - CommendButton2] Code
Private Sub CommandButton2_Click()
'Program .End
End Sub
Code 38 : Ex_Check & Option
[CheckBox] [OptionButten] .
.
. If UserForm1.OptionButton1 = True Then Sex = " "
[OptionButton1] [Sex] " .
[OptionButton] [CheckBox] .
. If UserForm1.CheckBox3 = True Then _
Pro = Pro + UserForm1.CheckBox3.Caption & ", " & vbCrLf
Code . .
[CheckBox]
[Caption] .
[CheckBox1 /2] [CheckBox3 /4] .
.
. [OptuonButton] .
Ex_Check & Option [OptionButton]
. Frame . < 17> Frame .
17 : Ex_Frame
-
7/27/2019 Vba for Autocad by Na!
61/83
[Frame] . < 17> [OptionButton]
[OptionButton] .
[OptionButton] ..
[Module] Code
Sub Ex_Frame()
'Form
UserForm1.Show
End Sub
[Form - CommendButton1] Code
Private Sub CommandButton1_Click()
'Program .
End
End SubCode 39 : Ex_Frame
Ex_Frame [OptionButton] [Frame] [Module]
. [Modeule] DVB
AutoCAD Lord VBA . - < 3>
.. [Sub ~ End Sub] .
.
-
7/27/2019 Vba for Autocad by Na!
62/83
PROGRAM I : Program - Photo Numbering
isual Basic for Application VBA ORM: User Interface - UserForm1.~
Program . Na!
Program . .
1. rogram Program ,
CAD .
Na! VBA .
. Programing .
[PROGRAM] -Photo Numbering-
.
< 18> .
18 : Programing -
< 18> Index ,
.
.
Index
.. 10 ..
. 50 ...
-
7/27/2019 Vba for Autocad by Na!
63/83
2. Program .
.
Code .
< 19> Photo Numbering .
19 : Photo Number
< 19> . .
Codeing
. Code ..
..
3. program
. .
Program ..
< 20> Photo Number .
20 : Photo Number
-
7/27/2019 Vba for Autocad by Na!
64/83
< 20> 2 .
[GetPoint] Point .
Circle
Text
[GetPont] Point
.
< 21> [GePoint] Point .
21
< 21> C_R Circle ,
dH dV ,
Coding
.
code .
Sub Photo_Number()
'
'
Dim Bbp(0 To 2) As Double
'Text
Dim P_No As AcadText: Dim No_S As String: Dim No_H As Double
'Circle
Dim P_C As AcadCircle: Dim C_R As Double
'
Dim P_PL As AcadLWPolyline
Dim dH As Double '
Dim dV As Double '
Dim PL_P(0 To 7) As Double 'PolyLine
'
Bbp(0) = 0: Bbp(1) = 0: Bbp(2) = 0
-
7/27/2019 Vba for Autocad by Na!
65/83
'Text ==> 'Form
No_S = 15
No_H = 1
'Circle
C_R = 0.935
'
dV = 1.2: dH = 1.5
PL_P(0) = Bbp(0): PL_P(1) = Bbp(1)
PL_P(2) = PL_P(0): PL_P(3) = PL_P(1) + dV
PL_P(4) = PL_P(0) + dH: PL_P(5) = PL_P(1)
PL_P(6) = PL_P(0): PL_P(7) = PL_P(1) - dV
'
Set P_PL = ThisDrawing.ModelSpace.AddLightWeightPolyline(PL_P)
P_PL.Closed = True
'
Set P_C = ThisDrawing.ModelSpace.AddCircle(Bbp, C_R)
'TextSet P_No = ThisDrawing.ModelSpace.AddText(No_S, Bbp, No_H)
P_No.Alignment = acAlignmentMiddleCenter
P_No.TextAlignmentPoint = Bbp
End Sub
Code 40 : Photo Numbering
[MODULE II - CAD ] .
[Bbp] .
[Form] [Get~] Program Code
Code .
Na! .. .. [ ] ..
< 22> .
22 Photo Numbering
-
7/27/2019 Vba for Autocad by Na!
66/83
4. 3.
.
[Layer] [Hatch] .
[Block] .
.
..
Sub Photo_Number()
'
'
Dim Bbp(0 To 2) As Double
'Text
Dim P_No As AcadText
Dim No_S As String
Dim No_H As Double
================ ===================
'
dV = 1.2dH = 1.5
PL_P(0) = Bbp(0): PL_P(1) = Bbp(1)
PL_P(2) = PL_P(0): PL_P(3) = PL_P(1) + dV
PL_P(4) = PL_P(0) + dH: PL_P(5) = PL_P(1)
PL_P(6) = PL_P(0): PL_P(7) = PL_P(1) - dV
' (Circle+Text) LayerDim Pno_Lay01 As AcadLayer
Dim L_Name01 As String
L_Name01 = "PNo_Layer01"
On Error Resume Next
Set Pno_Lay01 = ThisDrawing.Layers(L_Name01)
On Error GoTo 0
If Pno_Lay01 Is Nothing Then
Set Pno_Lay01 = ThisDrawing.Layers.Add(L_Name01)
Else
End If
-
7/27/2019 Vba for Autocad by Na!
67/83
' LayerDim Pno_Lay02 As AcadLayer
Dim L_Name02 As String
L_Name02 = "PNo_Layer02"
On Error Resume Next
Set Pno_Lay02 = ThisDrawing.Layers(L_Name02)
On Error GoTo 0
If Pno_Lay02 Is Nothing Then
Set Pno_Lay02 = ThisDrawing.Layers.Add(L_Name02)
Else
End If
'
'LayerThisDrawing.ActiveLayer = ThisDrawing.Layers(L_Name02)
' BlockDim B_PNo02 As AcadBlock
Dim Name_B02 As String
Name_B02 = "B_Pno02"On Error Resume Next
Set B_PNo02 = ThisDrawing.Blocks(Name_B02)
On Error GoTo 0
If B_PNo02 Is Nothing Then
Set B_PNo02 = ThisDrawing.Blocks.Add(Bbp, Name_B02)
Set P_PL = B_PNo02.AddLightWeightPolyline(PL_P)
P_PL.Closed = True
'HatchDim H_obj02 As AcadHatch
Dim H_Name02 As String
Dim H_Type02 As Long
Dim H_ass02 As Boolean
Dim H_OL02(0 To 0) As AcadEntity
H_Name02 = "solid"
H_Type02 = 1
-
7/27/2019 Vba for Autocad by Na!
68/83
H_ass02 = True
Set H_OL02(0) = P_PL
Set H_obj02 = B_PNo02.AddHatch(H_Type02, H_Name02, H_ass02)
H_obj02.AppendOuterLoop (H_OL02)
H_obj02.Evaluate
H_obj02.Color = acRed
Else
End If
'
'LayerThisDrawing.ActiveLayer = ThisDrawing.Layers(L_Name01)
' BlockDim B_PNo01 As AcadBlock
Dim Name_B01 As String
Name_B01 = "B_Pno01"
On Error Resume Next
Set B_PNo01 = ThisDrawing.Blocks(Name_B01)
On Error GoTo 0If B_PNo01 Is Nothing Then
Set B_PNo01 = ThisDrawing.Blocks.Add(Bbp, Name_B01)
Set P_C = B_PNo01.AddCircle(Bbp, C_R)
'HatchDim H_obj01 As AcadHatch
Dim H_Name01 As String
Dim H_Type01 As Long
Dim H_ass01 As Boolean
Dim H_OL01(0 To 0) As AcadEntity
H_Name01 = "solid"
H_Type01 = 1
H_ass01 = True
Set H_OL01(0) = P_C
Set H_obj01 = B_PNo01.AddHatch(H_Type01, H_Name01, H_ass01)
H_obj01.AppendOuterLoop (H_OL01)
-
7/27/2019 Vba for Autocad by Na!
69/83
H_obj01.Evaluate
H_obj01.Color = acCyan
Else
End If
'Dim ip(0 To 2) As Double
ip(0) = 100: ip(1) = 100: ip(2) = 0 'GetPoint
'Dim Ag As Double
Ag = 0.785398163 'GetAngle
'ThisDrawing.ActiveLayer = ThisDrawing.Layers(L_Name02)
Dim IB_Pno02 As AcadObject
Set IB_Pno02 = ThisDrawing.ModelSpace.InsertBlock(ip, Name_B02, No_H, No_H, No_H, Ag)
'ThisDrawing.ActiveLayer = ThisDrawing.Layers(L_Name01)
Dim IB_Pno01 As AcadObject
Set IB_Pno01 = ThisDrawing.ModelSpace.InsertBlock(ip, Name_B01, No_H, No_H, No_H, 0)
'Text
Set P_No = ThisDrawing.ModelSpace.AddText(No_S, ip, No_H)
P_No.Alignment = acAlignmentMiddleCenter
P_No.TextAlignmentPoint = ip
End Sub
Code 41 :
[Layer] [Hatch] .
[MODULE II] Code .
Code .
[No_H] [IsertBlock] Scale .
Program [Layer]
. < 23> .
23 Photo Numbering
-
7/27/2019 Vba for Autocad by Na!
70/83
5. MODULE III .
.
. [Get~] .
.
Sub Photo_Number()
'
'
Dim Bbp(0 To 2) As Double
================ ===================
'Dim ip As ACAD_POINT
ip = ThisDrawing.Utility.GetPoint(, vbCrLf & " ? : ")
'Dim Ag As Double
Ag = ThisDrawing.Utility.GetAngle(ip, vbCrLf & " : ")
'ThisDrawing.ActiveLayer = ThisDrawing.Layers(L_Name02)
Dim IB_Pno02 As AcadObject
Set IB_Pno02 = ThisDrawing.ModelSpace.InsertBlock(ip, Name_B02, No_H, No_H, No_H, Ag)
'
ThisDrawing.ActiveLayer = ThisDrawing.Layers(L_Name01)
Dim IB_Pno01 As AcadObject
Set IB_Pno01 = ThisDrawing.ModelSpace.InsertBlock(ip, Name_B01, No_H, No_H, No_H, 0)
'Text
Set P_No = ThisDrawing.ModelSpace.AddText(No_S, ip, No_H)
P_No.Alignment = acAlignmentMiddleCenter
P_No.TextAlignmentPoint = ip
End Sub
Code 42 :
.
-
7/27/2019 Vba for Autocad by Na!
71/83
6. Photo Numbering Program .
3, 4, 5 5
.
Counter
.
.
.
Sub Photo_Number()
'
'
Dim Bbp(0 To 2) As Double
================ ===================
'Do
Dim ip As ACAD_POINT
'On Error Resume Next
ip = ThisDrawing.Utility.GetPoint(, vbCrLf & " ? : ")
'ipIf ip(0) = Empty Then
Exit Do
Else
'
Dim Ag As Double
Ag = ThisDrawing.Utility.GetAngle(ip, vbCrLf & " : ")
================ ===================
'Text
Set P_No = ThisDrawing.ModelSpace.AddText(No_S, ip, No_H)
P_No.Alignment = acAlignmentMiddleCenter
P_No.TextAlignmentPoint = ip
-
7/27/2019 Vba for Autocad by Na!
72/83
'No_S = No_S + 1
'ip = Empty
End If
Loop
End Sub
Code 43 :
MODULE IVMODULE V . Counter .
Code .
.
Code .
7. orm Program .
[No_S] [No_H] Form
Program .
5. .
< 24> 2 [TextBox] [CommandButton] Photo Numbering Form
.
24 : Photo Numbering Form
Form Photo Numbering Code .
[Module] Code
Sub Photo_Number()
'
'
-
7/27/2019 Vba for Autocad by Na!
73/83
Dim Bbp(0 To 2) As Double
'Text
Dim P_No As AcadText
Dim No_S As String
Dim No_H As Double
'Circle
Dim P_C As AcadCircle
Dim C_R As Double
'
Dim P_PL As AcadLWPolyline
Dim dH As Double ' Dim dV As Double '
Dim PL_P(0 To 7) As Double 'PolyLine
'FormUserForm1.Show
'
Bbp(0) = 0: Bbp(1) = 0: Bbp(2) = 0
'Text
No_S = UserForm1.TextBox1
No_H = UserForm1.TextBox2
'Circle
C_R = 0.935
'
dV = 1.2
dH = 1.5
PL_P(0) = Bbp(0): PL_P(1) = Bbp(1)
PL_P(2) = PL_P(0): PL_P(3) = PL_P(1) + dV
PL_P(4) = PL_P(0) + dH: PL_P(5) = PL_P(1)
PL_P(6) = PL_P(0): PL_P(7) = PL_P(1) - dV
' (Circle+Text) Layer
Dim Pno_Lay01 As AcadLayer
Dim L_Name01 As String
L_Name01 = "PNo_Layer01"
-
7/27/2019 Vba for Autocad by Na!
74/83
On Error Resume Next
Set Pno_Lay01 = ThisDrawing.Layers(L_Name01)
On Error GoTo 0
If Pno_Lay01 Is Nothing Then
Set Pno_Lay01 = ThisDrawing.Layers.Add(L_Name01)
Else
End If
' Layer
Dim Pno_Lay02 As AcadLayer
Dim L_Name02 As String
L_Name02 = "PNo_Layer02"
On Error Resume Next
Set Pno_Lay02 = ThisDrawing.Layers(L_Name02)
On Error GoTo 0
If Pno_Lay02 Is Nothing Then
Set Pno_Lay02 = ThisDrawing.Layers.Add(L_Name02)
Else
End If
'
'Layer
ThisDrawing.ActiveLayer = ThisDrawing.Layers(L_Name02)
' Block
Dim B_PNo02 As AcadBlock
Dim Name_B02 As String
Name_B02 = "B_Pno02"
On Error Resume Next
Set B_PNo02 = ThisDrawing.Blocks(Name_B02)
On Error GoTo 0
If B_PNo02 Is Nothing Then
Set B_PNo02 = ThisDrawing.Blocks.Add(Bbp, Name_B02)
Set P_PL = B_PNo02.AddLightWeightPolyline(PL_P)
-
7/27/2019 Vba for Autocad by Na!
75/83
P_PL.Closed = True
'Hatch
Dim H_obj02 As AcadHatch
Dim H_Name02 As String
Dim H_Type02 As Long
Dim H_ass02 As Boolean
Dim H_OL02(0 To 0) As AcadEntity
H_Name02 = "solid"
H_Type02 = 1
H_ass02 = True
Set H_OL02(0) = P_PL
Set H_obj02 = B_PNo02.AddHatch(H_Type02, H_Name02, H_ass02)
H_obj02.AppendOuterLoop (H_OL02)
H_obj02.Evaluate
H_obj02.Color = acRed
Else
End If
'
'Layer
ThisDrawing.ActiveLayer = ThisDrawing.Layers(L_Name01)
' Block
Dim B_PNo01 As AcadBlock
Dim Name_B01 As String
Name_B01 = "B_Pno01"
On Error Resume Next
Set B_PNo01 = ThisDrawing.Blocks(Name_B01)
On Error GoTo 0
If B_PNo01 Is Nothing Then
Set B_PNo01 = ThisDrawing.Blocks.Add(Bbp, Name_B01)
Set P_C = B_PNo01.AddCircle(Bbp, C_R)
'Hatch
Dim H_obj01 As AcadHatch
-
7/27/2019 Vba for Autocad by Na!
76/83
Dim H_Name01 As String
Dim H_Type01 As Long
Dim H_ass01 As Boolean
Dim H_OL01(0 To 0) As AcadEntity
H_Name01 = "solid"
H_Type01 = 1
H_ass01 = True
Set H_OL01(0) = P_C
Set H_obj01 = B_PNo01.AddHatch(H_Type01, H_Name01, H_ass01)
H_obj01.AppendOuterLoop (H_OL01)
H_obj01.Evaluate
H_obj01.Color = acCyanElse
End If
'
Do
Dim ip As ACAD_POINT
'
On Error Resume Next ip = ThisDrawing.Utility.GetPoint(, vbCrLf & " ? : ")
'ip
If ip(0) = Empty Then
Exit Do
Else
'
Dim Ag As Double
Ag = ThisDrawing.Utility.GetAngle(ip, vbCrLf & " : ")
'
ThisDrawing.ActiveLayer = ThisDrawing.Layers(L_Name02)
Dim IB_Pno02 As AcadObject
Set IB_Pno02 = ThisDrawing.ModelSpace.InsertBlock(ip, Name_B02, No_H, No_H, No_H, Ag)
'
ThisDrawing.ActiveLayer = ThisDrawing.Layers(L_Name01)
Dim IB_Pno01 As AcadObject
-
7/27/2019 Vba for Autocad by Na!
77/83
Set IB_Pno01 = ThisDrawing.ModelSpace.InsertBlock(ip, Name_B01, No_H, No_H, No_H, 0)
'Text
Set P_No = ThisDrawing.ModelSpace.AddText(No_S, ip, No_H)
P_No.Alignment = acAlignmentMiddleCenter
P_No.TextAlignmentPoint = ip
'
No_S = No_S + 1
'
ip = Empty
End If
Loop
End Sub
[Form - CommendButton1] Code
Private Sub CommandButton1_Click()
'Form .Me.Hide
End Sub [Form - CommendButton2] Code
Private Sub CommandButton2_Click()
'Program .End
End Sub
Code 44 : Photo Numbering
Form FORM .
-
7/27/2019 Vba for Autocad by Na!
78/83
PROGRAM II : Excel - ToExcel
Visual Basic for Application (VBA) VBA AutoCAD
MS-OFFICE Data
. AutoCAD CAD
EXCEL . Data
.
AutoCAD Data Excel .
.
(T) >> (R) < 25> .
25 :
.
.. .. .
. Excel . .
< 26> To Excel Form .
26 : To Excel Form
To Excel Code .
-
7/27/2019 Vba for Autocad by Na!
79/83
[Module] Code
Sub ToExcel()
'
Dim SsObj As Object 'SelectionSet
Dim Obj As Object '
Dim TTe As String '
Dim i As Integer 'Excel
Dim j As Integer 'Excel
Dim k As Integer 'Excel
UserForm1.Show
On Error Resume NextDim Excelapp As Object
'Excel .
Set Excelapp = GetObject(, "Excel.Application")
'Excel Excel .
If Err Then
MsgBox "Excel ."
Err.Clear
'Excel
Dim Excel_Book As Object 'Excel WorkBook
Dim Excel_Sheet As Object 'Excel Sheet
Set Excelapp = CreateObject("excel.Application") 'Excel
Set Excel_Book = Excelapp.Workbooks.Add 'WorkBook
Set Excel_Sheet = Excel_Book.Worksheets.Item(1) ' Sheet
' Code Error
If Err Then
MsgBox "Excel . " & vbCrLf & _
"Excel . "
Exit Sub
End If
End If
'Excel
Excelapp.Visible = True
-
7/27/2019 Vba for Autocad by Na!
80/83
Dim ActiveWorkbook As Object
Set ActiveWorkbook = Excelapp.ActiveWorkbook
'
k = UserForm1.TextBox2.Text
'
i = UserForm1.TextBox1.Text
'SelectionSet Error
On Error Resume Next
If ThisDrawing.SelectionSets("Sset") Then ThisDrawing.SelectionSets("Sset").Delete
On Error GoTo 0
'Set SsObj = ThisDrawing.SelectionSets.Add("Sset")
Dim GpCode(0) As Integer
Dim DataValue(0) As Variant
GpCode(0) = 0
DataValue(0) = "text"
Dim Ftype As Variant, Fdata As Variant
Ftype = GpCodeFdata = DataValue
SsObj.SelectOnScreen Ftype, Fdata
' Cell
j = 1
'
For Each Obj In SsObj
'
TTe = Obj.TextString
' Cell
If j = (k + 1) Then
i = i + 1
j = 1
End If
'Excel
ActiveWorkbook.ActiveSheet.Cells(i, j).Value2 = TTe
-
7/27/2019 Vba for Autocad by Na!
81/83
' Cell
j = j + 1
Next Obj
End Sub
[Form - CommendButton1] Code
Private Sub CommandButton1_Click()
'Form .
Me.Hide
End Sub
[Form - CommendButton2] Code
Private Sub CommandButton2_Click() 'Program .
End
End Sub
Code 45 : To Excel
Excel .
.
. .. Na! ..
-
7/27/2019 Vba for Autocad by Na!
82/83
RUN : DVB - Lisp
Lisp VBA DVB .
Lisp
.
Lisp DVB Lisp Lisp
.
DVB Lisp Code .
(defun c:toex()
(command "-vbarun" "ToEx.dvb!ToExcel")
(princ)
)
Code 46 : DVB Lisp Code
ToEx [Sub ToExcel() ~ End Sub] Procedure
DVB Lisp .
.
. (defun c:toex()
AutoCAD . [toex] .
. (command "-vbarun" "ToEx.dvb!ToExcel")
VBA .
ToEx.DVB [Sub ToExcel() ~ End Sub] Procedure .
Program Lisp
.
-
7/27/2019 Vba for Autocad by Na!
83/83
DESCRIPTION : -
.
..
..
Na! VBA ..
VBA [ http://www.vbcad.co.kr ]
Krst polt, AutoCAD .
Na! VBA .
AutoCAD VBA [ http://cafe.never.com/email72 ]
NEVER AutoCAD VBA Cafe
Dream .
.. ...
* 2006 [http://www.acadvba.com/ ] .
-
.
. .. .
Auto CAD AutoCAD ActiveX VBA
VB VBA .
..
.
..
Code CD ..
.
. ? .
Na! .. .
VBA ..
.
Na!