-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCAMWorks.vb
156 lines (98 loc) · 5.65 KB
/
CAMWorks.vb
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
' Import main DriveWorks Extensibility types
Imports DriveWorks.Extensibility
' Other useful extensibility imports in DriveWorks.Applications.dll (this has been added as a reference for you)
Imports DriveWorks.Applications
Imports DriveWorks.Applications.Administrator.Extensibility
Imports DriveWorks.Applications.Autopilot.Extensibility
' Other useful extensibility imports (you will need to add a reference to use these)
Imports DriveWorks.SolidWorks ' In DriveWorks.SolidWorks.dll
Imports DriveWorks.Applications.Extensibility
Imports DriveWorks.SolidWorks.Generation
<ApplicationPlugin("DriveWorks.CAMWorks", "DriveWorks CAMWorks Plugin", "DriveWorks CAMWorks")> _
Public Class CAMWorks
Implements IApplicationPlugin
Implements IHasConfiguration
Private mApplication As IApplication
Private mSettings As PluginSettings
Private WithEvents mGenerationService As IGenerationService
Private WithEvents mSolidWorksService As ISolidWorksService
Private mGroupService As IGroupService
Private mGroupSettings As Generation.GenerationSettings
Private Const EVENT_SOURCE_NAME As String = "urn://DriveWorks/Labs/CAMWorks"
Private mEventLog As IApplicationEventService
Private mModelList As New List(Of String)
Public Sub Initialize(application As DriveWorks.Applications.IApplication) Implements DriveWorks.Applications.Extensibility.IApplicationPlugin.Initialize
mApplication = application
mSettings = New PluginSettings(application.SettingsManager)
' this plugin requires 2 of the DriveWorks services
mSolidWorksService = application.ServiceManager.GetService(Of ISolidWorksService)()
mGenerationService = application.ServiceManager.GetService(Of IGenerationService)()
' Get the logging service
mEventLog = application.ServiceManager.GetService(Of IApplicationEventService)()
' Load settings
LoadSettings()
End Sub
Public Sub ShowConfiguration(owner As System.Windows.Forms.IWin32Window) Implements DriveWorks.Applications.Extensibility.IHasConfiguration.ShowConfiguration
Dim configForm As New ConfigureCAMWorks(mModelList)
If configForm.ShowDialog() = Windows.Forms.DialogResult.OK Then
mModelList = configForm.Models
SaveSettings()
End If
End Sub
#Region " Settings "
Private Sub LoadSettings()
Dim loadString As String = mSettings.GetSetting("ModelList", "")
If loadString.Trim.Equals(String.Empty) Then Exit Sub
Dim modelAdday As String() = loadString.Split("|")
For Each model In modelAdday
mModelList.Add(model)
Next
End Sub
Private Sub SaveSettings()
Dim saveString As String = String.Empty
For Each Model In mModelList
If saveString = String.Empty Then
saveString = Model
Else
saveString = saveString & "|" & Model
End If
Next
mSettings.SaveSetting("ModelList", saveString)
End Sub
#End Region
Private Sub mGenerationService_BatchStarted(sender As Object, e As EventArgs) Handles mGenerationService.BatchStarted
' at the point of starting batch, we MUST have a group open, so this is a good time to get the group service
' We need the group service so that we can ultimatelly find the Group Content Folder to know where the macros folder is.
mGroupService = mApplication.ServiceManager.GetService(Of IGroupService)()
Dim settingsManager As ISettingsManager = mApplication.SettingsManager
mGroupSettings = New GenerationSettings
mGroupSettings.Load(mGroupService.ActiveGroup, settingsManager)
End Sub
Private Sub mGenerationService_ModelGenerationContextCreated(sender As Object, e As DriveWorks.SolidWorks.Generation.ModelGenerationContextEventArgs) Handles mGenerationService.ModelGenerationContextCreated
Try
For Each modelActionName As String In mModelList
Dim modelName As String = System.IO.Path.GetFileNameWithoutExtension(e.Context.Model.MasterPath)
' Let the user know that we are loaded, and a model is being generated
AddEvent(ApplicationEventType.Information, String.Format("Testing for model name (Mapping = {0}, Model = {1})", modelActionName, modelName), True, modelActionName)
If modelName.Equals(modelActionName, StringComparison.OrdinalIgnoreCase) Then
' Let the user know that we are loaded, and a model is being generated
AddEvent(ApplicationEventType.Information, String.Format("Model Match found (Mapping Name = {0}) - CAM Data will be created after generation is complete.", modelActionName), True, modelActionName)
Dim modelGenerationContext As New CAMModelContext(e.Context, mSolidWorksService, mEventLog, EVENT_SOURCE_NAME, mGroupSettings)
Exit Sub
End If
Next
Catch ex As Exception
' Let the user know that there was a major problem
AddEvent(ApplicationEventType.Error, "Error creating CAMWorks Data.", True, ex.ToString)
End Try
End Sub
Private Sub AddEvent(ByVal type As DriveWorks.Applications.ApplicationEventType, ByVal description As String, ByVal loggingEnabled As Boolean, Optional ByVal targetName As String = Nothing)
If mEventLog Is Nothing Then
Return
End If
If Not loggingEnabled Then
Return
End If
mEventLog.AddEvent(type, EVENT_SOURCE_NAME, "Export CAMWorks Data", description, Nothing, targetName, Nothing)
End Sub
End Class