solidworks-mcp-server 2.0.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -0
- package/README.md +75 -8
- package/dist/db/connection.d.ts.map +1 -1
- package/dist/db/connection.js.map +1 -1
- package/dist/knowledge/chromadb.js +1 -1
- package/dist/knowledge/chromadb.js.map +1 -1
- package/dist/resources/design-table.d.ts +16 -16
- package/dist/resources/design-table.d.ts.map +1 -1
- package/dist/resources/design-table.js +2 -2
- package/dist/resources/design-table.js.map +1 -1
- package/dist/resources/pdm.d.ts +43 -43
- package/dist/resources/pdm.d.ts.map +1 -1
- package/dist/resources/pdm.js +8 -8
- package/dist/resources/pdm.js.map +1 -1
- package/dist/solidworks/api.d.ts +15 -14
- package/dist/solidworks/api.d.ts.map +1 -1
- package/dist/solidworks/api.js +343 -71
- package/dist/solidworks/api.js.map +1 -1
- package/dist/tools/analysis.d.ts +4 -4
- package/dist/tools/analysis.d.ts.map +1 -1
- package/dist/tools/analysis.js +10 -15
- package/dist/tools/analysis.js.map +1 -1
- package/dist/tools/drawing.d.ts +5 -5
- package/dist/tools/drawing.d.ts.map +1 -1
- package/dist/tools/drawing.js +5 -5
- package/dist/tools/drawing.js.map +1 -1
- package/dist/tools/export.d.ts +4 -4
- package/dist/tools/export.d.ts.map +1 -1
- package/dist/tools/export.js +8 -8
- package/dist/tools/export.js.map +1 -1
- package/dist/tools/modeling.d.ts +1 -1
- package/dist/tools/modeling.d.ts.map +1 -1
- package/dist/tools/modeling.js +71 -15
- package/dist/tools/modeling.js.map +1 -1
- package/dist/tools/vba-advanced.d.ts +228 -0
- package/dist/tools/vba-advanced.d.ts.map +1 -0
- package/dist/tools/vba-advanced.js +787 -0
- package/dist/tools/vba-advanced.js.map +1 -0
- package/dist/tools/vba-assembly.d.ts +143 -0
- package/dist/tools/vba-assembly.d.ts.map +1 -0
- package/dist/tools/vba-assembly.js +588 -0
- package/dist/tools/vba-assembly.js.map +1 -0
- package/dist/tools/vba-drawing.d.ts +350 -0
- package/dist/tools/vba-drawing.d.ts.map +1 -0
- package/dist/tools/vba-drawing.js +695 -0
- package/dist/tools/vba-drawing.js.map +1 -0
- package/dist/tools/vba-file-management.d.ts +156 -0
- package/dist/tools/vba-file-management.d.ts.map +1 -0
- package/dist/tools/vba-file-management.js +655 -0
- package/dist/tools/vba-file-management.js.map +1 -0
- package/dist/tools/vba-part.d.ts +187 -0
- package/dist/tools/vba-part.d.ts.map +1 -0
- package/dist/tools/vba-part.js +516 -0
- package/dist/tools/vba-part.js.map +1 -0
- package/dist/tools/vba.d.ts +1037 -9
- package/dist/tools/vba.d.ts.map +1 -1
- package/dist/tools/vba.js +94 -26
- package/dist/tools/vba.js.map +1 -1
- package/dist/utils/logger.js +2 -2
- package/dist/utils/logger.js.map +1 -1
- package/package.json +6 -3
- package/scripts/setup.js +71 -0
|
@@ -0,0 +1,787 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* VBA Generation for Advanced SolidWorks Features
|
|
4
|
+
* Configurations, equations, simulation setup, and advanced automation
|
|
5
|
+
*/
|
|
6
|
+
export const advancedVBATools = [
|
|
7
|
+
{
|
|
8
|
+
name: 'vba_configurations',
|
|
9
|
+
description: 'Generate VBA for managing configurations',
|
|
10
|
+
inputSchema: z.object({
|
|
11
|
+
operation: z.enum(['create', 'derive', 'suppress_features', 'set_properties', 'table_driven']),
|
|
12
|
+
configName: z.string(),
|
|
13
|
+
parentConfig: z.string().optional(),
|
|
14
|
+
features: z.array(z.string()).optional(),
|
|
15
|
+
properties: z.record(z.any()).optional(),
|
|
16
|
+
suppressStates: z.record(z.boolean()).optional(),
|
|
17
|
+
displayStates: z.array(z.string()).optional()
|
|
18
|
+
}),
|
|
19
|
+
handler: (args) => {
|
|
20
|
+
return `
|
|
21
|
+
Sub ManageConfiguration_${args.operation}()
|
|
22
|
+
Dim swApp As SldWorks.SldWorks
|
|
23
|
+
Dim swModel As SldWorks.ModelDoc2
|
|
24
|
+
Dim swConfig As SldWorks.Configuration
|
|
25
|
+
Dim swConfigMgr As SldWorks.ConfigurationManager
|
|
26
|
+
Dim swFeature As SldWorks.Feature
|
|
27
|
+
Dim bRet As Boolean
|
|
28
|
+
|
|
29
|
+
Set swApp = Application.SldWorks
|
|
30
|
+
Set swModel = swApp.ActiveDoc
|
|
31
|
+
|
|
32
|
+
If swModel Is Nothing Then
|
|
33
|
+
MsgBox "No active document"
|
|
34
|
+
Exit Sub
|
|
35
|
+
End If
|
|
36
|
+
|
|
37
|
+
Set swConfigMgr = swModel.ConfigurationManager
|
|
38
|
+
|
|
39
|
+
${args.operation === 'create' ? `
|
|
40
|
+
' Create new configuration
|
|
41
|
+
Set swConfig = swModel.AddConfiguration3( _
|
|
42
|
+
"${args.configName}", _
|
|
43
|
+
"Created via VBA", _
|
|
44
|
+
"", _
|
|
45
|
+
swConfigurationOptions2_e.swConfigOption_LinkToParent + _
|
|
46
|
+
swConfigurationOptions2_e.swConfigOption_InheritProperties, _
|
|
47
|
+
"${args.parentConfig || ''}")
|
|
48
|
+
|
|
49
|
+
If Not swConfig Is Nothing Then
|
|
50
|
+
' Activate configuration
|
|
51
|
+
swModel.ShowConfiguration2 "${args.configName}"
|
|
52
|
+
|
|
53
|
+
${args.features && args.features.length > 0 ? `
|
|
54
|
+
' Suppress/Unsuppress features
|
|
55
|
+
${args.features.map((feat) => `
|
|
56
|
+
Set swFeature = swModel.FeatureByName("${feat}")
|
|
57
|
+
If Not swFeature Is Nothing Then
|
|
58
|
+
swFeature.SetSuppression2 _
|
|
59
|
+
${args.suppressStates && args.suppressStates[feat] ?
|
|
60
|
+
'swFeatureSuppressionAction_e.swSuppressFeature' :
|
|
61
|
+
'swFeatureSuppressionAction_e.swUnSuppressFeature'}, _
|
|
62
|
+
swInConfigurationOpts_e.swThisConfiguration, Nothing
|
|
63
|
+
End If`).join('\n ')}` : ''}
|
|
64
|
+
|
|
65
|
+
${args.properties ? `
|
|
66
|
+
' Set configuration properties
|
|
67
|
+
Dim swCustPropMgr As SldWorks.CustomPropertyManager
|
|
68
|
+
Set swCustPropMgr = swConfig.CustomPropertyManager
|
|
69
|
+
|
|
70
|
+
${Object.entries(args.properties).map(([key, value]) => `
|
|
71
|
+
swCustPropMgr.Add3 "${key}", swCustomInfoType_e.swCustomInfoText, _
|
|
72
|
+
"${value}", swCustomPropertyAddOption_e.swCustomPropertyReplaceValue`).join('\n ')}` : ''}
|
|
73
|
+
|
|
74
|
+
MsgBox "Configuration '${args.configName}' created"
|
|
75
|
+
End If` : ''}
|
|
76
|
+
|
|
77
|
+
${args.operation === 'derive' ? `
|
|
78
|
+
' Create derived configuration
|
|
79
|
+
Dim parentConfig As SldWorks.Configuration
|
|
80
|
+
Set parentConfig = swModel.GetConfigurationByName("${args.parentConfig || 'Default'}")
|
|
81
|
+
|
|
82
|
+
If Not parentConfig Is Nothing Then
|
|
83
|
+
Set swConfig = parentConfig.GetDerivedConfiguration3( _
|
|
84
|
+
"${args.configName}", _
|
|
85
|
+
swConfigurationOptions2_e.swConfigOption_LinkToParent + _
|
|
86
|
+
swConfigurationOptions2_e.swConfigOption_InheritProperties, _
|
|
87
|
+
"Derived configuration")
|
|
88
|
+
|
|
89
|
+
If Not swConfig Is Nothing Then
|
|
90
|
+
swModel.ShowConfiguration2 "${args.configName}"
|
|
91
|
+
MsgBox "Derived configuration created: ${args.configName}"
|
|
92
|
+
End If
|
|
93
|
+
End If` : ''}
|
|
94
|
+
|
|
95
|
+
${args.operation === 'suppress_features' ? `
|
|
96
|
+
' Suppress features in configuration
|
|
97
|
+
swModel.ShowConfiguration2 "${args.configName}"
|
|
98
|
+
|
|
99
|
+
${args.features ? args.features.map((feat) => `
|
|
100
|
+
Set swFeature = swModel.FeatureByName("${feat}")
|
|
101
|
+
If Not swFeature Is Nothing Then
|
|
102
|
+
swFeature.SetSuppression2 _
|
|
103
|
+
swFeatureSuppressionAction_e.swSuppressFeature, _
|
|
104
|
+
swInConfigurationOpts_e.swThisConfiguration, Nothing
|
|
105
|
+
Debug.Print "Suppressed: ${feat}"
|
|
106
|
+
End If`).join('\n ') : ''}
|
|
107
|
+
|
|
108
|
+
MsgBox "Features suppressed in configuration"` : ''}
|
|
109
|
+
|
|
110
|
+
swModel.EditRebuild3
|
|
111
|
+
End Sub`;
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'vba_equations',
|
|
116
|
+
description: 'Generate VBA for managing equations and global variables',
|
|
117
|
+
inputSchema: z.object({
|
|
118
|
+
operation: z.enum(['add', 'modify', 'delete', 'link', 'export']),
|
|
119
|
+
equations: z.array(z.object({
|
|
120
|
+
name: z.string(),
|
|
121
|
+
value: z.string(),
|
|
122
|
+
isGlobal: z.boolean().optional(),
|
|
123
|
+
comment: z.string().optional()
|
|
124
|
+
})).optional(),
|
|
125
|
+
externalFile: z.string().optional(),
|
|
126
|
+
linkExternal: z.boolean().optional()
|
|
127
|
+
}),
|
|
128
|
+
handler: (args) => {
|
|
129
|
+
return `
|
|
130
|
+
Sub ManageEquations_${args.operation}()
|
|
131
|
+
Dim swApp As SldWorks.SldWorks
|
|
132
|
+
Dim swModel As SldWorks.ModelDoc2
|
|
133
|
+
Dim swEquationMgr As SldWorks.EquationMgr
|
|
134
|
+
Dim equations() As String
|
|
135
|
+
Dim i As Integer
|
|
136
|
+
Dim equationIndex As Integer
|
|
137
|
+
|
|
138
|
+
Set swApp = Application.SldWorks
|
|
139
|
+
Set swModel = swApp.ActiveDoc
|
|
140
|
+
|
|
141
|
+
If swModel Is Nothing Then
|
|
142
|
+
MsgBox "No active document"
|
|
143
|
+
Exit Sub
|
|
144
|
+
End If
|
|
145
|
+
|
|
146
|
+
Set swEquationMgr = swModel.GetEquationMgr
|
|
147
|
+
|
|
148
|
+
${args.operation === 'add' ? `
|
|
149
|
+
' Add equations
|
|
150
|
+
${args.equations ? args.equations.map((eq, i) => `
|
|
151
|
+
' Add equation: ${eq.name}
|
|
152
|
+
equationIndex = swEquationMgr.Add2( _
|
|
153
|
+
-1, _
|
|
154
|
+
"\\"${eq.name}\\" = ${eq.value}", _
|
|
155
|
+
${eq.isGlobal ? 'True' : 'False'})
|
|
156
|
+
|
|
157
|
+
If equationIndex >= 0 Then
|
|
158
|
+
Debug.Print "Added equation: ${eq.name} = ${eq.value}"
|
|
159
|
+
${eq.comment ? `swEquationMgr.SetEquationComment equationIndex, "${eq.comment}"` : ''}
|
|
160
|
+
End If`).join('\n ') : ''}
|
|
161
|
+
|
|
162
|
+
MsgBox "Equations added successfully"` : ''}
|
|
163
|
+
|
|
164
|
+
${args.operation === 'modify' ? `
|
|
165
|
+
' Modify existing equations
|
|
166
|
+
Dim equationCount As Integer
|
|
167
|
+
equationCount = swEquationMgr.GetCount
|
|
168
|
+
|
|
169
|
+
For i = 0 To equationCount - 1
|
|
170
|
+
Dim currentEq As String
|
|
171
|
+
currentEq = swEquationMgr.Equation(i)
|
|
172
|
+
|
|
173
|
+
${args.equations ? args.equations.map((eq) => `
|
|
174
|
+
If InStr(currentEq, "\\"${eq.name}\\"") > 0 Then
|
|
175
|
+
swEquationMgr.Equation(i) = "\\"${eq.name}\\" = ${eq.value}"
|
|
176
|
+
Debug.Print "Modified equation: ${eq.name}"
|
|
177
|
+
End If`).join('\n ') : ''}
|
|
178
|
+
Next i
|
|
179
|
+
|
|
180
|
+
MsgBox "Equations modified"` : ''}
|
|
181
|
+
|
|
182
|
+
${args.operation === 'delete' ? `
|
|
183
|
+
' Delete equations
|
|
184
|
+
${args.equations ? args.equations.map((eq) => `
|
|
185
|
+
For i = swEquationMgr.GetCount - 1 To 0 Step -1
|
|
186
|
+
If InStr(swEquationMgr.Equation(i), "\\"${eq.name}\\"") > 0 Then
|
|
187
|
+
swEquationMgr.Delete i
|
|
188
|
+
Debug.Print "Deleted equation: ${eq.name}"
|
|
189
|
+
End If
|
|
190
|
+
Next i`).join('\n ') : ''}
|
|
191
|
+
|
|
192
|
+
MsgBox "Equations deleted"` : ''}
|
|
193
|
+
|
|
194
|
+
${args.operation === 'link' ? `
|
|
195
|
+
' Link to external equation file
|
|
196
|
+
If swEquationMgr.LinkToFile Then
|
|
197
|
+
' Already linked, update path
|
|
198
|
+
swEquationMgr.FilePath = "${args.externalFile}"
|
|
199
|
+
Else
|
|
200
|
+
' Create link
|
|
201
|
+
swEquationMgr.LinkToFile = True
|
|
202
|
+
swEquationMgr.FilePath = "${args.externalFile}"
|
|
203
|
+
End If
|
|
204
|
+
|
|
205
|
+
swEquationMgr.UpdateValuesFromExternalEquationFile
|
|
206
|
+
MsgBox "Linked to external file: ${args.externalFile}"` : ''}
|
|
207
|
+
|
|
208
|
+
${args.operation === 'export' ? `
|
|
209
|
+
' Export equations to file
|
|
210
|
+
Dim fso As Object, file As Object
|
|
211
|
+
Set fso = CreateObject("Scripting.FileSystemObject")
|
|
212
|
+
Set file = fso.CreateTextFile("${args.externalFile || 'C:\\Temp\\equations.txt'}", True)
|
|
213
|
+
|
|
214
|
+
file.WriteLine "' SolidWorks Equations Export"
|
|
215
|
+
file.WriteLine "' Generated: " & Now
|
|
216
|
+
file.WriteLine ""
|
|
217
|
+
|
|
218
|
+
For i = 0 To swEquationMgr.GetCount - 1
|
|
219
|
+
file.WriteLine swEquationMgr.Equation(i)
|
|
220
|
+
|
|
221
|
+
Dim comment As String
|
|
222
|
+
comment = swEquationMgr.GetEquationComment(i)
|
|
223
|
+
If comment <> "" Then
|
|
224
|
+
file.WriteLine "' " & comment
|
|
225
|
+
End If
|
|
226
|
+
Next i
|
|
227
|
+
|
|
228
|
+
file.Close
|
|
229
|
+
MsgBox "Equations exported to: ${args.externalFile || 'C:\\Temp\\equations.txt'}"` : ''}
|
|
230
|
+
|
|
231
|
+
swModel.EditRebuild3
|
|
232
|
+
End Sub`;
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
name: 'vba_simulation_setup',
|
|
237
|
+
description: 'Generate VBA for setting up simulation studies',
|
|
238
|
+
inputSchema: z.object({
|
|
239
|
+
studyType: z.enum(['static', 'frequency', 'buckling', 'thermal', 'nonlinear', 'dynamic']),
|
|
240
|
+
studyName: z.string(),
|
|
241
|
+
materials: z.array(z.object({
|
|
242
|
+
componentName: z.string(),
|
|
243
|
+
materialName: z.string()
|
|
244
|
+
})).optional(),
|
|
245
|
+
fixtures: z.array(z.object({
|
|
246
|
+
faceName: z.string(),
|
|
247
|
+
type: z.enum(['fixed', 'roller', 'hinge'])
|
|
248
|
+
})).optional(),
|
|
249
|
+
loads: z.array(z.object({
|
|
250
|
+
faceName: z.string(),
|
|
251
|
+
type: z.enum(['force', 'pressure', 'torque']),
|
|
252
|
+
value: z.number(),
|
|
253
|
+
unit: z.string()
|
|
254
|
+
})).optional(),
|
|
255
|
+
meshQuality: z.enum(['draft', 'standard', 'fine']).optional()
|
|
256
|
+
}),
|
|
257
|
+
handler: (args) => {
|
|
258
|
+
return `
|
|
259
|
+
Sub SetupSimulationStudy_${args.studyType}()
|
|
260
|
+
Dim swApp As SldWorks.SldWorks
|
|
261
|
+
Dim swModel As SldWorks.ModelDoc2
|
|
262
|
+
Dim swSimulation As Object ' CosmosWorksLib.CwAddincallback
|
|
263
|
+
Dim swStudyMgr As Object ' CosmosWorksLib.CWStudyManager
|
|
264
|
+
Dim swStudy As Object ' CosmosWorksLib.CWStudy
|
|
265
|
+
Dim swMesh As Object ' CosmosWorksLib.CWMesh
|
|
266
|
+
Dim errCode As Long
|
|
267
|
+
|
|
268
|
+
Set swApp = Application.SldWorks
|
|
269
|
+
Set swModel = swApp.ActiveDoc
|
|
270
|
+
|
|
271
|
+
If swModel Is Nothing Then
|
|
272
|
+
MsgBox "No active document"
|
|
273
|
+
Exit Sub
|
|
274
|
+
End If
|
|
275
|
+
|
|
276
|
+
' Get Simulation add-in
|
|
277
|
+
Set swSimulation = swApp.GetAddInObject("SldWorks.Simulation")
|
|
278
|
+
|
|
279
|
+
If swSimulation Is Nothing Then
|
|
280
|
+
MsgBox "Simulation add-in not loaded"
|
|
281
|
+
Exit Sub
|
|
282
|
+
End If
|
|
283
|
+
|
|
284
|
+
' Activate Simulation
|
|
285
|
+
swSimulation.InitializeInterface swApp, swModel
|
|
286
|
+
Set swStudyMgr = swSimulation.StudyManager
|
|
287
|
+
|
|
288
|
+
' Create study
|
|
289
|
+
Set swStudy = swStudyMgr.CreateNewStudy3( _
|
|
290
|
+
"${args.studyName}", _
|
|
291
|
+
${args.studyType === 'static' ? '0' :
|
|
292
|
+
args.studyType === 'frequency' ? '1' :
|
|
293
|
+
args.studyType === 'buckling' ? '2' :
|
|
294
|
+
args.studyType === 'thermal' ? '3' :
|
|
295
|
+
args.studyType === 'nonlinear' ? '4' :
|
|
296
|
+
'5'}, _
|
|
297
|
+
0, errCode)
|
|
298
|
+
|
|
299
|
+
If swStudy Is Nothing Then
|
|
300
|
+
MsgBox "Failed to create study. Error: " & errCode
|
|
301
|
+
Exit Sub
|
|
302
|
+
End If
|
|
303
|
+
|
|
304
|
+
${args.materials && args.materials.length > 0 ? `
|
|
305
|
+
' Apply materials
|
|
306
|
+
${args.materials.map((mat) => `
|
|
307
|
+
swModel.Extension.SelectByID2 "${mat.componentName}", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0
|
|
308
|
+
Dim swMaterial As Object
|
|
309
|
+
Set swMaterial = swStudy.GetMaterial("${mat.materialName}")
|
|
310
|
+
If Not swMaterial Is Nothing Then
|
|
311
|
+
swStudy.ApplyMaterial swMaterial
|
|
312
|
+
Debug.Print "Applied material: ${mat.materialName} to ${mat.componentName}"
|
|
313
|
+
End If`).join('\n ')}` : ''}
|
|
314
|
+
|
|
315
|
+
${args.fixtures && args.fixtures.length > 0 ? `
|
|
316
|
+
' Add fixtures
|
|
317
|
+
${args.fixtures.map((fix) => `
|
|
318
|
+
swModel.Extension.SelectByID2 "${fix.faceName}", "FACE", 0, 0, 0, False, 0, Nothing, 0
|
|
319
|
+
Dim swFixture As Object
|
|
320
|
+
Set swFixture = swStudy.AddRestraint( _
|
|
321
|
+
${fix.type === 'fixed' ? '0' :
|
|
322
|
+
fix.type === 'roller' ? '1' :
|
|
323
|
+
'2'}, _
|
|
324
|
+
swModel.SelectionManager)
|
|
325
|
+
If Not swFixture Is Nothing Then
|
|
326
|
+
Debug.Print "Added ${fix.type} fixture to ${fix.faceName}"
|
|
327
|
+
End If`).join('\n ')}` : ''}
|
|
328
|
+
|
|
329
|
+
${args.loads && args.loads.length > 0 ? `
|
|
330
|
+
' Add loads
|
|
331
|
+
${args.loads.map((load) => `
|
|
332
|
+
swModel.Extension.SelectByID2 "${load.faceName}", "FACE", 0, 0, 0, False, 0, Nothing, 0
|
|
333
|
+
Dim swLoad As Object
|
|
334
|
+
Set swLoad = swStudy.AddLoad( _
|
|
335
|
+
${load.type === 'force' ? '0' :
|
|
336
|
+
load.type === 'pressure' ? '1' :
|
|
337
|
+
'2'}, _
|
|
338
|
+
swModel.SelectionManager)
|
|
339
|
+
If Not swLoad Is Nothing Then
|
|
340
|
+
swLoad.Value = ${load.value}
|
|
341
|
+
swLoad.Unit = "${load.unit}"
|
|
342
|
+
Debug.Print "Added ${load.type}: ${load.value} ${load.unit} to ${load.faceName}"
|
|
343
|
+
End If`).join('\n ')}` : ''}
|
|
344
|
+
|
|
345
|
+
' Create mesh
|
|
346
|
+
Set swMesh = swStudy.GetMesh
|
|
347
|
+
If Not swMesh Is Nothing Then
|
|
348
|
+
swMesh.Quality = ${args.meshQuality === 'draft' ? '0' :
|
|
349
|
+
args.meshQuality === 'fine' ? '2' : '1'}
|
|
350
|
+
|
|
351
|
+
Dim meshResult As Long
|
|
352
|
+
meshResult = swStudy.CreateMesh(0, 0, 0, errCode)
|
|
353
|
+
|
|
354
|
+
If meshResult = 0 Then
|
|
355
|
+
Debug.Print "Mesh created successfully"
|
|
356
|
+
Else
|
|
357
|
+
MsgBox "Failed to create mesh. Error: " & errCode
|
|
358
|
+
End If
|
|
359
|
+
End If
|
|
360
|
+
|
|
361
|
+
MsgBox "Simulation study '${args.studyName}' created and configured"
|
|
362
|
+
End Sub`;
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
name: 'vba_api_automation',
|
|
367
|
+
description: 'Generate VBA for advanced API automation and event handling',
|
|
368
|
+
inputSchema: z.object({
|
|
369
|
+
automationType: z.enum(['event_handler', 'macro_feature', 'property_page', 'add_in']),
|
|
370
|
+
eventTypes: z.array(z.enum([
|
|
371
|
+
'file_save', 'file_open', 'rebuild', 'selection_change',
|
|
372
|
+
'dimension_change', 'feature_add', 'configuration_change'
|
|
373
|
+
])).optional(),
|
|
374
|
+
className: z.string().optional(),
|
|
375
|
+
methods: z.array(z.object({
|
|
376
|
+
name: z.string(),
|
|
377
|
+
parameters: z.array(z.string()).optional(),
|
|
378
|
+
returnType: z.string().optional()
|
|
379
|
+
})).optional()
|
|
380
|
+
}),
|
|
381
|
+
handler: (args) => {
|
|
382
|
+
const eventHandlers = {
|
|
383
|
+
file_save: `
|
|
384
|
+
Private Function swApp_FileSaveNotify(ByVal FileName As String) As Long
|
|
385
|
+
Debug.Print "File saving: " & FileName
|
|
386
|
+
' Add custom save logic here
|
|
387
|
+
swApp_FileSaveNotify = 0
|
|
388
|
+
End Function`,
|
|
389
|
+
file_open: `
|
|
390
|
+
Private Function swApp_FileOpenNotify(ByVal FileName As String) As Long
|
|
391
|
+
Debug.Print "File opened: " & FileName
|
|
392
|
+
' Add custom open logic here
|
|
393
|
+
swApp_FileOpenNotify = 0
|
|
394
|
+
End Function`,
|
|
395
|
+
rebuild: `
|
|
396
|
+
Private Function swApp_RebuildNotify() As Long
|
|
397
|
+
Debug.Print "Model rebuilding"
|
|
398
|
+
' Add custom rebuild logic here
|
|
399
|
+
swApp_RebuildNotify = 0
|
|
400
|
+
End Function`,
|
|
401
|
+
selection_change: `
|
|
402
|
+
Private Function swApp_SelectionChangeNotify() As Long
|
|
403
|
+
Dim swSelMgr As SldWorks.SelectionMgr
|
|
404
|
+
Set swSelMgr = swModel.SelectionManager
|
|
405
|
+
|
|
406
|
+
Debug.Print "Selection changed. Count: " & swSelMgr.GetSelectedObjectCount2(-1)
|
|
407
|
+
' Add custom selection logic here
|
|
408
|
+
swApp_SelectionChangeNotify = 0
|
|
409
|
+
End Function`,
|
|
410
|
+
dimension_change: `
|
|
411
|
+
Private Function swApp_DimensionChangeNotify(ByVal swDim As Object) As Long
|
|
412
|
+
Debug.Print "Dimension changed: " & swDim.FullName
|
|
413
|
+
' Add custom dimension change logic here
|
|
414
|
+
swApp_DimensionChangeNotify = 0
|
|
415
|
+
End Function`
|
|
416
|
+
};
|
|
417
|
+
return `
|
|
418
|
+
${args.automationType === 'event_handler' ? `
|
|
419
|
+
' Class module for SolidWorks event handling
|
|
420
|
+
' Name this class module: ${args.className || 'SwEventHandler'}
|
|
421
|
+
|
|
422
|
+
Option Explicit
|
|
423
|
+
|
|
424
|
+
' SolidWorks application events
|
|
425
|
+
Public WithEvents swApp As SldWorks.SldWorks
|
|
426
|
+
Public WithEvents swModel As SldWorks.ModelDoc2
|
|
427
|
+
|
|
428
|
+
' Initialize event handler
|
|
429
|
+
Public Sub Init(app As SldWorks.SldWorks, model As SldWorks.ModelDoc2)
|
|
430
|
+
Set swApp = app
|
|
431
|
+
Set swModel = model
|
|
432
|
+
|
|
433
|
+
' Enable notifications
|
|
434
|
+
If Not swModel Is Nothing Then
|
|
435
|
+
swModel.EnableNotifications = True
|
|
436
|
+
End If
|
|
437
|
+
End Sub
|
|
438
|
+
|
|
439
|
+
${args.eventTypes ? args.eventTypes.map((evt) => eventHandlers[evt] || '').join('\n\n') : ''}
|
|
440
|
+
|
|
441
|
+
' Cleanup
|
|
442
|
+
Public Sub Terminate()
|
|
443
|
+
Set swModel = Nothing
|
|
444
|
+
Set swApp = Nothing
|
|
445
|
+
End Sub
|
|
446
|
+
|
|
447
|
+
' Usage in main module:
|
|
448
|
+
' Dim eventHandler As New SwEventHandler
|
|
449
|
+
' eventHandler.Init swApp, swModel` : ''}
|
|
450
|
+
|
|
451
|
+
${args.automationType === 'macro_feature' ? `
|
|
452
|
+
Sub CreateMacroFeature()
|
|
453
|
+
Dim swApp As SldWorks.SldWorks
|
|
454
|
+
Dim swModel As SldWorks.ModelDoc2
|
|
455
|
+
Dim swFeatMgr As SldWorks.FeatureManager
|
|
456
|
+
Dim swMacroFeature As SldWorks.Feature
|
|
457
|
+
Dim swMacroFeatureDef As SldWorks.MacroFeatureData
|
|
458
|
+
Dim methods(9) As String
|
|
459
|
+
Dim dimTypes(1) As Long
|
|
460
|
+
Dim dimValues(1) As Double
|
|
461
|
+
Dim paramNames(1) As String
|
|
462
|
+
Dim paramTypes(1) As Long
|
|
463
|
+
Dim paramValues(1) As String
|
|
464
|
+
|
|
465
|
+
Set swApp = Application.SldWorks
|
|
466
|
+
Set swModel = swApp.ActiveDoc
|
|
467
|
+
|
|
468
|
+
If swModel Is Nothing Then Exit Sub
|
|
469
|
+
|
|
470
|
+
Set swFeatMgr = swModel.FeatureManager
|
|
471
|
+
|
|
472
|
+
' Define macro feature methods
|
|
473
|
+
methods(0) = "${args.className || 'CustomFeature'}" ' Module name
|
|
474
|
+
methods(1) = "swmRebuild" ' Rebuild function
|
|
475
|
+
methods(2) = "swmEdit" ' Edit function
|
|
476
|
+
methods(3) = "swmSecurity" ' Security function
|
|
477
|
+
methods(4) = "" ' Reserved
|
|
478
|
+
methods(5) = "" ' Reserved
|
|
479
|
+
methods(6) = "" ' Reserved
|
|
480
|
+
methods(7) = "" ' Reserved
|
|
481
|
+
methods(8) = "" ' Reserved
|
|
482
|
+
methods(9) = "" ' Icon file
|
|
483
|
+
|
|
484
|
+
' Set parameters
|
|
485
|
+
paramNames(0) = "Parameter1"
|
|
486
|
+
paramTypes(0) = swMacroFeatureParamType_e.swMacroFeatureParamTypeDouble
|
|
487
|
+
paramValues(0) = "10.0"
|
|
488
|
+
|
|
489
|
+
' Create macro feature
|
|
490
|
+
Set swMacroFeature = swFeatMgr.InsertMacroFeature3( _
|
|
491
|
+
"${args.className || 'CustomFeature'}", _
|
|
492
|
+
"", methods, _
|
|
493
|
+
paramNames, paramTypes, paramValues, _
|
|
494
|
+
Nothing, Nothing, Nothing, _
|
|
495
|
+
Nothing, swMacroFeatureOptions_e.swMacroFeatureByDefault)
|
|
496
|
+
|
|
497
|
+
If Not swMacroFeature Is Nothing Then
|
|
498
|
+
MsgBox "Macro feature created: " & swMacroFeature.Name
|
|
499
|
+
End If
|
|
500
|
+
End Sub
|
|
501
|
+
|
|
502
|
+
' Macro feature rebuild method
|
|
503
|
+
Function swmRebuild(swApp As Variant, swModel As Variant, swFeature As Variant) As Variant
|
|
504
|
+
' Custom rebuild logic
|
|
505
|
+
swmRebuild = True
|
|
506
|
+
End Function
|
|
507
|
+
|
|
508
|
+
' Macro feature edit method
|
|
509
|
+
Function swmEdit(swApp As Variant, swModel As Variant, swFeature As Variant) As Variant
|
|
510
|
+
' Custom edit logic
|
|
511
|
+
MsgBox "Editing macro feature"
|
|
512
|
+
swmEdit = True
|
|
513
|
+
End Function` : ''}
|
|
514
|
+
|
|
515
|
+
${args.automationType === 'property_page' ? `
|
|
516
|
+
' Property Manager Page Handler
|
|
517
|
+
Sub CreatePropertyPage()
|
|
518
|
+
Dim swApp As SldWorks.SldWorks
|
|
519
|
+
Dim swModel As SldWorks.ModelDoc2
|
|
520
|
+
Dim swPMPage As SldWorks.PropertyManagerPage2
|
|
521
|
+
Dim swPMPageHandler As PropertyManagerPageHandler
|
|
522
|
+
Dim errors As Long
|
|
523
|
+
|
|
524
|
+
Set swApp = Application.SldWorks
|
|
525
|
+
Set swModel = swApp.ActiveDoc
|
|
526
|
+
|
|
527
|
+
If swModel Is Nothing Then Exit Sub
|
|
528
|
+
|
|
529
|
+
' Create property page handler
|
|
530
|
+
Set swPMPageHandler = New PropertyManagerPageHandler
|
|
531
|
+
|
|
532
|
+
' Create property page
|
|
533
|
+
Set swPMPage = swApp.CreatePropertyManagerPage( _
|
|
534
|
+
"${args.className || 'Custom Properties'}", _
|
|
535
|
+
swPropertyManagerPageOptions_e.swPropertyManagerOptions_OkayButton + _
|
|
536
|
+
swPropertyManagerPageOptions_e.swPropertyManagerOptions_CancelButton, _
|
|
537
|
+
swPMPageHandler, errors)
|
|
538
|
+
|
|
539
|
+
If Not swPMPage Is Nothing Then
|
|
540
|
+
' Add controls
|
|
541
|
+
Dim group As SldWorks.PropertyManagerPageGroup
|
|
542
|
+
Dim textbox As SldWorks.PropertyManagerPageTextbox
|
|
543
|
+
Dim numberbox As SldWorks.PropertyManagerPageNumberbox
|
|
544
|
+
|
|
545
|
+
Set group = swPMPage.AddGroupBox(1, "Parameters", _
|
|
546
|
+
swPropertyManagerPageGroupBoxOptions_e.swGroupBoxOptions_Expanded)
|
|
547
|
+
|
|
548
|
+
Set textbox = group.AddControl2(2, _
|
|
549
|
+
swPropertyManagerPageControlType_e.swControlType_Textbox, _
|
|
550
|
+
"Name:", swPropertyManagerPageControlLeftAlign_e.swControlAlign_LeftEdge, _
|
|
551
|
+
swPropertyManagerPageControlOptions_e.swControlOptions_Enabled, "")
|
|
552
|
+
|
|
553
|
+
Set numberbox = group.AddControl2(3, _
|
|
554
|
+
swPropertyManagerPageControlType_e.swControlType_Numberbox, _
|
|
555
|
+
"Value:", swPropertyManagerPageControlLeftAlign_e.swControlAlign_LeftEdge, _
|
|
556
|
+
swPropertyManagerPageControlOptions_e.swControlOptions_Enabled, "")
|
|
557
|
+
|
|
558
|
+
numberbox.SetRange2 swNumberboxUnitType_e.swNumberBox_Length, 0, 100, True, 10, 1, 0.1
|
|
559
|
+
|
|
560
|
+
' Show property page
|
|
561
|
+
swPMPage.Show
|
|
562
|
+
End If
|
|
563
|
+
End Sub` : ''}
|
|
564
|
+
|
|
565
|
+
${args.automationType === 'add_in' ? `
|
|
566
|
+
' SolidWorks Add-in Template
|
|
567
|
+
' Implements SwAddin interface
|
|
568
|
+
|
|
569
|
+
Option Explicit
|
|
570
|
+
|
|
571
|
+
Implements SwAddin
|
|
572
|
+
|
|
573
|
+
Private swApp As SldWorks.SldWorks
|
|
574
|
+
Private addinID As Long
|
|
575
|
+
|
|
576
|
+
Private Function SwAddin_ConnectToSW(ThisSW As Object, Cookie As Long) As Boolean
|
|
577
|
+
Set swApp = ThisSW
|
|
578
|
+
addinID = Cookie
|
|
579
|
+
|
|
580
|
+
' Register callbacks
|
|
581
|
+
swApp.SetAddinCallbackInfo2 0, Me, addinID
|
|
582
|
+
|
|
583
|
+
' Add menu items
|
|
584
|
+
AddMenuItems
|
|
585
|
+
|
|
586
|
+
' Add toolbar
|
|
587
|
+
AddToolbar
|
|
588
|
+
|
|
589
|
+
SwAddin_ConnectToSW = True
|
|
590
|
+
End Function
|
|
591
|
+
|
|
592
|
+
Private Function SwAddin_DisconnectFromSW() As Boolean
|
|
593
|
+
' Clean up
|
|
594
|
+
RemoveMenuItems
|
|
595
|
+
RemoveToolbar
|
|
596
|
+
|
|
597
|
+
Set swApp = Nothing
|
|
598
|
+
SwAddin_DisconnectFromSW = True
|
|
599
|
+
End Function
|
|
600
|
+
|
|
601
|
+
Private Sub AddMenuItems()
|
|
602
|
+
Dim menuID As Long
|
|
603
|
+
menuID = swApp.AddMenu(swDocumentTypes_e.swDocPART, _
|
|
604
|
+
"${args.className || 'Custom Add-in'}", 0)
|
|
605
|
+
|
|
606
|
+
swApp.AddMenuItem4 menuID, 0, _
|
|
607
|
+
"Command 1@${args.className || 'Custom Add-in'}", _
|
|
608
|
+
0, "OnCommand1", "", ""
|
|
609
|
+
End Sub
|
|
610
|
+
|
|
611
|
+
Private Sub AddToolbar()
|
|
612
|
+
Dim toolbar As Object
|
|
613
|
+
Set toolbar = swApp.AddToolbar5( _
|
|
614
|
+
addinID, "${args.className || 'Custom Toolbar'}", _
|
|
615
|
+
swDocumentTypes_e.swDocPART + swDocumentTypes_e.swDocASSEMBLY, _
|
|
616
|
+
swToolbarOptions_e.swToolbarOptions_ShowInAllDocuments)
|
|
617
|
+
End Sub
|
|
618
|
+
|
|
619
|
+
Public Sub OnCommand1()
|
|
620
|
+
MsgBox "Custom command executed"
|
|
621
|
+
End Sub` : ''}`;
|
|
622
|
+
}
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
name: 'vba_error_handling',
|
|
626
|
+
description: 'Generate VBA with comprehensive error handling and logging',
|
|
627
|
+
inputSchema: z.object({
|
|
628
|
+
functionName: z.string(),
|
|
629
|
+
operationType: z.string(),
|
|
630
|
+
logToFile: z.boolean().optional(),
|
|
631
|
+
logPath: z.string().optional(),
|
|
632
|
+
emailOnError: z.boolean().optional(),
|
|
633
|
+
emailAddress: z.string().optional()
|
|
634
|
+
}),
|
|
635
|
+
handler: (args) => {
|
|
636
|
+
return `
|
|
637
|
+
' Error handling and logging utilities
|
|
638
|
+
Option Explicit
|
|
639
|
+
|
|
640
|
+
Private Const LOG_FILE As String = "${args.logPath || 'C:\\Temp\\SolidWorksVBA.log'}"
|
|
641
|
+
|
|
642
|
+
Sub ${args.functionName}_WithErrorHandling()
|
|
643
|
+
On Error GoTo ErrorHandler
|
|
644
|
+
|
|
645
|
+
Dim swApp As SldWorks.SldWorks
|
|
646
|
+
Dim swModel As SldWorks.ModelDoc2
|
|
647
|
+
Dim startTime As Double
|
|
648
|
+
Dim endTime As Double
|
|
649
|
+
|
|
650
|
+
startTime = Timer
|
|
651
|
+
|
|
652
|
+
' Initialize
|
|
653
|
+
Set swApp = Application.SldWorks
|
|
654
|
+
Set swModel = swApp.ActiveDoc
|
|
655
|
+
|
|
656
|
+
' Log operation start
|
|
657
|
+
LogMessage "INFO", "Starting ${args.operationType}"
|
|
658
|
+
|
|
659
|
+
' Validate prerequisites
|
|
660
|
+
If swModel Is Nothing Then
|
|
661
|
+
Err.Raise vbObjectError + 1000, "${args.functionName}", _
|
|
662
|
+
"No active document found"
|
|
663
|
+
End If
|
|
664
|
+
|
|
665
|
+
' ===============================
|
|
666
|
+
' Main operation logic goes here
|
|
667
|
+
' ===============================
|
|
668
|
+
|
|
669
|
+
' Your ${args.operationType} code here
|
|
670
|
+
|
|
671
|
+
' ===============================
|
|
672
|
+
|
|
673
|
+
endTime = Timer
|
|
674
|
+
LogMessage "SUCCESS", "${args.operationType} completed in " & _
|
|
675
|
+
Format(endTime - startTime, "0.00") & " seconds"
|
|
676
|
+
|
|
677
|
+
Exit Sub
|
|
678
|
+
|
|
679
|
+
ErrorHandler:
|
|
680
|
+
Dim errorMsg As String
|
|
681
|
+
errorMsg = "Error in ${args.functionName}: " & vbCrLf & _
|
|
682
|
+
"Number: " & Err.Number & vbCrLf & _
|
|
683
|
+
"Description: " & Err.Description & vbCrLf & _
|
|
684
|
+
"Source: " & Err.Source
|
|
685
|
+
|
|
686
|
+
' Log error
|
|
687
|
+
LogMessage "ERROR", errorMsg
|
|
688
|
+
|
|
689
|
+
${args.emailOnError ? `
|
|
690
|
+
' Send email notification
|
|
691
|
+
SendErrorEmail "${args.emailAddress}", "${args.functionName} Error", errorMsg` : ''}
|
|
692
|
+
|
|
693
|
+
' Display error to user
|
|
694
|
+
MsgBox errorMsg, vbCritical, "Error in ${args.operationType}"
|
|
695
|
+
|
|
696
|
+
' Clean up
|
|
697
|
+
On Error Resume Next
|
|
698
|
+
If Not swModel Is Nothing Then
|
|
699
|
+
swModel.ClearSelection2 True
|
|
700
|
+
End If
|
|
701
|
+
|
|
702
|
+
' Re-raise error if needed
|
|
703
|
+
' Err.Raise Err.Number, Err.Source, Err.Description
|
|
704
|
+
End Sub
|
|
705
|
+
|
|
706
|
+
Private Sub LogMessage(logLevel As String, message As String)
|
|
707
|
+
${args.logToFile ? `
|
|
708
|
+
Dim fso As Object
|
|
709
|
+
Dim logFile As Object
|
|
710
|
+
|
|
711
|
+
On Error Resume Next
|
|
712
|
+
|
|
713
|
+
Set fso = CreateObject("Scripting.FileSystemObject")
|
|
714
|
+
|
|
715
|
+
' Create log file if it doesn't exist
|
|
716
|
+
If Not fso.FileExists(LOG_FILE) Then
|
|
717
|
+
Set logFile = fso.CreateTextFile(LOG_FILE, True)
|
|
718
|
+
logFile.WriteLine "Timestamp,Level,Message"
|
|
719
|
+
Else
|
|
720
|
+
Set logFile = fso.OpenTextFile(LOG_FILE, 8) ' Append mode
|
|
721
|
+
End If
|
|
722
|
+
|
|
723
|
+
' Write log entry
|
|
724
|
+
logFile.WriteLine Now & "," & logLevel & "," & Replace(message, ",", ";")
|
|
725
|
+
logFile.Close
|
|
726
|
+
|
|
727
|
+
Set logFile = Nothing
|
|
728
|
+
Set fso = Nothing` : ''}
|
|
729
|
+
|
|
730
|
+
' Also output to immediate window
|
|
731
|
+
Debug.Print "[" & logLevel & "] " & Now & " - " & message
|
|
732
|
+
End Sub
|
|
733
|
+
|
|
734
|
+
${args.emailOnError ? `
|
|
735
|
+
Private Sub SendErrorEmail(recipient As String, subject As String, body As String)
|
|
736
|
+
On Error Resume Next
|
|
737
|
+
|
|
738
|
+
Dim outlook As Object
|
|
739
|
+
Dim mail As Object
|
|
740
|
+
|
|
741
|
+
Set outlook = CreateObject("Outlook.Application")
|
|
742
|
+
Set mail = outlook.CreateItem(0) ' olMailItem
|
|
743
|
+
|
|
744
|
+
With mail
|
|
745
|
+
.To = recipient
|
|
746
|
+
.Subject = subject
|
|
747
|
+
.Body = body & vbCrLf & vbCrLf & _
|
|
748
|
+
"Generated by: ${args.functionName}" & vbCrLf & _
|
|
749
|
+
"Time: " & Now & vbCrLf & _
|
|
750
|
+
"Computer: " & Environ("COMPUTERNAME") & vbCrLf & _
|
|
751
|
+
"User: " & Environ("USERNAME")
|
|
752
|
+
.Send
|
|
753
|
+
End With
|
|
754
|
+
|
|
755
|
+
Set mail = Nothing
|
|
756
|
+
Set outlook = Nothing
|
|
757
|
+
End Sub` : ''}
|
|
758
|
+
|
|
759
|
+
' Performance monitoring
|
|
760
|
+
Private Sub MeasurePerformance(operationName As String, codeBlock As String)
|
|
761
|
+
Dim startTime As Double, endTime As Double
|
|
762
|
+
Dim memBefore As Long, memAfter As Long
|
|
763
|
+
|
|
764
|
+
' Get memory usage before
|
|
765
|
+
memBefore = GetMemoryUsage()
|
|
766
|
+
startTime = Timer
|
|
767
|
+
|
|
768
|
+
' Execute code block
|
|
769
|
+
Application.Run codeBlock
|
|
770
|
+
|
|
771
|
+
endTime = Timer
|
|
772
|
+
memAfter = GetMemoryUsage()
|
|
773
|
+
|
|
774
|
+
LogMessage "PERFORMANCE", operationName & " - Time: " & _
|
|
775
|
+
Format(endTime - startTime, "0.000") & "s, Memory: " & _
|
|
776
|
+
Format((memAfter - memBefore) / 1024, "0.00") & " KB"
|
|
777
|
+
End Sub
|
|
778
|
+
|
|
779
|
+
Private Function GetMemoryUsage() As Long
|
|
780
|
+
' Returns approximate memory usage in bytes
|
|
781
|
+
On Error Resume Next
|
|
782
|
+
GetMemoryUsage = Application.MemoryUsed * 1024
|
|
783
|
+
End Function`;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
];
|
|
787
|
+
//# sourceMappingURL=vba-advanced.js.map
|