/
Chapter4.txt
67 lines (55 loc) · 1.94 KB
/
Chapter4.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Public WithEvents objApp As AcadApplication
Option Explicit
Public objApp As New clsApplicationEvents
Public Sub InitializeEvents()
Set objApp.objApp = ThisDrawing.Application
End Sub
Public Sub App_StartMacro()
InitializeEvents
End Sub
Private Sub objApp_SysVarChanged(ByVal SysvarName As String, _
ByVal newVal As Variant)
MsgBox "The System Variable: " & SysvarName & " has changed to " & newVal
End Sub
Private Sub objApp_NewDrawing()
ThisDrawing.SetVariable "SAVETIME", 30
MsgBox "The autosave interval is currently set to 30 mins"
End Sub
Option Explicit
Public objCurrentLayer As AcadLayer
Public objPreviousLayer As AcadLayer
Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
Set objPreviousLayer = ThisDrawing.ActiveLayer
Select Case CommandName
Case "LINE"
If Not ThisDrawing.ActiveLayer.Name = "OBJECTS" Then
Set objCurrentLayer = ThisDrawing.Layers.Add("OBJECTS")
ThisDrawing.ActiveLayer = objCurrentLayer
End If
End Select
End Sub
Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
Select Case CommandName
Case "LINE"
ThisDrawing.ActiveLayer = objPreviousLayer
End Select
Set objCurrentLayer = Nothing
Set objPreviousLayer = Nothing
End Sub
Public WithEvents objLine As AcadLine
Dim objLine As New clsObjectEvent
Public Sub InitializeEvent()
Dim dblStart(2) As Double
Dim dblEnd(2) As Double
dblEnd(0) = 1: dblEnd(1) = 1: dblEnd(2) = 0
Set objLine.objLine = ThisDrawing.ModelSpace.AddLine(dblStart, dblEnd)
End Sub
Private Sub objLine_Modified(ByVal pObject As AutoCAD.IAcadObject)
Dim varStartPoint As Variant
Dim varEndPoint As Variant
varStartPoint = pObject.StartPoint
varEndPoint = pObject.EndPoint
MsgBox "New line runs from (" & varStartPoint(0) & ", " & _
varStartPoint(1) & ", " & varStartPoint(2) & " ) to (" & _
varEndPoint(0) & ", " & varEndPoint(1) & ", " & varEndPoint(2) & ")."
End Sub