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.
Files changed (62) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +75 -8
  3. package/dist/db/connection.d.ts.map +1 -1
  4. package/dist/db/connection.js.map +1 -1
  5. package/dist/knowledge/chromadb.js +1 -1
  6. package/dist/knowledge/chromadb.js.map +1 -1
  7. package/dist/resources/design-table.d.ts +16 -16
  8. package/dist/resources/design-table.d.ts.map +1 -1
  9. package/dist/resources/design-table.js +2 -2
  10. package/dist/resources/design-table.js.map +1 -1
  11. package/dist/resources/pdm.d.ts +43 -43
  12. package/dist/resources/pdm.d.ts.map +1 -1
  13. package/dist/resources/pdm.js +8 -8
  14. package/dist/resources/pdm.js.map +1 -1
  15. package/dist/solidworks/api.d.ts +15 -14
  16. package/dist/solidworks/api.d.ts.map +1 -1
  17. package/dist/solidworks/api.js +343 -71
  18. package/dist/solidworks/api.js.map +1 -1
  19. package/dist/tools/analysis.d.ts +4 -4
  20. package/dist/tools/analysis.d.ts.map +1 -1
  21. package/dist/tools/analysis.js +10 -15
  22. package/dist/tools/analysis.js.map +1 -1
  23. package/dist/tools/drawing.d.ts +5 -5
  24. package/dist/tools/drawing.d.ts.map +1 -1
  25. package/dist/tools/drawing.js +5 -5
  26. package/dist/tools/drawing.js.map +1 -1
  27. package/dist/tools/export.d.ts +4 -4
  28. package/dist/tools/export.d.ts.map +1 -1
  29. package/dist/tools/export.js +8 -8
  30. package/dist/tools/export.js.map +1 -1
  31. package/dist/tools/modeling.d.ts +1 -1
  32. package/dist/tools/modeling.d.ts.map +1 -1
  33. package/dist/tools/modeling.js +71 -15
  34. package/dist/tools/modeling.js.map +1 -1
  35. package/dist/tools/vba-advanced.d.ts +228 -0
  36. package/dist/tools/vba-advanced.d.ts.map +1 -0
  37. package/dist/tools/vba-advanced.js +787 -0
  38. package/dist/tools/vba-advanced.js.map +1 -0
  39. package/dist/tools/vba-assembly.d.ts +143 -0
  40. package/dist/tools/vba-assembly.d.ts.map +1 -0
  41. package/dist/tools/vba-assembly.js +588 -0
  42. package/dist/tools/vba-assembly.js.map +1 -0
  43. package/dist/tools/vba-drawing.d.ts +350 -0
  44. package/dist/tools/vba-drawing.d.ts.map +1 -0
  45. package/dist/tools/vba-drawing.js +695 -0
  46. package/dist/tools/vba-drawing.js.map +1 -0
  47. package/dist/tools/vba-file-management.d.ts +156 -0
  48. package/dist/tools/vba-file-management.d.ts.map +1 -0
  49. package/dist/tools/vba-file-management.js +655 -0
  50. package/dist/tools/vba-file-management.js.map +1 -0
  51. package/dist/tools/vba-part.d.ts +187 -0
  52. package/dist/tools/vba-part.d.ts.map +1 -0
  53. package/dist/tools/vba-part.js +516 -0
  54. package/dist/tools/vba-part.js.map +1 -0
  55. package/dist/tools/vba.d.ts +1037 -9
  56. package/dist/tools/vba.d.ts.map +1 -1
  57. package/dist/tools/vba.js +94 -26
  58. package/dist/tools/vba.js.map +1 -1
  59. package/dist/utils/logger.js +2 -2
  60. package/dist/utils/logger.js.map +1 -1
  61. package/package.json +6 -3
  62. package/scripts/setup.js +71 -0
@@ -0,0 +1,695 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * VBA Generation for Drawing Automation
4
+ * Comprehensive SolidWorks drawing creation and management
5
+ */
6
+ export const drawingVBATools = [
7
+ {
8
+ name: 'vba_create_drawing_views',
9
+ description: 'Generate VBA for creating drawing views',
10
+ inputSchema: z.object({
11
+ viewType: z.enum([
12
+ 'standard', 'projected', 'auxiliary', 'section', 'detail',
13
+ 'broken', 'break_out_section', 'isometric', 'named'
14
+ ]),
15
+ modelPath: z.string().describe('Path to model file'),
16
+ viewOrientation: z.enum([
17
+ 'front', 'back', 'left', 'right', 'top', 'bottom',
18
+ 'isometric', 'dimetric', 'trimetric', 'current'
19
+ ]).optional(),
20
+ position: z.object({
21
+ x: z.number().describe('X position in mm'),
22
+ y: z.number().describe('Y position in mm')
23
+ }),
24
+ scale: z.number().optional().describe('View scale (e.g., 0.5 for 1:2)'),
25
+ sectionLine: z.object({
26
+ startX: z.number(),
27
+ startY: z.number(),
28
+ endX: z.number(),
29
+ endY: z.number()
30
+ }).optional(),
31
+ detailCircle: z.object({
32
+ centerX: z.number(),
33
+ centerY: z.number(),
34
+ radius: z.number()
35
+ }).optional()
36
+ }),
37
+ handler: (args) => {
38
+ const viewOrientations = {
39
+ front: 'swDrawingViewOrientations_e.swDrawingFrontView',
40
+ back: 'swDrawingViewOrientations_e.swDrawingBackView',
41
+ left: 'swDrawingViewOrientations_e.swDrawingLeftView',
42
+ right: 'swDrawingViewOrientations_e.swDrawingRightView',
43
+ top: 'swDrawingViewOrientations_e.swDrawingTopView',
44
+ bottom: 'swDrawingViewOrientations_e.swDrawingBottomView',
45
+ isometric: 'swDrawingViewOrientations_e.swDrawingIsometricView'
46
+ };
47
+ const viewTypes = {
48
+ standard: `
49
+ ' Create standard view
50
+ Set swView = swDraw.CreateDrawViewFromModelView3( _
51
+ "${args.modelPath}", _
52
+ "*${args.viewOrientation || 'Front'}", _
53
+ ${args.position.x / 1000}, ${args.position.y / 1000}, 0)
54
+
55
+ If Not swView Is Nothing Then
56
+ swView.ScaleDecimal = ${args.scale || 1}
57
+ MsgBox "Standard view created"
58
+ End If`,
59
+ projected: `
60
+ ' Create projected view from parent
61
+ Set swParentView = swDraw.GetFirstView ' Get sheet
62
+ Set swParentView = swParentView.GetNextView ' Get first view
63
+
64
+ If Not swParentView Is Nothing Then
65
+ Set swView = swDraw.CreateUnfoldedViewAt3( _
66
+ ${args.position.x / 1000}, ${args.position.y / 1000}, 0, False)
67
+
68
+ If Not swView Is Nothing Then
69
+ MsgBox "Projected view created"
70
+ End If
71
+ End If`,
72
+ section: `
73
+ ' Create section view
74
+ Set swParentView = swDraw.GetFirstView.GetNextView
75
+
76
+ If Not swParentView Is Nothing Then
77
+ ' Create section line
78
+ Set swSketchMgr = swDraw.SketchManager
79
+ swSketchMgr.InsertSketch False
80
+ swSketchMgr.CreateLine _
81
+ ${(args.sectionLine?.startX || 0) / 1000}, _
82
+ ${(args.sectionLine?.startY || 0) / 1000}, 0, _
83
+ ${(args.sectionLine?.endX || 100) / 1000}, _
84
+ ${(args.sectionLine?.endY || 0) / 1000}, 0
85
+ swSketchMgr.InsertSketch True
86
+
87
+ ' Create section view
88
+ Set swView = swDraw.CreateSectionViewAt5( _
89
+ ${args.position.x / 1000}, ${args.position.y / 1000}, 0, _
90
+ "Section A-A", _
91
+ swCreateSectionViewOptions_e.swCreateSectionView_DisplaySurfaceCut, _
92
+ "", 0)
93
+
94
+ If Not swView Is Nothing Then
95
+ MsgBox "Section view created"
96
+ End If
97
+ End If`,
98
+ detail: `
99
+ ' Create detail view
100
+ Set swParentView = swDraw.GetFirstView.GetNextView
101
+
102
+ If Not swParentView Is Nothing Then
103
+ ' Create detail circle
104
+ Set swSketchMgr = swDraw.SketchManager
105
+ swSketchMgr.InsertSketch False
106
+ swSketchMgr.CreateCircle _
107
+ ${(args.detailCircle?.centerX || 0) / 1000}, _
108
+ ${(args.detailCircle?.centerY || 0) / 1000}, 0, _
109
+ ${(args.detailCircle?.radius || 10) / 1000}
110
+ swSketchMgr.InsertSketch True
111
+
112
+ ' Create detail view
113
+ Set swView = swDraw.CreateDetailViewAt4( _
114
+ ${args.position.x / 1000}, ${args.position.y / 1000}, 0, _
115
+ swDetViewStyle_e.swDetViewSTANDARD, _
116
+ ${args.scale || 2}, _
117
+ True, "Detail A", _
118
+ swDetCircleShowType_e.swDetCircleCIRCLE, _
119
+ True, False, False)
120
+
121
+ If Not swView Is Nothing Then
122
+ MsgBox "Detail view created"
123
+ End If
124
+ End If`
125
+ };
126
+ return `
127
+ Sub CreateDrawingView_${args.viewType}()
128
+ Dim swApp As SldWorks.SldWorks
129
+ Dim swModel As SldWorks.ModelDoc2
130
+ Dim swDraw As SldWorks.DrawingDoc
131
+ Dim swView As SldWorks.View
132
+ Dim swParentView As SldWorks.View
133
+ Dim swSketchMgr As SldWorks.SketchManager
134
+
135
+ Set swApp = Application.SldWorks
136
+ Set swModel = swApp.ActiveDoc
137
+
138
+ If swModel Is Nothing Then
139
+ MsgBox "No active document"
140
+ Exit Sub
141
+ End If
142
+
143
+ If swModel.GetType <> swDocumentTypes_e.swDocDRAWING Then
144
+ MsgBox "Please open a drawing document"
145
+ Exit Sub
146
+ End If
147
+
148
+ Set swDraw = swModel
149
+
150
+ ${viewTypes[args.viewType] || viewTypes.standard}
151
+
152
+ swModel.ViewZoomtofit2
153
+ swModel.EditRebuild3
154
+ End Sub`;
155
+ }
156
+ },
157
+ {
158
+ name: 'vba_drawing_dimensions',
159
+ description: 'Generate VBA for adding dimensions to drawings',
160
+ inputSchema: z.object({
161
+ dimensionType: z.enum([
162
+ 'linear', 'angular', 'radial', 'diameter', 'ordinate',
163
+ 'chamfer', 'arc_length', 'coordinate'
164
+ ]),
165
+ viewName: z.string().optional().describe('Name of the view'),
166
+ entities: z.array(z.object({
167
+ type: z.enum(['edge', 'vertex', 'face']),
168
+ name: z.string()
169
+ })).optional(),
170
+ position: z.object({
171
+ x: z.number(),
172
+ y: z.number()
173
+ }),
174
+ tolerance: z.object({
175
+ type: z.enum(['bilateral', 'limit', 'symmetric', 'basic', 'min', 'max']).optional(),
176
+ upper: z.number().optional(),
177
+ lower: z.number().optional()
178
+ }).optional(),
179
+ prefix: z.string().optional(),
180
+ suffix: z.string().optional()
181
+ }),
182
+ handler: (args) => {
183
+ return `
184
+ Sub AddDimension_${args.dimensionType}()
185
+ Dim swApp As SldWorks.SldWorks
186
+ Dim swModel As SldWorks.ModelDoc2
187
+ Dim swDraw As SldWorks.DrawingDoc
188
+ Dim swView As SldWorks.View
189
+ Dim swDispDim As SldWorks.DisplayDimension
190
+ Dim swDim As SldWorks.Dimension
191
+ Dim swTol As SldWorks.DimensionTolerance
192
+
193
+ Set swApp = Application.SldWorks
194
+ Set swModel = swApp.ActiveDoc
195
+
196
+ If swModel Is Nothing Or swModel.GetType <> swDocumentTypes_e.swDocDRAWING Then
197
+ MsgBox "Please open a drawing document"
198
+ Exit Sub
199
+ End If
200
+
201
+ Set swDraw = swModel
202
+
203
+ ' Get the view
204
+ Set swView = swDraw.GetFirstView ' Sheet
205
+ Set swView = swView.GetNextView ' First view
206
+ ${args.viewName ? `
207
+ ' Find specific view
208
+ Do While Not swView Is Nothing
209
+ If swView.Name = "${args.viewName}" Then Exit Do
210
+ Set swView = swView.GetNextView
211
+ Loop` : ''}
212
+
213
+ If swView Is Nothing Then
214
+ MsgBox "View not found"
215
+ Exit Sub
216
+ End If
217
+
218
+ ' Activate view
219
+ swDraw.ActivateView swView.Name
220
+
221
+ ${args.entities && args.entities.length > 0 ? `
222
+ ' Select entities
223
+ ${args.entities.map((entity, i) => `
224
+ swModel.Extension.SelectByID2 "${entity.name}", "${entity.type.toUpperCase()}", _
225
+ 0, 0, 0, ${i > 0 ? 'True' : 'False'}, 0, Nothing, 0`).join('')}` : ''}
226
+
227
+ ' Add dimension based on type
228
+ ${args.dimensionType === 'linear' ? `
229
+ Set swDispDim = swModel.AddDimension2( _
230
+ ${args.position.x / 1000}, ${args.position.y / 1000}, 0)` : ''}
231
+
232
+ ${args.dimensionType === 'angular' ? `
233
+ Set swDispDim = swModel.AddAngularDimension2( _
234
+ ${args.position.x / 1000}, ${args.position.y / 1000}, 0)` : ''}
235
+
236
+ ${args.dimensionType === 'radial' ? `
237
+ Set swDispDim = swModel.AddRadialDimension2( _
238
+ ${args.position.x / 1000}, ${args.position.y / 1000}, 0)` : ''}
239
+
240
+ ${args.dimensionType === 'diameter' ? `
241
+ Set swDispDim = swModel.AddDiameterDimension2( _
242
+ ${args.position.x / 1000}, ${args.position.y / 1000}, 0)` : ''}
243
+
244
+ ${args.dimensionType === 'ordinate' ? `
245
+ Set swDispDim = swModel.AddOrdinateDimension2( _
246
+ 0, ${args.position.x / 1000}, ${args.position.y / 1000}, 0)` : ''}
247
+
248
+ If Not swDispDim Is Nothing Then
249
+ Set swDim = swDispDim.GetDimension2(0)
250
+
251
+ ${args.prefix ? `swDim.SetText swTextPrefix, "${args.prefix}"` : ''}
252
+ ${args.suffix ? `swDim.SetText swTextSuffix, "${args.suffix}"` : ''}
253
+
254
+ ${args.tolerance ? `
255
+ ' Set tolerance
256
+ Set swTol = swDim.Tolerance
257
+ swTol.Type = ${args.tolerance.type === 'bilateral' ? 'swTolBILATERAL' :
258
+ args.tolerance.type === 'limit' ? 'swTolLIMIT' :
259
+ args.tolerance.type === 'symmetric' ? 'swTolSYMMETRIC' :
260
+ args.tolerance.type === 'basic' ? 'swTolBASIC' :
261
+ 'swTolNONE'}
262
+ ${args.tolerance.upper ? `swTol.SetValues 0, ${args.tolerance.upper / 1000}, ${args.tolerance.lower ? args.tolerance.lower / 1000 : 0}` : ''}` : ''}
263
+
264
+ MsgBox "${args.dimensionType} dimension added"
265
+ Else
266
+ MsgBox "Failed to add dimension"
267
+ End If
268
+
269
+ swModel.ClearSelection2 True
270
+ End Sub`;
271
+ }
272
+ },
273
+ {
274
+ name: 'vba_drawing_annotations',
275
+ description: 'Generate VBA for adding annotations to drawings',
276
+ inputSchema: z.object({
277
+ annotationType: z.enum([
278
+ 'note', 'balloon', 'datum', 'geometric_tolerance',
279
+ 'surface_finish', 'weld_symbol', 'center_mark', 'centerline'
280
+ ]),
281
+ text: z.string().optional().describe('Annotation text'),
282
+ position: z.object({
283
+ x: z.number(),
284
+ y: z.number()
285
+ }),
286
+ leaderPoints: z.array(z.object({
287
+ x: z.number(),
288
+ y: z.number()
289
+ })).optional(),
290
+ style: z.object({
291
+ fontSize: z.number().optional(),
292
+ bold: z.boolean().optional(),
293
+ italic: z.boolean().optional(),
294
+ underline: z.boolean().optional()
295
+ }).optional(),
296
+ balloonStyle: z.enum(['circular', 'triangle', 'hexagon', 'box', 'diamond']).optional(),
297
+ itemNumber: z.number().optional()
298
+ }),
299
+ handler: (args) => {
300
+ const annotations = {
301
+ note: `
302
+ ' Create note
303
+ Set swNote = swModel.InsertNote("${args.text || 'Note Text'}")
304
+
305
+ If Not swNote Is Nothing Then
306
+ Set swAnn = swNote.GetAnnotation
307
+ swAnn.SetPosition ${args.position.x / 1000}, ${args.position.y / 1000}, 0
308
+
309
+ ${args.style ? `
310
+ ' Set text format
311
+ Dim swTextFormat As SldWorks.TextFormat
312
+ Set swTextFormat = swAnn.GetTextFormat(0)
313
+ ${args.style.fontSize ? `swTextFormat.CharHeight = ${args.style.fontSize / 1000}` : ''}
314
+ ${args.style.bold ? `swTextFormat.Bold = True` : ''}
315
+ ${args.style.italic ? `swTextFormat.Italic = True` : ''}
316
+ ${args.style.underline ? `swTextFormat.Underline = True` : ''}
317
+ swNote.SetTextFormat 0, False, swTextFormat` : ''}
318
+
319
+ ${args.leaderPoints && args.leaderPoints.length > 0 ? `
320
+ ' Add leader
321
+ swNote.SetBalloon swBalloonStyle_e.swBS_None, swBalloonFit_e.swBF_Tightest
322
+ Dim leaderInfo As SldWorks.Leader
323
+ Set leaderInfo = swNote.GetLeader
324
+ leaderInfo.SetLeader2 True, swLeaderSide_e.swLS_SMART, True, False, False, False` : ''}
325
+
326
+ MsgBox "Note added"
327
+ End If`,
328
+ balloon: `
329
+ ' Create balloon
330
+ Set swNote = swModel.InsertNote("${args.itemNumber || '1'}")
331
+
332
+ If Not swNote Is Nothing Then
333
+ Set swAnn = swNote.GetAnnotation
334
+ swAnn.SetPosition ${args.position.x / 1000}, ${args.position.y / 1000}, 0
335
+
336
+ ' Set balloon style
337
+ swNote.SetBalloon _
338
+ ${args.balloonStyle === 'circular' ? 'swBS_Circular' :
339
+ args.balloonStyle === 'triangle' ? 'swBS_Triangle' :
340
+ args.balloonStyle === 'hexagon' ? 'swBS_Hexagon' :
341
+ args.balloonStyle === 'box' ? 'swBS_Box' :
342
+ 'swBS_Circular'}, _
343
+ swBF_Tightest
344
+
345
+ ${args.leaderPoints && args.leaderPoints.length > 0 ? `
346
+ ' Attach leader to component
347
+ swModel.Extension.SelectByID2 "", "EDGE", _
348
+ ${args.leaderPoints[0].x / 1000}, _
349
+ ${args.leaderPoints[0].y / 1000}, 0, _
350
+ False, 0, Nothing, 0
351
+
352
+ Dim leaderInfo As SldWorks.Leader
353
+ Set leaderInfo = swNote.GetLeader
354
+ leaderInfo.SetLeader2 True, swLS_SMART, True, False, False, False` : ''}
355
+
356
+ MsgBox "Balloon added"
357
+ End If`,
358
+ geometric_tolerance: `
359
+ ' Create geometric tolerance
360
+ Set swGtol = swModel.InsertGtol
361
+
362
+ If Not swGtol Is Nothing Then
363
+ swGtol.SetFrameValues 1, "${args.text || '⟂0.01 A'}", "", "", "", ""
364
+ Set swAnn = swGtol.GetAnnotation
365
+ swAnn.SetPosition ${args.position.x / 1000}, ${args.position.y / 1000}, 0
366
+
367
+ MsgBox "Geometric tolerance added"
368
+ End If`,
369
+ surface_finish: `
370
+ ' Create surface finish symbol
371
+ Set swSFSymbol = swModel.InsertSurfaceFinishSymbol3( _
372
+ swSurfaceFinishStandard_e.swSurfaceFinishStandard_ISO, _
373
+ swSFLaySymType_e.swSFLaySym_None, _
374
+ swSurfaceFinishSymbol_e.swSFMachiningRequired, _
375
+ "${args.text || '1.6'}", "", "", "", "", "")
376
+
377
+ If Not swSFSymbol Is Nothing Then
378
+ Set swAnn = swSFSymbol.GetAnnotation
379
+ swAnn.SetPosition ${args.position.x / 1000}, ${args.position.y / 1000}, 0
380
+
381
+ MsgBox "Surface finish symbol added"
382
+ End If`,
383
+ weld_symbol: `
384
+ ' Create weld symbol
385
+ Set swWeldSymbol = swModel.InsertWeldSymbol3
386
+
387
+ If Not swWeldSymbol Is Nothing Then
388
+ ' Configure weld symbol
389
+ swWeldSymbol.SetWeldSymbol True, "Fillet", "${args.text || '5'}", "", "", ""
390
+ Set swAnn = swWeldSymbol.GetAnnotation
391
+ swAnn.SetPosition ${args.position.x / 1000}, ${args.position.y / 1000}, 0
392
+
393
+ MsgBox "Weld symbol added"
394
+ End If`,
395
+ center_mark: `
396
+ ' Create center mark
397
+ swModel.Extension.SelectByID2 "", "EDGE", _
398
+ ${args.position.x / 1000}, ${args.position.y / 1000}, 0, _
399
+ False, 0, Nothing, 0
400
+
401
+ Set swCenterMark = swModel.AddCenterMark( _
402
+ swCenterMarkConnectionLine_e.swCenterMark_ConnectionLines, _
403
+ swCenterMarkGapDistance_e.swCenterMark_GapDistance)
404
+
405
+ If Not swCenterMark Is Nothing Then
406
+ MsgBox "Center mark added"
407
+ End If`
408
+ };
409
+ return `
410
+ Sub AddAnnotation_${args.annotationType}()
411
+ Dim swApp As SldWorks.SldWorks
412
+ Dim swModel As SldWorks.ModelDoc2
413
+ Dim swDraw As SldWorks.DrawingDoc
414
+ Dim swNote As SldWorks.Note
415
+ Dim swAnn As SldWorks.Annotation
416
+ Dim swGtol As SldWorks.Gtol
417
+ Dim swSFSymbol As SldWorks.SurfaceFinishSymbol
418
+ Dim swWeldSymbol As SldWorks.WeldSymbol
419
+ Dim swCenterMark As SldWorks.CenterMark
420
+
421
+ Set swApp = Application.SldWorks
422
+ Set swModel = swApp.ActiveDoc
423
+
424
+ If swModel Is Nothing Or swModel.GetType <> swDocumentTypes_e.swDocDRAWING Then
425
+ MsgBox "Please open a drawing document"
426
+ Exit Sub
427
+ End If
428
+
429
+ Set swDraw = swModel
430
+
431
+ ${annotations[args.annotationType] || annotations.note}
432
+
433
+ swModel.EditRebuild3
434
+ End Sub`;
435
+ }
436
+ },
437
+ {
438
+ name: 'vba_drawing_tables',
439
+ description: 'Generate VBA for creating tables in drawings',
440
+ inputSchema: z.object({
441
+ tableType: z.enum(['general', 'hole', 'revision', 'bom', 'weldment_cutlist']),
442
+ position: z.object({
443
+ x: z.number(),
444
+ y: z.number()
445
+ }),
446
+ rows: z.number().optional(),
447
+ columns: z.number().optional(),
448
+ headers: z.array(z.string()).optional(),
449
+ data: z.array(z.array(z.string())).optional(),
450
+ template: z.string().optional().describe('Path to table template'),
451
+ anchorType: z.enum(['top_left', 'top_right', 'bottom_left', 'bottom_right']).optional()
452
+ }),
453
+ handler: (args) => {
454
+ return `
455
+ Sub CreateTable_${args.tableType}()
456
+ Dim swApp As SldWorks.SldWorks
457
+ Dim swModel As SldWorks.ModelDoc2
458
+ Dim swDraw As SldWorks.DrawingDoc
459
+ Dim swTable As SldWorks.TableAnnotation
460
+ Dim swBOMTable As SldWorks.BomTableAnnotation
461
+ Dim i As Integer, j As Integer
462
+
463
+ Set swApp = Application.SldWorks
464
+ Set swModel = swApp.ActiveDoc
465
+
466
+ If swModel Is Nothing Or swModel.GetType <> swDocumentTypes_e.swDocDRAWING Then
467
+ MsgBox "Please open a drawing document"
468
+ Exit Sub
469
+ End If
470
+
471
+ Set swDraw = swModel
472
+
473
+ ${args.tableType === 'general' ? `
474
+ ' Create general table
475
+ Set swTable = swDraw.InsertTableAnnotation2( _
476
+ False, ${args.position.x / 1000}, ${args.position.y / 1000}, _
477
+ ${args.anchorType === 'top_right' ? 'swBOMConfigurationAnchor_TopRight' :
478
+ args.anchorType === 'bottom_left' ? 'swBOMConfigurationAnchor_BottomLeft' :
479
+ args.anchorType === 'bottom_right' ? 'swBOMConfigurationAnchor_BottomRight' :
480
+ 'swBOMConfigurationAnchor_TopLeft'}, _
481
+ "${args.template || ''}", _
482
+ ${args.rows || 5}, ${args.columns || 3})
483
+
484
+ If Not swTable Is Nothing Then
485
+ ' Set headers
486
+ ${args.headers ? args.headers.map((header, i) => `
487
+ swTable.Text(0, ${i}) = "${header}"`).join('\n ') : ''}
488
+
489
+ ' Set data
490
+ ${args.data ? args.data.map((row, i) => row.map((cell, j) => `
491
+ swTable.Text(${i + 1}, ${j}) = "${cell}"`).join('')).join('') : ''}
492
+
493
+ MsgBox "General table created"
494
+ End If` : ''}
495
+
496
+ ${args.tableType === 'hole' ? `
497
+ ' Create hole table
498
+ Set swTable = swDraw.InsertHoleTable2( _
499
+ "${args.template || ''}", _
500
+ ${args.position.x / 1000}, ${args.position.y / 1000}, _
501
+ ${args.anchorType === 'top_right' ? 'swBOMConfigurationAnchor_TopRight' :
502
+ args.anchorType === 'bottom_left' ? 'swBOMConfigurationAnchor_BottomLeft' :
503
+ args.anchorType === 'bottom_right' ? 'swBOMConfigurationAnchor_BottomRight' :
504
+ 'swBOMConfigurationAnchor_TopLeft'}, _
505
+ "A", True)
506
+
507
+ If Not swTable Is Nothing Then
508
+ MsgBox "Hole table created"
509
+ End If` : ''}
510
+
511
+ ${args.tableType === 'revision' ? `
512
+ ' Create revision table
513
+ Set swTable = swDraw.InsertRevisionTable2( _
514
+ True, ${args.position.x / 1000}, ${args.position.y / 1000}, _
515
+ ${args.anchorType === 'top_right' ? 'swBOMConfigurationAnchor_TopRight' :
516
+ args.anchorType === 'bottom_left' ? 'swBOMConfigurationAnchor_BottomLeft' :
517
+ args.anchorType === 'bottom_right' ? 'swBOMConfigurationAnchor_BottomRight' :
518
+ 'swBOMConfigurationAnchor_TopLeft'}, _
519
+ "${args.template || ''}")
520
+
521
+ If Not swTable Is Nothing Then
522
+ ' Add revision
523
+ swTable.AddRevision "A"
524
+ swTable.Text(1, 0) = "A"
525
+ swTable.Text(1, 1) = Format(Date, "mm/dd/yyyy")
526
+ swTable.Text(1, 2) = "Initial Release"
527
+ swTable.Text(1, 3) = Application.UserName
528
+
529
+ MsgBox "Revision table created"
530
+ End If` : ''}
531
+
532
+ ${args.tableType === 'bom' ? `
533
+ ' Create BOM table
534
+ Dim swBOMFeature As SldWorks.BomFeature
535
+ Set swBOMFeature = swDraw.FeatureManager.InsertBomTable3( _
536
+ "${args.template || ''}", _
537
+ ${args.position.x / 1000}, ${args.position.y / 1000}, _
538
+ swBomType_e.swBomType_PartsOnly, _
539
+ "", _
540
+ swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft, _
541
+ swBomStandard_e.swBomStandard_BomTable, _
542
+ False)
543
+
544
+ If Not swBOMFeature Is Nothing Then
545
+ Set swBOMTable = swBOMFeature.GetTableAnnotations(0)
546
+ Set swTable = swBOMTable
547
+
548
+ ' Configure BOM
549
+ swTable.Title = "BILL OF MATERIALS"
550
+
551
+ MsgBox "BOM table created"
552
+ End If` : ''}
553
+
554
+ ' Format table
555
+ If Not swTable Is Nothing Then
556
+ ' Auto-fit columns
557
+ For j = 0 To swTable.ColumnCount - 1
558
+ swTable.SetColumnWidth j, -1, swTableRowColSizeType_e.swAutoSizeFitText
559
+ Next j
560
+
561
+ ' Set row height
562
+ For i = 0 To swTable.RowCount - 1
563
+ swTable.SetRowHeight i, 10 / 1000, swTableRowColSizeType_e.swManualSizing
564
+ Next i
565
+ End If
566
+
567
+ swModel.EditRebuild3
568
+ End Sub`;
569
+ }
570
+ },
571
+ {
572
+ name: 'vba_drawing_sheet_format',
573
+ description: 'Generate VBA for managing drawing sheets and formats',
574
+ inputSchema: z.object({
575
+ operation: z.enum(['create_sheet', 'modify_format', 'title_block', 'border']),
576
+ sheetName: z.string().optional(),
577
+ sheetSize: z.enum(['A4', 'A3', 'A2', 'A1', 'A0', 'Letter', 'Legal', 'Tabloid', 'Custom']).optional(),
578
+ customSize: z.object({
579
+ width: z.number(),
580
+ height: z.number()
581
+ }).optional(),
582
+ scale: z.string().optional().describe('Sheet scale (e.g., "1:2")'),
583
+ templatePath: z.string().optional(),
584
+ titleBlockData: z.record(z.string()).optional()
585
+ }),
586
+ handler: (args) => {
587
+ const sheetSizes = {
588
+ A4: [210, 297],
589
+ A3: [297, 420],
590
+ A2: [420, 594],
591
+ A1: [594, 841],
592
+ A0: [841, 1189],
593
+ Letter: [215.9, 279.4],
594
+ Legal: [215.9, 355.6],
595
+ Tabloid: [279.4, 431.8]
596
+ };
597
+ return `
598
+ Sub ManageDrawingSheet_${args.operation}()
599
+ Dim swApp As SldWorks.SldWorks
600
+ Dim swModel As SldWorks.ModelDoc2
601
+ Dim swDraw As SldWorks.DrawingDoc
602
+ Dim swSheet As SldWorks.Sheet
603
+ Dim vSheetProps As Variant
604
+ Dim bRet As Boolean
605
+
606
+ Set swApp = Application.SldWorks
607
+ Set swModel = swApp.ActiveDoc
608
+
609
+ If swModel Is Nothing Or swModel.GetType <> swDocumentTypes_e.swDocDRAWING Then
610
+ MsgBox "Please open a drawing document"
611
+ Exit Sub
612
+ End If
613
+
614
+ Set swDraw = swModel
615
+
616
+ ${args.operation === 'create_sheet' ? `
617
+ ' Create new sheet
618
+ bRet = swDraw.NewSheet4( _
619
+ "${args.sheetName || 'NewSheet'}", _
620
+ ${args.sheetSize && args.sheetSize !== 'Custom' ?
621
+ `swDwgPaperSizes_e.swDwgPaper${args.sheetSize}size` :
622
+ 'swDwgPaperSizes_e.swDwgPapersUserDefined'}, _
623
+ ${args.templatePath ? `"${args.templatePath}"` : 'swDwgTemplates_e.swDwgTemplateNone'}, _
624
+ ${args.scale ? args.scale.split(':')[0] : '1'}, _
625
+ ${args.scale ? args.scale.split(':')[1] : '1'}, _
626
+ True, "", _
627
+ ${args.customSize ? args.customSize.width / 1000 : sheetSizes[args.sheetSize || 'A4'][0] / 1000}, _
628
+ ${args.customSize ? args.customSize.height / 1000 : sheetSizes[args.sheetSize || 'A4'][1] / 1000}, _
629
+ "Default", True)
630
+
631
+ If bRet Then
632
+ MsgBox "New sheet created: ${args.sheetName || 'New Sheet'}"
633
+ Else
634
+ MsgBox "Failed to create sheet"
635
+ End If` : ''}
636
+
637
+ ${args.operation === 'modify_format' ? `
638
+ ' Modify sheet format
639
+ Set swSheet = swDraw.GetCurrentSheet
640
+
641
+ If Not swSheet Is Nothing Then
642
+ ' Set sheet properties
643
+ vSheetProps = swSheet.GetProperties2
644
+
645
+ ' Update scale
646
+ ${args.scale ? `
647
+ Dim scaleNum As Double, scaleDenom As Double
648
+ scaleNum = ${args.scale.split(':')[0]}
649
+ scaleDenom = ${args.scale.split(':')[1]}
650
+ swSheet.SetScale scaleNum, scaleDenom, True, True` : ''}
651
+
652
+ ' Update size
653
+ ${args.sheetSize ? `
654
+ swSheet.SetSize _
655
+ ${sheetSizes[args.sheetSize][0] / 1000}, _
656
+ ${sheetSizes[args.sheetSize][1] / 1000}` : ''}
657
+
658
+ MsgBox "Sheet format updated"
659
+ End If` : ''}
660
+
661
+ ${args.operation === 'title_block' ? `
662
+ ' Update title block
663
+ Set swSheet = swDraw.GetCurrentSheet
664
+
665
+ If Not swSheet Is Nothing Then
666
+ ' Get title block
667
+ Dim swView As SldWorks.View
668
+ Set swView = swDraw.GetFirstView ' This is the sheet itself
669
+
670
+ ' Find and update title block notes
671
+ ${args.titleBlockData ? Object.entries(args.titleBlockData).map(([key, value]) => `
672
+ swModel.Extension.SelectByID2 "$PRPSHEET:\\"${key}\\"", "NOTE", 0, 0, 0, False, 0, Nothing, 0
673
+ Dim swNote As SldWorks.Note
674
+ Set swNote = swModel.SelectionManager.GetSelectedObject6(1, -1)
675
+ If Not swNote Is Nothing Then
676
+ swNote.SetText "${value}"
677
+ End If`).join('\n ') : ''}
678
+
679
+ ' Update custom properties
680
+ Dim swCustProp As SldWorks.CustomPropertyManager
681
+ Set swCustProp = swModel.Extension.CustomPropertyManager("")
682
+
683
+ ${args.titleBlockData ? Object.entries(args.titleBlockData).map(([key, value]) => `
684
+ swCustProp.Add3 "${key}", swCustomInfoType_e.swCustomInfoText, "${value}", _
685
+ swCustomPropertyAddOption_e.swCustomPropertyReplaceValue`).join('\n ') : ''}
686
+
687
+ MsgBox "Title block updated"
688
+ End If` : ''}
689
+
690
+ swModel.EditRebuild3
691
+ End Sub`;
692
+ }
693
+ }
694
+ ];
695
+ //# sourceMappingURL=vba-drawing.js.map