solidworks-mcp-server 3.0.9 → 3.1.3

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 (243) hide show
  1. package/CHANGELOG.md +175 -131
  2. package/LICENSE +20 -20
  3. package/README.md +195 -444
  4. package/dist/adapters/circuit-breaker.d.ts +84 -0
  5. package/dist/adapters/circuit-breaker.d.ts.map +1 -0
  6. package/dist/adapters/circuit-breaker.js +228 -0
  7. package/dist/adapters/circuit-breaker.js.map +1 -0
  8. package/dist/adapters/connection-pool.d.ts +83 -0
  9. package/dist/adapters/connection-pool.d.ts.map +1 -0
  10. package/dist/adapters/connection-pool.js +282 -0
  11. package/dist/adapters/connection-pool.js.map +1 -0
  12. package/dist/adapters/edge-adapter.d.ts +43 -0
  13. package/dist/adapters/edge-adapter.d.ts.map +1 -0
  14. package/dist/adapters/edge-adapter.js +417 -0
  15. package/dist/adapters/edge-adapter.js.map +1 -0
  16. package/dist/adapters/factory.d.ts +60 -0
  17. package/dist/adapters/factory.d.ts.map +1 -0
  18. package/dist/adapters/factory.js +212 -0
  19. package/dist/adapters/factory.js.map +1 -0
  20. package/dist/adapters/feature-complexity-analyzer.d.ts +102 -0
  21. package/dist/adapters/feature-complexity-analyzer.d.ts.map +1 -0
  22. package/dist/adapters/feature-complexity-analyzer.js +322 -0
  23. package/dist/adapters/feature-complexity-analyzer.js.map +1 -0
  24. package/dist/adapters/macro-generator.d.ts +30 -0
  25. package/dist/adapters/macro-generator.d.ts.map +1 -0
  26. package/dist/adapters/macro-generator.js +524 -0
  27. package/dist/adapters/macro-generator.js.map +1 -0
  28. package/dist/adapters/mock-solidworks-adapter.d.ts +92 -0
  29. package/dist/adapters/mock-solidworks-adapter.d.ts.map +1 -0
  30. package/dist/adapters/mock-solidworks-adapter.js +367 -0
  31. package/dist/adapters/mock-solidworks-adapter.js.map +1 -0
  32. package/dist/adapters/types.d.ts +376 -0
  33. package/dist/adapters/types.d.ts.map +1 -0
  34. package/dist/adapters/types.js +261 -0
  35. package/dist/adapters/types.js.map +1 -0
  36. package/dist/adapters/winax-adapter-enhanced.d.ts +55 -0
  37. package/dist/adapters/winax-adapter-enhanced.d.ts.map +1 -0
  38. package/dist/adapters/winax-adapter-enhanced.js +601 -0
  39. package/dist/adapters/winax-adapter-enhanced.js.map +1 -0
  40. package/dist/adapters/winax-adapter.d.ts +55 -0
  41. package/dist/adapters/winax-adapter.d.ts.map +1 -0
  42. package/dist/adapters/winax-adapter.js +667 -0
  43. package/dist/adapters/winax-adapter.js.map +1 -0
  44. package/dist/api/stainless-api.d.ts +29 -0
  45. package/dist/api/stainless-api.d.ts.map +1 -0
  46. package/dist/api/stainless-api.js +408 -0
  47. package/dist/api/stainless-api.js.map +1 -0
  48. package/dist/cache/manager.d.ts.map +1 -1
  49. package/dist/cache/manager.js +4 -3
  50. package/dist/cache/manager.js.map +1 -1
  51. package/dist/core/interfaces/core-abstractions.d.ts.map +1 -1
  52. package/dist/core/interfaces/core-abstractions.js.map +1 -1
  53. package/dist/db/connection.js +4 -4
  54. package/dist/db/connection.js.map +1 -1
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +86 -79
  57. package/dist/index.js.map +1 -1
  58. package/dist/knowledge/chromadb.d.ts.map +1 -1
  59. package/dist/knowledge/chromadb.js +5 -3
  60. package/dist/knowledge/chromadb.js.map +1 -1
  61. package/dist/macro/recorder.d.ts +1 -1
  62. package/dist/macro/recorder.d.ts.map +1 -1
  63. package/dist/macro/recorder.js +10 -10
  64. package/dist/macro/recorder.js.map +1 -1
  65. package/dist/resources/base.js +10 -10
  66. package/dist/resources/base.js.map +1 -1
  67. package/dist/resources/design-table.d.ts +10 -12
  68. package/dist/resources/design-table.d.ts.map +1 -1
  69. package/dist/resources/design-table.js +42 -39
  70. package/dist/resources/design-table.js.map +1 -1
  71. package/dist/resources/pdm.d.ts +44 -45
  72. package/dist/resources/pdm.d.ts.map +1 -1
  73. package/dist/resources/pdm.js +118 -79
  74. package/dist/resources/pdm.js.map +1 -1
  75. package/dist/resources/registry.d.ts +1 -1
  76. package/dist/resources/registry.d.ts.map +1 -1
  77. package/dist/resources/registry.js +1 -1
  78. package/dist/shared/constants/solidworks-constants.d.ts.map +1 -1
  79. package/dist/shared/constants/solidworks-constants.js +9 -9
  80. package/dist/shared/constants/solidworks-constants.js.map +1 -1
  81. package/dist/solidworks/api.d.ts +8 -3
  82. package/dist/solidworks/api.d.ts.map +1 -1
  83. package/dist/solidworks/api.js +599 -134
  84. package/dist/solidworks/api.js.map +1 -1
  85. package/dist/state/store.d.ts +1 -1
  86. package/dist/state/store.d.ts.map +1 -1
  87. package/dist/state/store.js +14 -14
  88. package/dist/state/store.js.map +1 -1
  89. package/dist/tools/analysis.d.ts +12 -2
  90. package/dist/tools/analysis.d.ts.map +1 -1
  91. package/dist/tools/analysis.js +141 -31
  92. package/dist/tools/analysis.js.map +1 -1
  93. package/dist/tools/diagnostics.d.ts +1 -1
  94. package/dist/tools/diagnostics.d.ts.map +1 -1
  95. package/dist/tools/diagnostics.js +2 -2
  96. package/dist/tools/diagnostics.js.map +1 -1
  97. package/dist/tools/drawing.d.ts +2 -2
  98. package/dist/tools/drawing.d.ts.map +1 -1
  99. package/dist/tools/drawing.js +94 -10
  100. package/dist/tools/drawing.js.map +1 -1
  101. package/dist/tools/enhanced-drawing.d.ts +1 -1
  102. package/dist/tools/enhanced-drawing.d.ts.map +1 -1
  103. package/dist/tools/enhanced-drawing.js +10 -13
  104. package/dist/tools/enhanced-drawing.js.map +1 -1
  105. package/dist/tools/export.d.ts +1 -1
  106. package/dist/tools/export.d.ts.map +1 -1
  107. package/dist/tools/export.js +88 -14
  108. package/dist/tools/export.js.map +1 -1
  109. package/dist/tools/extrusion-helper.d.ts +15 -0
  110. package/dist/tools/extrusion-helper.d.ts.map +1 -0
  111. package/dist/tools/extrusion-helper.js +61 -0
  112. package/dist/tools/extrusion-helper.js.map +1 -0
  113. package/dist/tools/macro-security.d.ts +2 -2
  114. package/dist/tools/macro-security.d.ts.map +1 -1
  115. package/dist/tools/macro-security.js +2 -2
  116. package/dist/tools/macro-security.js.map +1 -1
  117. package/dist/tools/modeling.d.ts +2 -2
  118. package/dist/tools/modeling.d.ts.map +1 -1
  119. package/dist/tools/modeling.js +6 -6
  120. package/dist/tools/modeling.js.map +1 -1
  121. package/dist/tools/native-macro.d.ts +1 -1
  122. package/dist/tools/native-macro.d.ts.map +1 -1
  123. package/dist/tools/native-macro.js +246 -239
  124. package/dist/tools/native-macro.js.map +1 -1
  125. package/dist/tools/sketch.d.ts +28 -28
  126. package/dist/tools/sketch.d.ts.map +1 -1
  127. package/dist/tools/sketch.js +202 -136
  128. package/dist/tools/sketch.js.map +1 -1
  129. package/dist/tools/template-manager.d.ts +5 -5
  130. package/dist/tools/template-manager.d.ts.map +1 -1
  131. package/dist/tools/template-manager.js +66 -65
  132. package/dist/tools/template-manager.js.map +1 -1
  133. package/dist/tools/vba-advanced.d.ts +10 -10
  134. package/dist/tools/vba-advanced.d.ts.map +1 -1
  135. package/dist/tools/vba-advanced.js +791 -708
  136. package/dist/tools/vba-advanced.js.map +1 -1
  137. package/dist/tools/vba-assembly.d.ts +10 -10
  138. package/dist/tools/vba-assembly.d.ts.map +1 -1
  139. package/dist/tools/vba-assembly.js +562 -500
  140. package/dist/tools/vba-assembly.js.map +1 -1
  141. package/dist/tools/vba-drawing.d.ts +12 -12
  142. package/dist/tools/vba-drawing.d.ts.map +1 -1
  143. package/dist/tools/vba-drawing.js +681 -572
  144. package/dist/tools/vba-drawing.js.map +1 -1
  145. package/dist/tools/vba-file-management.d.ts +12 -12
  146. package/dist/tools/vba-file-management.d.ts.map +1 -1
  147. package/dist/tools/vba-file-management.js +662 -589
  148. package/dist/tools/vba-file-management.js.map +1 -1
  149. package/dist/tools/vba-part.d.ts +10 -10
  150. package/dist/tools/vba-part.d.ts.map +1 -1
  151. package/dist/tools/vba-part.js +484 -426
  152. package/dist/tools/vba-part.js.map +1 -1
  153. package/dist/tools/vba.d.ts +361 -361
  154. package/dist/tools/vba.d.ts.map +1 -1
  155. package/dist/tools/vba.js +67 -81
  156. package/dist/tools/vba.js.map +1 -1
  157. package/dist/utils/config.js +2 -2
  158. package/dist/utils/config.js.map +1 -1
  159. package/dist/utils/environment.d.ts +243 -0
  160. package/dist/utils/environment.d.ts.map +1 -0
  161. package/dist/utils/environment.js +207 -0
  162. package/dist/utils/environment.js.map +1 -0
  163. package/dist/utils/logger.d.ts.map +1 -1
  164. package/dist/utils/logger.js +6 -6
  165. package/dist/utils/logger.js.map +1 -1
  166. package/dist/utils/solidworks-config.d.ts +39 -0
  167. package/dist/utils/solidworks-config.d.ts.map +1 -0
  168. package/dist/utils/solidworks-config.js +156 -0
  169. package/dist/utils/solidworks-config.js.map +1 -0
  170. package/package.json +84 -84
  171. package/scripts/setup.js +70 -70
  172. package/dist/application/services/command-bus.d.ts +0 -39
  173. package/dist/application/services/command-bus.d.ts.map +0 -1
  174. package/dist/application/services/command-bus.js +0 -88
  175. package/dist/application/services/command-bus.js.map +0 -1
  176. package/dist/application/services/event-bus.d.ts +0 -31
  177. package/dist/application/services/event-bus.d.ts.map +0 -1
  178. package/dist/application/services/event-bus.js +0 -83
  179. package/dist/application/services/event-bus.js.map +0 -1
  180. package/dist/application/services/query-bus.d.ts +0 -30
  181. package/dist/application/services/query-bus.d.ts.map +0 -1
  182. package/dist/application/services/query-bus.js +0 -59
  183. package/dist/application/services/query-bus.js.map +0 -1
  184. package/dist/application/services/tool-registry.d.ts +0 -53
  185. package/dist/application/services/tool-registry.d.ts.map +0 -1
  186. package/dist/application/services/tool-registry.js +0 -81
  187. package/dist/application/services/tool-registry.js.map +0 -1
  188. package/dist/application/use-cases/analysis/index.d.ts +0 -13
  189. package/dist/application/use-cases/analysis/index.d.ts.map +0 -1
  190. package/dist/application/use-cases/analysis/index.js +0 -17
  191. package/dist/application/use-cases/analysis/index.js.map +0 -1
  192. package/dist/application/use-cases/drawing/index.d.ts +0 -13
  193. package/dist/application/use-cases/drawing/index.d.ts.map +0 -1
  194. package/dist/application/use-cases/drawing/index.js +0 -17
  195. package/dist/application/use-cases/drawing/index.js.map +0 -1
  196. package/dist/application/use-cases/export/index.d.ts +0 -13
  197. package/dist/application/use-cases/export/index.d.ts.map +0 -1
  198. package/dist/application/use-cases/export/index.js +0 -17
  199. package/dist/application/use-cases/export/index.js.map +0 -1
  200. package/dist/application/use-cases/macro/index.d.ts +0 -13
  201. package/dist/application/use-cases/macro/index.d.ts.map +0 -1
  202. package/dist/application/use-cases/macro/index.js +0 -17
  203. package/dist/application/use-cases/macro/index.js.map +0 -1
  204. package/dist/application/use-cases/modeling/index.d.ts +0 -56
  205. package/dist/application/use-cases/modeling/index.d.ts.map +0 -1
  206. package/dist/application/use-cases/modeling/index.js +0 -385
  207. package/dist/application/use-cases/modeling/index.js.map +0 -1
  208. package/dist/index.refactored.d.ts +0 -7
  209. package/dist/index.refactored.d.ts.map +0 -1
  210. package/dist/index.refactored.js +0 -254
  211. package/dist/index.refactored.js.map +0 -1
  212. package/dist/infrastructure/config/configuration-manager.d.ts +0 -381
  213. package/dist/infrastructure/config/configuration-manager.d.ts.map +0 -1
  214. package/dist/infrastructure/config/configuration-manager.js +0 -566
  215. package/dist/infrastructure/config/configuration-manager.js.map +0 -1
  216. package/dist/infrastructure/container/service-locator.d.ts +0 -14
  217. package/dist/infrastructure/container/service-locator.d.ts.map +0 -1
  218. package/dist/infrastructure/container/service-locator.js +0 -38
  219. package/dist/infrastructure/container/service-locator.js.map +0 -1
  220. package/dist/infrastructure/logging/logger.d.ts +0 -24
  221. package/dist/infrastructure/logging/logger.d.ts.map +0 -1
  222. package/dist/infrastructure/logging/logger.js +0 -65
  223. package/dist/infrastructure/logging/logger.js.map +0 -1
  224. package/dist/infrastructure/solidworks/solidworks-adapter.d.ts +0 -43
  225. package/dist/infrastructure/solidworks/solidworks-adapter.d.ts.map +0 -1
  226. package/dist/infrastructure/solidworks/solidworks-adapter.js +0 -527
  227. package/dist/infrastructure/solidworks/solidworks-adapter.js.map +0 -1
  228. package/dist/presentation/mcp/request-handler.d.ts +0 -41
  229. package/dist/presentation/mcp/request-handler.d.ts.map +0 -1
  230. package/dist/presentation/mcp/request-handler.js +0 -100
  231. package/dist/presentation/mcp/request-handler.js.map +0 -1
  232. package/dist/presentation/transformers/error-transformer.d.ts +0 -16
  233. package/dist/presentation/transformers/error-transformer.d.ts.map +0 -1
  234. package/dist/presentation/transformers/error-transformer.js +0 -44
  235. package/dist/presentation/transformers/error-transformer.js.map +0 -1
  236. package/dist/presentation/transformers/response-transformer.d.ts +0 -24
  237. package/dist/presentation/transformers/response-transformer.d.ts.map +0 -1
  238. package/dist/presentation/transformers/response-transformer.js +0 -102
  239. package/dist/presentation/transformers/response-transformer.js.map +0 -1
  240. package/dist/tools/drawing-analysis.d.ts +0 -9
  241. package/dist/tools/drawing-analysis.d.ts.map +0 -1
  242. package/dist/tools/drawing-analysis.js +0 -239
  243. package/dist/tools/drawing-analysis.js.map +0 -1
@@ -9,9 +9,22 @@ export const assemblyVBATools = [
9
9
  description: 'Generate VBA for creating assembly mates',
10
10
  inputSchema: z.object({
11
11
  mateType: z.enum([
12
- 'coincident', 'parallel', 'perpendicular', 'tangent', 'concentric',
13
- 'distance', 'angle', 'symmetric', 'width', 'path', 'linear_coupler',
14
- 'cam', 'gear', 'rack_pinion', 'screw', 'universal_joint'
12
+ 'coincident',
13
+ 'parallel',
14
+ 'perpendicular',
15
+ 'tangent',
16
+ 'concentric',
17
+ 'distance',
18
+ 'angle',
19
+ 'symmetric',
20
+ 'width',
21
+ 'path',
22
+ 'linear_coupler',
23
+ 'cam',
24
+ 'gear',
25
+ 'rack_pinion',
26
+ 'screw',
27
+ 'universal_joint',
15
28
  ]),
16
29
  component1: z.string().describe('First component name'),
17
30
  face1: z.string().describe('Face/edge/vertex on first component'),
@@ -20,7 +33,7 @@ export const assemblyVBATools = [
20
33
  distance: z.number().optional().describe('Distance in mm for distance mate'),
21
34
  angle: z.number().optional().describe('Angle in degrees for angle mate'),
22
35
  flip: z.boolean().optional(),
23
- alignmentType: z.enum(['aligned', 'anti_aligned', 'closest']).optional()
36
+ alignmentType: z.enum(['aligned', 'anti_aligned', 'closest']).optional(),
24
37
  }),
25
38
  handler: (args) => {
26
39
  const mateConstants = {
@@ -35,70 +48,76 @@ export const assemblyVBATools = [
35
48
  cam: 'swMateCAMFOLLOWER',
36
49
  gear: 'swMateGEAR',
37
50
  rack_pinion: 'swMateRACKPINION',
38
- screw: 'swMateSCREW'
51
+ screw: 'swMateSCREW',
39
52
  };
40
- return `
41
- Sub CreateAssemblyMate_${args.mateType}()
42
- Dim swApp As SldWorks.SldWorks
43
- Dim swAssy As SldWorks.AssemblyDoc
44
- Dim swMate As SldWorks.Mate2
45
- Dim swSelMgr As SldWorks.SelectionMgr
46
- Dim mateError As Long
47
-
48
- Set swApp = Application.SldWorks
49
- Set swAssy = swApp.ActiveDoc
50
-
51
- If swAssy Is Nothing Then
52
- MsgBox "Please open an assembly document"
53
- Exit Sub
54
- End If
55
-
56
- Set swSelMgr = swAssy.SelectionManager
57
-
58
- ' Clear selections
59
- swAssy.ClearSelection2 True
60
-
61
- ' Select first entity
62
- swAssy.Extension.SelectByID2 "${args.face1}@${args.component1}", "FACE", 0, 0, 0, False, 1, Nothing, 0
63
-
64
- ' Select second entity
65
- swAssy.Extension.SelectByID2 "${args.face2}@${args.component2}", "FACE", 0, 0, 0, True, 1, Nothing, 0
66
-
67
- ' Create mate
68
- ${args.mateType === 'distance' ? `
69
- Set swMate = swAssy.AddMate5( _
70
- ${mateConstants[args.mateType]}, _
71
- ${args.alignmentType === 'anti_aligned' ? 'swMateAlignANTI_ALIGNED' : 'swMateAlignALIGNED'}, _
72
- ${args.flip ? 'True' : 'False'}, _
73
- ${args.distance / 1000}, 0, 0, 0, 0, 0, 0, 0, _
74
- False, False, 0, mateError)` : ''}
75
-
76
- ${args.mateType === 'angle' ? `
77
- Set swMate = swAssy.AddMate5( _
78
- ${mateConstants[args.mateType]}, _
79
- ${args.alignmentType === 'anti_aligned' ? 'swMateAlignANTI_ALIGNED' : 'swMateAlignALIGNED'}, _
80
- ${args.flip ? 'True' : 'False'}, _
81
- 0, ${args.angle * Math.PI / 180}, 0, 0, 0, 0, 0, 0, _
82
- False, False, 0, mateError)` : ''}
83
-
84
- ${!['distance', 'angle'].includes(args.mateType) ? `
85
- Set swMate = swAssy.AddMate5( _
86
- ${mateConstants[args.mateType]}, _
87
- ${args.alignmentType === 'anti_aligned' ? 'swMateAlignANTI_ALIGNED' : 'swMateAlignALIGNED'}, _
88
- ${args.flip ? 'True' : 'False'}, _
89
- 0, 0, 0, 0, 0, 0, 0, 0, _
90
- False, False, 0, mateError)` : ''}
91
-
92
- If Not swMate Is Nothing Then
93
- MsgBox "${args.mateType} mate created successfully"
94
- swAssy.EditRebuild3
95
- Else
96
- MsgBox "Failed to create mate. Error code: " & mateError
97
- End If
98
-
99
- swAssy.ClearSelection2 True
53
+ return `
54
+ Sub CreateAssemblyMate_${args.mateType}()
55
+ Dim swApp As SldWorks.SldWorks
56
+ Dim swAssy As SldWorks.AssemblyDoc
57
+ Dim swMate As SldWorks.Mate2
58
+ Dim swSelMgr As SldWorks.SelectionMgr
59
+ Dim mateError As Long
60
+
61
+ Set swApp = Application.SldWorks
62
+ Set swAssy = swApp.ActiveDoc
63
+
64
+ If swAssy Is Nothing Then
65
+ MsgBox "Please open an assembly document"
66
+ Exit Sub
67
+ End If
68
+
69
+ Set swSelMgr = swAssy.SelectionManager
70
+
71
+ ' Clear selections
72
+ swAssy.ClearSelection2 True
73
+
74
+ ' Select first entity
75
+ swAssy.Extension.SelectByID2 "${args.face1}@${args.component1}", "FACE", 0, 0, 0, False, 1, Nothing, 0
76
+
77
+ ' Select second entity
78
+ swAssy.Extension.SelectByID2 "${args.face2}@${args.component2}", "FACE", 0, 0, 0, True, 1, Nothing, 0
79
+
80
+ ' Create mate
81
+ ${args.mateType === 'distance'
82
+ ? `
83
+ Set swMate = swAssy.AddMate5( _
84
+ ${mateConstants[args.mateType]}, _
85
+ ${args.alignmentType === 'anti_aligned' ? 'swMateAlignANTI_ALIGNED' : 'swMateAlignALIGNED'}, _
86
+ ${args.flip ? 'True' : 'False'}, _
87
+ ${args.distance / 1000}, 0, 0, 0, 0, 0, 0, 0, _
88
+ False, False, 0, mateError)`
89
+ : ''}
90
+
91
+ ${args.mateType === 'angle'
92
+ ? `
93
+ Set swMate = swAssy.AddMate5( _
94
+ ${mateConstants[args.mateType]}, _
95
+ ${args.alignmentType === 'anti_aligned' ? 'swMateAlignANTI_ALIGNED' : 'swMateAlignALIGNED'}, _
96
+ ${args.flip ? 'True' : 'False'}, _
97
+ 0, ${(args.angle * Math.PI) / 180}, 0, 0, 0, 0, 0, 0, _
98
+ False, False, 0, mateError)`
99
+ : ''}
100
+
101
+ ${!['distance', 'angle'].includes(args.mateType)
102
+ ? `
103
+ Set swMate = swAssy.AddMate5( _
104
+ ${mateConstants[args.mateType]}, _
105
+ ${args.alignmentType === 'anti_aligned' ? 'swMateAlignANTI_ALIGNED' : 'swMateAlignALIGNED'}, _
106
+ ${args.flip ? 'True' : 'False'}, _
107
+ 0, 0, 0, 0, 0, 0, 0, 0, _
108
+ False, False, 0, mateError)`
109
+ : ''}
110
+
111
+ If Not swMate Is Nothing Then
112
+ MsgBox "${args.mateType} mate created successfully"
113
+ swAssy.EditRebuild3
114
+ Else
115
+ MsgBox "Failed to create mate. Error code: " & mateError
116
+ End If
117
+
118
+ swAssy.ClearSelection2 True
100
119
  End Sub`;
101
- }
120
+ },
102
121
  },
103
122
  {
104
123
  name: 'vba_assembly_components',
@@ -108,389 +127,414 @@ End Sub`;
108
127
  componentPath: z.string().optional().describe('Path to component file'),
109
128
  componentName: z.string().optional().describe('Component name in assembly'),
110
129
  configurationName: z.string().optional(),
111
- position: z.object({
130
+ position: z
131
+ .object({
112
132
  x: z.number(),
113
133
  y: z.number(),
114
- z: z.number()
115
- }).optional(),
134
+ z: z.number(),
135
+ })
136
+ .optional(),
116
137
  quantity: z.number().optional(),
117
138
  patternType: z.enum(['linear', 'circular']).optional(),
118
- spacing: z.number().optional().describe('Spacing in mm')
139
+ spacing: z.number().optional().describe('Spacing in mm'),
119
140
  }),
120
141
  handler: (args) => {
121
142
  const operations = {
122
- insert: `
123
- Sub InsertComponent()
124
- Dim swApp As SldWorks.SldWorks
125
- Dim swAssy As SldWorks.AssemblyDoc
126
- Dim swComp As SldWorks.Component2
127
- Dim swMathUtil As SldWorks.MathUtility
128
- Dim swTransform As SldWorks.MathTransform
129
- Dim transformData(15) As Double
130
-
131
- Set swApp = Application.SldWorks
132
- Set swAssy = swApp.ActiveDoc
133
-
134
- If swAssy Is Nothing Then
135
- MsgBox "Please open an assembly document"
136
- Exit Sub
137
- End If
138
-
139
- Set swMathUtil = swApp.GetMathUtility
140
-
141
- ' Set transform matrix for position
142
- transformData(0) = 1: transformData(1) = 0: transformData(2) = 0
143
- transformData(3) = 0: transformData(4) = 1: transformData(5) = 0
144
- transformData(6) = 0: transformData(7) = 0: transformData(8) = 1
145
- transformData(9) = ${args.position?.x || 0} / 1000
146
- transformData(10) = ${args.position?.y || 0} / 1000
147
- transformData(11) = ${args.position?.z || 0} / 1000
148
- transformData(12) = 1
149
-
150
- Set swTransform = swMathUtil.CreateTransform(transformData)
151
-
152
- ' Insert component
153
- Set swComp = swAssy.AddComponent5( _
154
- "${args.componentPath}", _
155
- swAddComponentConfigOptions_e.swAddComponentConfigOptions_CurrentSelectedConfig, _
156
- "${args.configurationName || ''}", _
157
- False, "", _
158
- ${args.position?.x || 0} / 1000, _
159
- ${args.position?.y || 0} / 1000, _
160
- ${args.position?.z || 0} / 1000)
161
-
162
- If Not swComp Is Nothing Then
163
- MsgBox "Component inserted: " & swComp.Name2
164
- swAssy.EditRebuild3
165
- Else
166
- MsgBox "Failed to insert component"
167
- End If
143
+ insert: `
144
+ Sub InsertComponent()
145
+ Dim swApp As SldWorks.SldWorks
146
+ Dim swAssy As SldWorks.AssemblyDoc
147
+ Dim swComp As SldWorks.Component2
148
+ Dim swMathUtil As SldWorks.MathUtility
149
+ Dim swTransform As SldWorks.MathTransform
150
+ Dim transformData(15) As Double
151
+
152
+ Set swApp = Application.SldWorks
153
+ Set swAssy = swApp.ActiveDoc
154
+
155
+ If swAssy Is Nothing Then
156
+ MsgBox "Please open an assembly document"
157
+ Exit Sub
158
+ End If
159
+
160
+ Set swMathUtil = swApp.GetMathUtility
161
+
162
+ ' Set transform matrix for position
163
+ transformData(0) = 1: transformData(1) = 0: transformData(2) = 0
164
+ transformData(3) = 0: transformData(4) = 1: transformData(5) = 0
165
+ transformData(6) = 0: transformData(7) = 0: transformData(8) = 1
166
+ transformData(9) = ${args.position?.x || 0} / 1000
167
+ transformData(10) = ${args.position?.y || 0} / 1000
168
+ transformData(11) = ${args.position?.z || 0} / 1000
169
+ transformData(12) = 1
170
+
171
+ Set swTransform = swMathUtil.CreateTransform(transformData)
172
+
173
+ ' Insert component
174
+ Set swComp = swAssy.AddComponent5( _
175
+ "${args.componentPath}", _
176
+ swAddComponentConfigOptions_e.swAddComponentConfigOptions_CurrentSelectedConfig, _
177
+ "${args.configurationName || ''}", _
178
+ False, "", _
179
+ ${args.position?.x || 0} / 1000, _
180
+ ${args.position?.y || 0} / 1000, _
181
+ ${args.position?.z || 0} / 1000)
182
+
183
+ If Not swComp Is Nothing Then
184
+ MsgBox "Component inserted: " & swComp.Name2
185
+ swAssy.EditRebuild3
186
+ Else
187
+ MsgBox "Failed to insert component"
188
+ End If
168
189
  End Sub`,
169
- replace: `
170
- Sub ReplaceComponent()
171
- Dim swApp As SldWorks.SldWorks
172
- Dim swAssy As SldWorks.AssemblyDoc
173
- Dim swComp As SldWorks.Component2
174
- Dim bRet As Boolean
175
-
176
- Set swApp = Application.SldWorks
177
- Set swAssy = swApp.ActiveDoc
178
-
179
- If swAssy Is Nothing Then Exit Sub
180
-
181
- ' Select component to replace
182
- swAssy.Extension.SelectByID2 "${args.componentName}", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0
183
- Set swComp = swAssy.SelectionManager.GetSelectedObject6(1, -1)
184
-
185
- If Not swComp Is Nothing Then
186
- ' Replace component
187
- bRet = swComp.Replace2("${args.componentPath}", "${args.configurationName || ''}", False, True)
188
-
189
- If bRet Then
190
- MsgBox "Component replaced successfully"
191
- swAssy.EditRebuild3
192
- Else
193
- MsgBox "Failed to replace component"
194
- End If
195
- End If
190
+ replace: `
191
+ Sub ReplaceComponent()
192
+ Dim swApp As SldWorks.SldWorks
193
+ Dim swAssy As SldWorks.AssemblyDoc
194
+ Dim swComp As SldWorks.Component2
195
+ Dim bRet As Boolean
196
+
197
+ Set swApp = Application.SldWorks
198
+ Set swAssy = swApp.ActiveDoc
199
+
200
+ If swAssy Is Nothing Then Exit Sub
201
+
202
+ ' Select component to replace
203
+ swAssy.Extension.SelectByID2 "${args.componentName}", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0
204
+ Set swComp = swAssy.SelectionManager.GetSelectedObject6(1, -1)
205
+
206
+ If Not swComp Is Nothing Then
207
+ ' Replace component
208
+ bRet = swComp.Replace2("${args.componentPath}", "${args.configurationName || ''}", False, True)
209
+
210
+ If bRet Then
211
+ MsgBox "Component replaced successfully"
212
+ swAssy.EditRebuild3
213
+ Else
214
+ MsgBox "Failed to replace component"
215
+ End If
216
+ End If
196
217
  End Sub`,
197
- pattern: `
198
- Sub CreateComponentPattern()
199
- Dim swApp As SldWorks.SldWorks
200
- Dim swAssy As SldWorks.AssemblyDoc
201
- Dim swFeat As SldWorks.Feature
202
- Dim swLocalPattern As SldWorks.LocalLinearPatternFeatureData
203
-
204
- Set swApp = Application.SldWorks
205
- Set swAssy = swApp.ActiveDoc
206
-
207
- If swAssy Is Nothing Then Exit Sub
208
-
209
- ' Select component(s) to pattern
210
- swAssy.Extension.SelectByID2 "${args.componentName}", "COMPONENT", 0, 0, 0, False, 1, Nothing, 0
211
-
212
- ${args.patternType === 'linear' ? `
213
- ' Select direction references
214
- swAssy.Extension.SelectByID2 "Right Plane", "PLANE", 0, 0, 0, True, 2, Nothing, 0
215
-
216
- ' Create linear pattern
217
- Set swFeat = swAssy.FeatureManager.FeatureLinearPattern4( _
218
- ${args.quantity || 3}, ${(args.spacing || 50) / 1000}, _
219
- 1, 0, False, False, "NULL", "NULL", _
220
- False, False, False, False, False, False, _
221
- False, False, False, False, 0, 0)` : ''}
222
-
223
- ${args.patternType === 'circular' ? `
224
- ' Select axis
225
- swAssy.Extension.SelectByID2 "Axis1", "AXIS", 0, 0, 0, True, 2, Nothing, 0
226
-
227
- ' Create circular pattern
228
- Set swFeat = swAssy.FeatureManager.FeatureCircularPattern5( _
229
- ${args.quantity || 6}, ${2 * Math.PI / (args.quantity || 6)}, _
230
- False, "NULL", False, True, False, False)` : ''}
231
-
232
- If Not swFeat Is Nothing Then
233
- MsgBox "Component pattern created: " & swFeat.Name
234
- swAssy.EditRebuild3
235
- End If
218
+ pattern: `
219
+ Sub CreateComponentPattern()
220
+ Dim swApp As SldWorks.SldWorks
221
+ Dim swAssy As SldWorks.AssemblyDoc
222
+ Dim swFeat As SldWorks.Feature
223
+ Dim swLocalPattern As SldWorks.LocalLinearPatternFeatureData
224
+
225
+ Set swApp = Application.SldWorks
226
+ Set swAssy = swApp.ActiveDoc
227
+
228
+ If swAssy Is Nothing Then Exit Sub
229
+
230
+ ' Select component(s) to pattern
231
+ swAssy.Extension.SelectByID2 "${args.componentName}", "COMPONENT", 0, 0, 0, False, 1, Nothing, 0
232
+
233
+ ${args.patternType === 'linear'
234
+ ? `
235
+ ' Select direction references
236
+ swAssy.Extension.SelectByID2 "Right Plane", "PLANE", 0, 0, 0, True, 2, Nothing, 0
237
+
238
+ ' Create linear pattern
239
+ Set swFeat = swAssy.FeatureManager.FeatureLinearPattern4( _
240
+ ${args.quantity || 3}, ${(args.spacing || 50) / 1000}, _
241
+ 1, 0, False, False, "NULL", "NULL", _
242
+ False, False, False, False, False, False, _
243
+ False, False, False, False, 0, 0)`
244
+ : ''}
245
+
246
+ ${args.patternType === 'circular'
247
+ ? `
248
+ ' Select axis
249
+ swAssy.Extension.SelectByID2 "Axis1", "AXIS", 0, 0, 0, True, 2, Nothing, 0
250
+
251
+ ' Create circular pattern
252
+ Set swFeat = swAssy.FeatureManager.FeatureCircularPattern5( _
253
+ ${args.quantity || 6}, ${(2 * Math.PI) / (args.quantity || 6)}, _
254
+ False, "NULL", False, True, False, False)`
255
+ : ''}
256
+
257
+ If Not swFeat Is Nothing Then
258
+ MsgBox "Component pattern created: " & swFeat.Name
259
+ swAssy.EditRebuild3
260
+ End If
261
+ End Sub`,
262
+ explode: `
263
+ Sub CreateExplodedView()
264
+ Dim swApp As SldWorks.SldWorks
265
+ Dim swAssy As SldWorks.AssemblyDoc
266
+ Dim swConfig As SldWorks.Configuration
267
+ Dim swExplodeView As SldWorks.ExplodedView
268
+
269
+ Set swApp = Application.SldWorks
270
+ Set swAssy = swApp.ActiveDoc
271
+
272
+ If swAssy Is Nothing Then Exit Sub
273
+
274
+ Set swConfig = swAssy.GetActiveConfiguration
275
+
276
+ ' Create new exploded view
277
+ Set swExplodeView = swConfig.CreateExplodedView2("ExplodedView_${Date.now()}")
278
+
279
+ If Not swExplodeView Is Nothing Then
280
+ ' Select components to explode
281
+ swAssy.Extension.SelectByID2 "${args.componentName}", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0
282
+
283
+ ' Add explode step
284
+ swExplodeView.AddExplodeStep _
285
+ ${(args.position?.x || 100) / 1000}, _
286
+ ${(args.position?.y || 0) / 1000}, _
287
+ ${(args.position?.z || 0) / 1000}
288
+
289
+ MsgBox "Exploded view created"
290
+ swAssy.ShowExploded2 True
291
+ End If
236
292
  End Sub`,
237
- explode: `
238
- Sub CreateExplodedView()
239
- Dim swApp As SldWorks.SldWorks
240
- Dim swAssy As SldWorks.AssemblyDoc
241
- Dim swConfig As SldWorks.Configuration
242
- Dim swExplodeView As SldWorks.ExplodedView
243
-
244
- Set swApp = Application.SldWorks
245
- Set swAssy = swApp.ActiveDoc
246
-
247
- If swAssy Is Nothing Then Exit Sub
248
-
249
- Set swConfig = swAssy.GetActiveConfiguration
250
-
251
- ' Create new exploded view
252
- Set swExplodeView = swConfig.CreateExplodedView2("ExplodedView_${Date.now()}")
253
-
254
- If Not swExplodeView Is Nothing Then
255
- ' Select components to explode
256
- swAssy.Extension.SelectByID2 "${args.componentName}", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0
257
-
258
- ' Add explode step
259
- swExplodeView.AddExplodeStep _
260
- ${(args.position?.x || 100) / 1000}, _
261
- ${(args.position?.y || 0) / 1000}, _
262
- ${(args.position?.z || 0) / 1000}
263
-
264
- MsgBox "Exploded view created"
265
- swAssy.ShowExploded2 True
266
- End If
267
- End Sub`
268
293
  };
269
294
  return operations[args.operation] || 'Operation not supported';
270
- }
295
+ },
271
296
  },
272
297
  {
273
298
  name: 'vba_assembly_analysis',
274
299
  description: 'Generate VBA for assembly analysis',
275
300
  inputSchema: z.object({
276
301
  analysisType: z.enum([
277
- 'interference', 'clearance', 'collision', 'mass_properties',
278
- 'hole_alignment', 'assembly_statistics', 'bom_export'
302
+ 'interference',
303
+ 'clearance',
304
+ 'collision',
305
+ 'mass_properties',
306
+ 'hole_alignment',
307
+ 'assembly_statistics',
308
+ 'bom_export',
279
309
  ]),
280
310
  components: z.array(z.string()).optional().describe('Components to analyze'),
281
311
  outputPath: z.string().optional().describe('Path for results export'),
282
312
  includeSubassemblies: z.boolean().optional().default(true),
283
- treatCoincidentAsInterference: z.boolean().optional().default(false)
313
+ treatCoincidentAsInterference: z.boolean().optional().default(false),
284
314
  }),
285
315
  handler: (args) => {
286
316
  const analyses = {
287
- interference: `
288
- Sub CheckInterference()
289
- Dim swApp As SldWorks.SldWorks
290
- Dim swAssy As SldWorks.AssemblyDoc
291
- Dim swIntMgr As SldWorks.InterferenceDetectionMgr
292
- Dim vInts As Variant
293
- Dim i As Integer
294
- Dim swInt As SldWorks.Interference
295
- Dim vol As Double
296
-
297
- Set swApp = Application.SldWorks
298
- Set swAssy = swApp.ActiveDoc
299
-
300
- If swAssy Is Nothing Then
301
- MsgBox "Please open an assembly"
302
- Exit Sub
303
- End If
304
-
305
- Set swIntMgr = swAssy.InterferenceDetectionManager
306
-
307
- ' Configure interference detection
308
- swIntMgr.TreatCoincidenceAsInterference = ${args.treatCoincidentAsInterference ? 'True' : 'False'}
309
- swIntMgr.TreatSubAssembliesAsComponents = ${args.includeSubassemblies ? 'False' : 'True'}
310
- swIntMgr.IncludeMultibodyPartInterferences = True
311
- swIntMgr.MakeInterferingPartsTransparent = True
312
-
313
- ${args.components && args.components.length > 0 ? `
314
- ' Select specific components
315
- ${args.components.map((comp) => `
316
- swAssy.Extension.SelectByID2 "${comp}", "COMPONENT", 0, 0, 0, True, 0, Nothing, 0`).join('')}` : ''}
317
-
318
- ' Run interference detection
319
- vInts = swIntMgr.GetInterferences
320
- swIntMgr.Done
321
-
322
- If Not IsEmpty(vInts) Then
323
- MsgBox "Found " & UBound(vInts) + 1 & " interference(s)"
324
-
325
- ' Process each interference
326
- For i = 0 To UBound(vInts)
327
- Set swInt = vInts(i)
328
- vol = swInt.Volume * 1000000000 ' Convert to mm³
329
-
330
- Debug.Print "Interference " & i + 1 & ":"
331
- Debug.Print " Component 1: " & swInt.Component1.Name2
332
- Debug.Print " Component 2: " & swInt.Component2.Name2
333
- Debug.Print " Volume: " & Format(vol, "0.00") & " mm³"
334
- Next i
335
-
336
- ${args.outputPath ? `
337
- ' Export results
338
- Dim fso As Object, file As Object
339
- Set fso = CreateObject("Scripting.FileSystemObject")
340
- Set file = fso.CreateTextFile("${args.outputPath}", True)
341
-
342
- file.WriteLine "Interference Detection Report"
343
- file.WriteLine "============================="
344
- file.WriteLine "Total Interferences: " & UBound(vInts) + 1
345
- file.WriteLine ""
346
-
347
- For i = 0 To UBound(vInts)
348
- Set swInt = vInts(i)
349
- file.WriteLine "Interference " & i + 1 & ":"
350
- file.WriteLine " Component 1: " & swInt.Component1.Name2
351
- file.WriteLine " Component 2: " & swInt.Component2.Name2
352
- file.WriteLine " Volume: " & Format(swInt.Volume * 1000000000, "0.00") & " mm³"
353
- file.WriteLine ""
354
- Next i
355
-
356
- file.Close
357
- MsgBox "Report exported to: " & "${args.outputPath}"` : ''}
358
- Else
359
- MsgBox "No interferences found"
360
- End If
317
+ interference: `
318
+ Sub CheckInterference()
319
+ Dim swApp As SldWorks.SldWorks
320
+ Dim swAssy As SldWorks.AssemblyDoc
321
+ Dim swIntMgr As SldWorks.InterferenceDetectionMgr
322
+ Dim vInts As Variant
323
+ Dim i As Integer
324
+ Dim swInt As SldWorks.Interference
325
+ Dim vol As Double
326
+
327
+ Set swApp = Application.SldWorks
328
+ Set swAssy = swApp.ActiveDoc
329
+
330
+ If swAssy Is Nothing Then
331
+ MsgBox "Please open an assembly"
332
+ Exit Sub
333
+ End If
334
+
335
+ Set swIntMgr = swAssy.InterferenceDetectionManager
336
+
337
+ ' Configure interference detection
338
+ swIntMgr.TreatCoincidenceAsInterference = ${args.treatCoincidentAsInterference ? 'True' : 'False'}
339
+ swIntMgr.TreatSubAssembliesAsComponents = ${args.includeSubassemblies ? 'False' : 'True'}
340
+ swIntMgr.IncludeMultibodyPartInterferences = True
341
+ swIntMgr.MakeInterferingPartsTransparent = True
342
+
343
+ ${args.components && args.components.length > 0
344
+ ? `
345
+ ' Select specific components
346
+ ${args.components
347
+ .map((comp) => `
348
+ swAssy.Extension.SelectByID2 "${comp}", "COMPONENT", 0, 0, 0, True, 0, Nothing, 0`)
349
+ .join('')}`
350
+ : ''}
351
+
352
+ ' Run interference detection
353
+ vInts = swIntMgr.GetInterferences
354
+ swIntMgr.Done
355
+
356
+ If Not IsEmpty(vInts) Then
357
+ MsgBox "Found " & UBound(vInts) + 1 & " interference(s)"
358
+
359
+ ' Process each interference
360
+ For i = 0 To UBound(vInts)
361
+ Set swInt = vInts(i)
362
+ vol = swInt.Volume * 1000000000 ' Convert to mm³
363
+
364
+ Debug.Print "Interference " & i + 1 & ":"
365
+ Debug.Print " Component 1: " & swInt.Component1.Name2
366
+ Debug.Print " Component 2: " & swInt.Component2.Name2
367
+ Debug.Print " Volume: " & Format(vol, "0.00") & " mm³"
368
+ Next i
369
+
370
+ ${args.outputPath
371
+ ? `
372
+ ' Export results
373
+ Dim fso As Object, file As Object
374
+ Set fso = CreateObject("Scripting.FileSystemObject")
375
+ Set file = fso.CreateTextFile("${args.outputPath}", True)
376
+
377
+ file.WriteLine "Interference Detection Report"
378
+ file.WriteLine "============================="
379
+ file.WriteLine "Total Interferences: " & UBound(vInts) + 1
380
+ file.WriteLine ""
381
+
382
+ For i = 0 To UBound(vInts)
383
+ Set swInt = vInts(i)
384
+ file.WriteLine "Interference " & i + 1 & ":"
385
+ file.WriteLine " Component 1: " & swInt.Component1.Name2
386
+ file.WriteLine " Component 2: " & swInt.Component2.Name2
387
+ file.WriteLine " Volume: " & Format(swInt.Volume * 1000000000, "0.00") & " mm³"
388
+ file.WriteLine ""
389
+ Next i
390
+
391
+ file.Close
392
+ MsgBox "Report exported to: " & "${args.outputPath}"`
393
+ : ''}
394
+ Else
395
+ MsgBox "No interferences found"
396
+ End If
397
+ End Sub`,
398
+ mass_properties: `
399
+ Sub CalculateMassProperties()
400
+ Dim swApp As SldWorks.SldWorks
401
+ Dim swAssy As SldWorks.AssemblyDoc
402
+ Dim swMass As SldWorks.MassProperty
403
+ Dim vCOG As Variant
404
+ Dim vMOI As Variant
405
+ Dim mass As Double
406
+
407
+ Set swApp = Application.SldWorks
408
+ Set swAssy = swApp.ActiveDoc
409
+
410
+ If swAssy Is Nothing Then Exit Sub
411
+
412
+ Set swMass = swAssy.Extension.CreateMassProperty
413
+
414
+ ${args.components && args.components.length > 0
415
+ ? `
416
+ ' Select specific components
417
+ swAssy.ClearSelection2 True
418
+ ${args.components
419
+ .map((comp) => `
420
+ swAssy.Extension.SelectByID2 "${comp}", "COMPONENT", 0, 0, 0, True, 0, Nothing, 0`)
421
+ .join('')}
422
+
423
+ ' Calculate for selected components
424
+ swMass.UseSelectedOnly = True`
425
+ : ''}
426
+
427
+ mass = swMass.Mass * 1000 ' Convert to grams
428
+ vCOG = swMass.CenterOfMass
429
+ vMOI = swMass.GetMomentOfInertia(0) ' At COG
430
+
431
+ ' Display results
432
+ MsgBox "Mass Properties:" & vbCrLf & _
433
+ "Mass: " & Format(mass, "0.00") & " g" & vbCrLf & _
434
+ "Volume: " & Format(swMass.Volume * 1000000000, "0.00") & " mm³" & vbCrLf & _
435
+ "Density: " & Format(swMass.Density, "0.00") & " kg/m³" & vbCrLf & _
436
+ "Surface Area: " & Format(swMass.SurfaceArea * 1000000, "0.00") & " mm²" & vbCrLf & vbCrLf & _
437
+ "Center of Gravity:" & vbCrLf & _
438
+ "X: " & Format(vCOG(0) * 1000, "0.00") & " mm" & vbCrLf & _
439
+ "Y: " & Format(vCOG(1) * 1000, "0.00") & " mm" & vbCrLf & _
440
+ "Z: " & Format(vCOG(2) * 1000, "0.00") & " mm"
441
+
442
+ ${args.outputPath
443
+ ? `
444
+ ' Export to file
445
+ Dim fso As Object, file As Object
446
+ Set fso = CreateObject("Scripting.FileSystemObject")
447
+ Set file = fso.CreateTextFile("${args.outputPath}", True)
448
+
449
+ file.WriteLine "Mass Properties Report"
450
+ file.WriteLine "====================="
451
+ file.WriteLine "Mass: " & Format(mass, "0.00") & " g"
452
+ file.WriteLine "Volume: " & Format(swMass.Volume * 1000000000, "0.00") & " mm³"
453
+ file.WriteLine "Density: " & Format(swMass.Density, "0.00") & " kg/m³"
454
+ file.WriteLine "Surface Area: " & Format(swMass.SurfaceArea * 1000000, "0.00") & " mm²"
455
+ file.WriteLine ""
456
+ file.WriteLine "Center of Gravity:"
457
+ file.WriteLine " X: " & Format(vCOG(0) * 1000, "0.00") & " mm"
458
+ file.WriteLine " Y: " & Format(vCOG(1) * 1000, "0.00") & " mm"
459
+ file.WriteLine " Z: " & Format(vCOG(2) * 1000, "0.00") & " mm"
460
+ file.WriteLine ""
461
+ file.WriteLine "Moments of Inertia (at COG):"
462
+ file.WriteLine " Ixx: " & Format(vMOI(0), "0.0000") & " kg·m²"
463
+ file.WriteLine " Iyy: " & Format(vMOI(1), "0.0000") & " kg·m²"
464
+ file.WriteLine " Izz: " & Format(vMOI(2), "0.0000") & " kg·m²"
465
+
466
+ file.Close
467
+ MsgBox "Report saved to: " & "${args.outputPath}"`
468
+ : ''}
361
469
  End Sub`,
362
- mass_properties: `
363
- Sub CalculateMassProperties()
364
- Dim swApp As SldWorks.SldWorks
365
- Dim swAssy As SldWorks.AssemblyDoc
366
- Dim swMass As SldWorks.MassProperty
367
- Dim vCOG As Variant
368
- Dim vMOI As Variant
369
- Dim mass As Double
370
-
371
- Set swApp = Application.SldWorks
372
- Set swAssy = swApp.ActiveDoc
373
-
374
- If swAssy Is Nothing Then Exit Sub
375
-
376
- Set swMass = swAssy.Extension.CreateMassProperty
377
-
378
- ${args.components && args.components.length > 0 ? `
379
- ' Select specific components
380
- swAssy.ClearSelection2 True
381
- ${args.components.map((comp) => `
382
- swAssy.Extension.SelectByID2 "${comp}", "COMPONENT", 0, 0, 0, True, 0, Nothing, 0`).join('')}
383
-
384
- ' Calculate for selected components
385
- swMass.UseSelectedOnly = True` : ''}
386
-
387
- mass = swMass.Mass * 1000 ' Convert to grams
388
- vCOG = swMass.CenterOfMass
389
- vMOI = swMass.GetMomentOfInertia(0) ' At COG
390
-
391
- ' Display results
392
- MsgBox "Mass Properties:" & vbCrLf & _
393
- "Mass: " & Format(mass, "0.00") & " g" & vbCrLf & _
394
- "Volume: " & Format(swMass.Volume * 1000000000, "0.00") & " mm³" & vbCrLf & _
395
- "Density: " & Format(swMass.Density, "0.00") & " kg/m³" & vbCrLf & _
396
- "Surface Area: " & Format(swMass.SurfaceArea * 1000000, "0.00") & " mm²" & vbCrLf & vbCrLf & _
397
- "Center of Gravity:" & vbCrLf & _
398
- "X: " & Format(vCOG(0) * 1000, "0.00") & " mm" & vbCrLf & _
399
- "Y: " & Format(vCOG(1) * 1000, "0.00") & " mm" & vbCrLf & _
400
- "Z: " & Format(vCOG(2) * 1000, "0.00") & " mm"
401
-
402
- ${args.outputPath ? `
403
- ' Export to file
404
- Dim fso As Object, file As Object
405
- Set fso = CreateObject("Scripting.FileSystemObject")
406
- Set file = fso.CreateTextFile("${args.outputPath}", True)
407
-
408
- file.WriteLine "Mass Properties Report"
409
- file.WriteLine "====================="
410
- file.WriteLine "Mass: " & Format(mass, "0.00") & " g"
411
- file.WriteLine "Volume: " & Format(swMass.Volume * 1000000000, "0.00") & " mm³"
412
- file.WriteLine "Density: " & Format(swMass.Density, "0.00") & " kg/m³"
413
- file.WriteLine "Surface Area: " & Format(swMass.SurfaceArea * 1000000, "0.00") & " mm²"
414
- file.WriteLine ""
415
- file.WriteLine "Center of Gravity:"
416
- file.WriteLine " X: " & Format(vCOG(0) * 1000, "0.00") & " mm"
417
- file.WriteLine " Y: " & Format(vCOG(1) * 1000, "0.00") & " mm"
418
- file.WriteLine " Z: " & Format(vCOG(2) * 1000, "0.00") & " mm"
419
- file.WriteLine ""
420
- file.WriteLine "Moments of Inertia (at COG):"
421
- file.WriteLine " Ixx: " & Format(vMOI(0), "0.0000") & " kg·m²"
422
- file.WriteLine " Iyy: " & Format(vMOI(1), "0.0000") & " kg·m²"
423
- file.WriteLine " Izz: " & Format(vMOI(2), "0.0000") & " kg·m²"
424
-
425
- file.Close
426
- MsgBox "Report saved to: " & "${args.outputPath}"` : ''}
470
+ bom_export: `
471
+ Sub ExportBOM()
472
+ Dim swApp As SldWorks.SldWorks
473
+ Dim swAssy As SldWorks.AssemblyDoc
474
+ Dim swBOMAnnotation As SldWorks.BomTableAnnotation
475
+ Dim swBOMFeature As SldWorks.BomFeature
476
+ Dim swTable As SldWorks.TableAnnotation
477
+ Dim i As Integer, j As Integer
478
+ Dim rowCount As Long, colCount As Long
479
+
480
+ Set swApp = Application.SldWorks
481
+ Set swAssy = swApp.ActiveDoc
482
+
483
+ If swAssy Is Nothing Then Exit Sub
484
+
485
+ ' Create BOM
486
+ Set swBOMFeature = swAssy.FeatureManager.InsertBomTable3( _
487
+ "", "${args.outputPath || 'C:\\Temp\\BOM.xlsx'}", _
488
+ swBomType_e.swBomType_PartsOnly, _
489
+ "", _
490
+ swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_ActiveConfiguration, _
491
+ swBomStandard_e.swBomStandard_BomTable, _
492
+ False)
493
+
494
+ If Not swBOMFeature Is Nothing Then
495
+ Set swBOMAnnotation = swBOMFeature.GetTableAnnotations(0)
496
+ Set swTable = swBOMAnnotation
497
+
498
+ rowCount = swTable.RowCount
499
+ colCount = swTable.ColumnCount
500
+
501
+ ' Export to Excel
502
+ Dim xlApp As Object
503
+ Dim xlBook As Object
504
+ Dim xlSheet As Object
505
+
506
+ Set xlApp = CreateObject("Excel.Application")
507
+ Set xlBook = xlApp.Workbooks.Add
508
+ Set xlSheet = xlBook.Sheets(1)
509
+
510
+ xlApp.Visible = True
511
+
512
+ ' Write headers
513
+ For j = 0 To colCount - 1
514
+ xlSheet.Cells(1, j + 1).Value = swTable.GetColumnTitle(j)
515
+ Next j
516
+
517
+ ' Write data
518
+ For i = 1 To rowCount - 1
519
+ For j = 0 To colCount - 1
520
+ xlSheet.Cells(i + 1, j + 1).Value = swTable.Text(i, j)
521
+ Next j
522
+ Next i
523
+
524
+ ' Format
525
+ xlSheet.Range("A1").CurrentRegion.Columns.AutoFit
526
+ xlSheet.Range("A1").CurrentRegion.Borders.LineStyle = 1
527
+
528
+ ${args.outputPath
529
+ ? `
530
+ xlBook.SaveAs "${args.outputPath}"
531
+ MsgBox "BOM exported to: ${args.outputPath}"`
532
+ : ''}
533
+ End If
427
534
  End Sub`,
428
- bom_export: `
429
- Sub ExportBOM()
430
- Dim swApp As SldWorks.SldWorks
431
- Dim swAssy As SldWorks.AssemblyDoc
432
- Dim swBOMAnnotation As SldWorks.BomTableAnnotation
433
- Dim swBOMFeature As SldWorks.BomFeature
434
- Dim swTable As SldWorks.TableAnnotation
435
- Dim i As Integer, j As Integer
436
- Dim rowCount As Long, colCount As Long
437
-
438
- Set swApp = Application.SldWorks
439
- Set swAssy = swApp.ActiveDoc
440
-
441
- If swAssy Is Nothing Then Exit Sub
442
-
443
- ' Create BOM
444
- Set swBOMFeature = swAssy.FeatureManager.InsertBomTable3( _
445
- "", "${args.outputPath || 'C:\\Temp\\BOM.xlsx'}", _
446
- swBomType_e.swBomType_PartsOnly, _
447
- "", _
448
- swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_ActiveConfiguration, _
449
- swBomStandard_e.swBomStandard_BomTable, _
450
- False)
451
-
452
- If Not swBOMFeature Is Nothing Then
453
- Set swBOMAnnotation = swBOMFeature.GetTableAnnotations(0)
454
- Set swTable = swBOMAnnotation
455
-
456
- rowCount = swTable.RowCount
457
- colCount = swTable.ColumnCount
458
-
459
- ' Export to Excel
460
- Dim xlApp As Object
461
- Dim xlBook As Object
462
- Dim xlSheet As Object
463
-
464
- Set xlApp = CreateObject("Excel.Application")
465
- Set xlBook = xlApp.Workbooks.Add
466
- Set xlSheet = xlBook.Sheets(1)
467
-
468
- xlApp.Visible = True
469
-
470
- ' Write headers
471
- For j = 0 To colCount - 1
472
- xlSheet.Cells(1, j + 1).Value = swTable.GetColumnTitle(j)
473
- Next j
474
-
475
- ' Write data
476
- For i = 1 To rowCount - 1
477
- For j = 0 To colCount - 1
478
- xlSheet.Cells(i + 1, j + 1).Value = swTable.Text(i, j)
479
- Next j
480
- Next i
481
-
482
- ' Format
483
- xlSheet.Range("A1").CurrentRegion.Columns.AutoFit
484
- xlSheet.Range("A1").CurrentRegion.Borders.LineStyle = 1
485
-
486
- ${args.outputPath ? `
487
- xlBook.SaveAs "${args.outputPath}"
488
- MsgBox "BOM exported to: ${args.outputPath}"` : ''}
489
- End If
490
- End Sub`
491
535
  };
492
536
  return analyses[args.analysisType] || 'Analysis type not supported';
493
- }
537
+ },
494
538
  },
495
539
  {
496
540
  name: 'vba_assembly_configurations',
@@ -501,88 +545,106 @@ End Sub`
501
545
  parentConfig: z.string().optional(),
502
546
  componentsToSuppress: z.array(z.string()).optional(),
503
547
  properties: z.record(z.string()).optional(),
504
- displayStates: z.array(z.string()).optional()
548
+ displayStates: z.array(z.string()).optional(),
505
549
  }),
506
550
  handler: (args) => {
507
- return `
508
- Sub ManageConfiguration_${args.operation}()
509
- Dim swApp As SldWorks.SldWorks
510
- Dim swAssy As SldWorks.AssemblyDoc
511
- Dim swConfig As SldWorks.Configuration
512
- Dim swConfigMgr As SldWorks.ConfigurationManager
513
- Dim bRet As Boolean
514
-
515
- Set swApp = Application.SldWorks
516
- Set swAssy = swApp.ActiveDoc
517
-
518
- If swAssy Is Nothing Then
519
- MsgBox "Please open an assembly"
520
- Exit Sub
521
- End If
522
-
523
- Set swConfigMgr = swAssy.ConfigurationManager
524
-
525
- ${args.operation === 'create' ? `
526
- ' Create new configuration
527
- Set swConfig = swAssy.AddConfiguration3( _
528
- "${args.configName}", _
529
- "Configuration created by VBA", _
530
- "", _
531
- swConfigurationOptions2_e.swConfigOption_LinkToParent + _
532
- swConfigurationOptions2_e.swConfigOption_InheritProperties, _
533
- "${args.parentConfig || ''}")
534
-
535
- If Not swConfig Is Nothing Then
536
- ' Activate new configuration
537
- swAssy.ShowConfiguration2 "${args.configName}"
538
-
539
- ${args.componentsToSuppress && args.componentsToSuppress.length > 0 ? `
540
- ' Suppress components
541
- ${args.componentsToSuppress.map((comp) => `
542
- swAssy.Extension.SelectByID2 "${comp}", "COMPONENT", 0, 0, 0, True, 0, Nothing, 0`).join('')}
543
- swAssy.EditSuppress2` : ''}
544
-
545
- ${args.properties ? `
546
- ' Set custom properties
547
- ${Object.entries(args.properties || {}).map(([key, value]) => `
548
- swConfig.CustomPropertyManager.Add3 "${key}", swCustomInfoType_e.swCustomInfoText, "${value}", _
549
- swCustomPropertyAddOption_e.swCustomPropertyReplaceValue`).join('')}` : ''}
550
-
551
- MsgBox "Configuration '${args.configName}' created"
552
- End If` : ''}
553
-
554
- ${args.operation === 'modify' ? `
555
- ' Get configuration
556
- Set swConfig = swAssy.GetConfigurationByName("${args.configName}")
557
-
558
- If Not swConfig Is Nothing Then
559
- ' Activate configuration
560
- swAssy.ShowConfiguration2 "${args.configName}"
561
-
562
- ${args.componentsToSuppress && args.componentsToSuppress.length > 0 ? `
563
- ' Modify suppression state
564
- ${args.componentsToSuppress.map((comp) => `
565
- swAssy.Extension.SelectByID2 "${comp}", "COMPONENT", 0, 0, 0, True, 0, Nothing, 0`).join('')}
566
- swAssy.EditSuppress2` : ''}
567
-
568
- MsgBox "Configuration '${args.configName}' modified"
569
- Else
570
- MsgBox "Configuration not found"
571
- End If` : ''}
572
-
573
- ${args.operation === 'delete' ? `
574
- ' Delete configuration
575
- bRet = swAssy.DeleteConfiguration2("${args.configName}")
576
-
577
- If bRet Then
578
- MsgBox "Configuration '${args.configName}' deleted"
579
- Else
580
- MsgBox "Failed to delete configuration"
581
- End If` : ''}
582
-
583
- swAssy.EditRebuild3
551
+ return `
552
+ Sub ManageConfiguration_${args.operation}()
553
+ Dim swApp As SldWorks.SldWorks
554
+ Dim swAssy As SldWorks.AssemblyDoc
555
+ Dim swConfig As SldWorks.Configuration
556
+ Dim swConfigMgr As SldWorks.ConfigurationManager
557
+ Dim bRet As Boolean
558
+
559
+ Set swApp = Application.SldWorks
560
+ Set swAssy = swApp.ActiveDoc
561
+
562
+ If swAssy Is Nothing Then
563
+ MsgBox "Please open an assembly"
564
+ Exit Sub
565
+ End If
566
+
567
+ Set swConfigMgr = swAssy.ConfigurationManager
568
+
569
+ ${args.operation === 'create'
570
+ ? `
571
+ ' Create new configuration
572
+ Set swConfig = swAssy.AddConfiguration3( _
573
+ "${args.configName}", _
574
+ "Configuration created by VBA", _
575
+ "", _
576
+ swConfigurationOptions2_e.swConfigOption_LinkToParent + _
577
+ swConfigurationOptions2_e.swConfigOption_InheritProperties, _
578
+ "${args.parentConfig || ''}")
579
+
580
+ If Not swConfig Is Nothing Then
581
+ ' Activate new configuration
582
+ swAssy.ShowConfiguration2 "${args.configName}"
583
+
584
+ ${args.componentsToSuppress && args.componentsToSuppress.length > 0
585
+ ? `
586
+ ' Suppress components
587
+ ${args.componentsToSuppress
588
+ .map((comp) => `
589
+ swAssy.Extension.SelectByID2 "${comp}", "COMPONENT", 0, 0, 0, True, 0, Nothing, 0`)
590
+ .join('')}
591
+ swAssy.EditSuppress2`
592
+ : ''}
593
+
594
+ ${args.properties
595
+ ? `
596
+ ' Set custom properties
597
+ ${Object.entries(args.properties || {})
598
+ .map(([key, value]) => `
599
+ swConfig.CustomPropertyManager.Add3 "${key}", swCustomInfoType_e.swCustomInfoText, "${value}", _
600
+ swCustomPropertyAddOption_e.swCustomPropertyReplaceValue`)
601
+ .join('')}`
602
+ : ''}
603
+
604
+ MsgBox "Configuration '${args.configName}' created"
605
+ End If`
606
+ : ''}
607
+
608
+ ${args.operation === 'modify'
609
+ ? `
610
+ ' Get configuration
611
+ Set swConfig = swAssy.GetConfigurationByName("${args.configName}")
612
+
613
+ If Not swConfig Is Nothing Then
614
+ ' Activate configuration
615
+ swAssy.ShowConfiguration2 "${args.configName}"
616
+
617
+ ${args.componentsToSuppress && args.componentsToSuppress.length > 0
618
+ ? `
619
+ ' Modify suppression state
620
+ ${args.componentsToSuppress
621
+ .map((comp) => `
622
+ swAssy.Extension.SelectByID2 "${comp}", "COMPONENT", 0, 0, 0, True, 0, Nothing, 0`)
623
+ .join('')}
624
+ swAssy.EditSuppress2`
625
+ : ''}
626
+
627
+ MsgBox "Configuration '${args.configName}' modified"
628
+ Else
629
+ MsgBox "Configuration not found"
630
+ End If`
631
+ : ''}
632
+
633
+ ${args.operation === 'delete'
634
+ ? `
635
+ ' Delete configuration
636
+ bRet = swAssy.DeleteConfiguration2("${args.configName}")
637
+
638
+ If bRet Then
639
+ MsgBox "Configuration '${args.configName}' deleted"
640
+ Else
641
+ MsgBox "Failed to delete configuration"
642
+ End If`
643
+ : ''}
644
+
645
+ swAssy.EditRebuild3
584
646
  End Sub`;
585
- }
586
- }
647
+ },
648
+ },
587
649
  ];
588
650
  //# sourceMappingURL=vba-assembly.js.map