1 |
Imports SolidWorks.Interop
|
2 |
Imports SolidWorks.Interop.swconst
|
3 |
Imports SolidWorks.Interop.swpublished
|
4 |
|
5 |
Namespace MAGIC
|
6 |
|
7 |
'Base class for model event handlers
|
8 |
Public Class DocumentEventHandler
|
9 |
Protected userAddin As MAGIC
|
10 |
Protected iDocument As sldworks.ModelDoc2
|
11 |
Protected iSwApp As SldWorks.SldWorks
|
12 |
|
13 |
Overridable Function Init(ByVal sw As sldworks.SldWorks, ByVal addin As Magic, ByVal model As sldworks.ModelDoc2) As Boolean
|
14 |
End Function
|
15 |
|
16 |
Overridable Function AttachEventHandlers() As Boolean
|
17 |
End Function
|
18 |
|
19 |
Overridable Function DetachEventHandlers() As Boolean
|
20 |
End Function
|
21 |
End Class
|
22 |
|
23 |
'Class to listen for Part Events
|
24 |
Public Class PartEventHandler
|
25 |
Inherits DocumentEventHandler
|
26 |
|
27 |
Dim WithEvents iPart As sldworks.PartDoc
|
28 |
|
29 |
Overrides Function Init(ByVal sw As sldworks.SldWorks, ByVal addin As Magic, ByVal model As sldworks.ModelDoc2) As Boolean
|
30 |
userAddin = addin
|
31 |
iPart = model
|
32 |
iDocument = iPart
|
33 |
iSwApp = sw
|
34 |
End Function
|
35 |
|
36 |
Overrides Function AttachEventHandlers() As Boolean
|
37 |
AddHandler iPart.DestroyNotify, AddressOf Me.PartDoc_DestroyNotify
|
38 |
AddHandler iPart.NewSelectionNotify, AddressOf Me.PartDoc_NewSelectionNotify
|
39 |
End Function
|
40 |
|
41 |
Overrides Function DetachEventHandlers() As Boolean
|
42 |
RemoveHandler iPart.DestroyNotify, AddressOf Me.PartDoc_DestroyNotify
|
43 |
RemoveHandler iPart.NewSelectionNotify, AddressOf Me.PartDoc_NewSelectionNotify
|
44 |
|
45 |
userAddin.DetachModelEventHandler(iDocument)
|
46 |
End Function
|
47 |
|
48 |
Function PartDoc_DestroyNotify() As Integer
|
49 |
DetachEventHandlers()
|
50 |
End Function
|
51 |
|
52 |
Function PartDoc_NewSelectionNotify() As Integer
|
53 |
' quand on sélectionne quelquechose (ou désélectionne) cette fonction est appelée.
|
54 |
' ne fonctionne pas si on sélectionne ou désélectionne par code
|
55 |
End Function
|
56 |
End Class
|
57 |
End Namespace |