solidworks-mcp-server 3.0.8 → 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.
- package/CHANGELOG.md +175 -98
- package/LICENSE +20 -20
- package/README.md +195 -423
- package/dist/adapters/circuit-breaker.d.ts +84 -0
- package/dist/adapters/circuit-breaker.d.ts.map +1 -0
- package/dist/adapters/circuit-breaker.js +228 -0
- package/dist/adapters/circuit-breaker.js.map +1 -0
- package/dist/adapters/connection-pool.d.ts +83 -0
- package/dist/adapters/connection-pool.d.ts.map +1 -0
- package/dist/adapters/connection-pool.js +282 -0
- package/dist/adapters/connection-pool.js.map +1 -0
- package/dist/adapters/edge-adapter.d.ts +43 -0
- package/dist/adapters/edge-adapter.d.ts.map +1 -0
- package/dist/adapters/edge-adapter.js +417 -0
- package/dist/adapters/edge-adapter.js.map +1 -0
- package/dist/adapters/factory.d.ts +60 -0
- package/dist/adapters/factory.d.ts.map +1 -0
- package/dist/adapters/factory.js +212 -0
- package/dist/adapters/factory.js.map +1 -0
- package/dist/adapters/feature-complexity-analyzer.d.ts +102 -0
- package/dist/adapters/feature-complexity-analyzer.d.ts.map +1 -0
- package/dist/adapters/feature-complexity-analyzer.js +322 -0
- package/dist/adapters/feature-complexity-analyzer.js.map +1 -0
- package/dist/adapters/macro-generator.d.ts +30 -0
- package/dist/adapters/macro-generator.d.ts.map +1 -0
- package/dist/adapters/macro-generator.js +524 -0
- package/dist/adapters/macro-generator.js.map +1 -0
- package/dist/adapters/mock-solidworks-adapter.d.ts +92 -0
- package/dist/adapters/mock-solidworks-adapter.d.ts.map +1 -0
- package/dist/adapters/mock-solidworks-adapter.js +367 -0
- package/dist/adapters/mock-solidworks-adapter.js.map +1 -0
- package/dist/adapters/types.d.ts +376 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +261 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/adapters/winax-adapter-enhanced.d.ts +55 -0
- package/dist/adapters/winax-adapter-enhanced.d.ts.map +1 -0
- package/dist/adapters/winax-adapter-enhanced.js +601 -0
- package/dist/adapters/winax-adapter-enhanced.js.map +1 -0
- package/dist/adapters/winax-adapter.d.ts +55 -0
- package/dist/adapters/winax-adapter.d.ts.map +1 -0
- package/dist/adapters/winax-adapter.js +667 -0
- package/dist/adapters/winax-adapter.js.map +1 -0
- package/dist/api/stainless-api.d.ts +29 -0
- package/dist/api/stainless-api.d.ts.map +1 -0
- package/dist/api/stainless-api.js +408 -0
- package/dist/api/stainless-api.js.map +1 -0
- package/dist/cache/manager.d.ts.map +1 -1
- package/dist/cache/manager.js +4 -3
- package/dist/cache/manager.js.map +1 -1
- package/dist/core/interfaces/core-abstractions.d.ts.map +1 -1
- package/dist/core/interfaces/core-abstractions.js.map +1 -1
- package/dist/db/connection.js +4 -4
- package/dist/db/connection.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +86 -79
- package/dist/index.js.map +1 -1
- package/dist/knowledge/chromadb.d.ts.map +1 -1
- package/dist/knowledge/chromadb.js +5 -3
- package/dist/knowledge/chromadb.js.map +1 -1
- package/dist/macro/recorder.d.ts +1 -1
- package/dist/macro/recorder.d.ts.map +1 -1
- package/dist/macro/recorder.js +10 -10
- package/dist/macro/recorder.js.map +1 -1
- package/dist/resources/base.js +10 -10
- package/dist/resources/base.js.map +1 -1
- package/dist/resources/design-table.d.ts +10 -12
- package/dist/resources/design-table.d.ts.map +1 -1
- package/dist/resources/design-table.js +42 -39
- package/dist/resources/design-table.js.map +1 -1
- package/dist/resources/pdm.d.ts +44 -45
- package/dist/resources/pdm.d.ts.map +1 -1
- package/dist/resources/pdm.js +118 -79
- package/dist/resources/pdm.js.map +1 -1
- package/dist/resources/registry.d.ts +1 -1
- package/dist/resources/registry.d.ts.map +1 -1
- package/dist/resources/registry.js +1 -1
- package/dist/shared/constants/solidworks-constants.d.ts.map +1 -1
- package/dist/shared/constants/solidworks-constants.js +9 -9
- package/dist/shared/constants/solidworks-constants.js.map +1 -1
- package/dist/solidworks/api.d.ts +8 -6
- package/dist/solidworks/api.d.ts.map +1 -1
- package/dist/solidworks/api.js +614 -188
- package/dist/solidworks/api.js.map +1 -1
- package/dist/state/store.d.ts +1 -1
- package/dist/state/store.d.ts.map +1 -1
- package/dist/state/store.js +14 -14
- package/dist/state/store.js.map +1 -1
- package/dist/tools/analysis.d.ts +12 -2
- package/dist/tools/analysis.d.ts.map +1 -1
- package/dist/tools/analysis.js +141 -31
- package/dist/tools/analysis.js.map +1 -1
- package/dist/tools/diagnostics.d.ts +1 -1
- package/dist/tools/diagnostics.d.ts.map +1 -1
- package/dist/tools/diagnostics.js +2 -2
- package/dist/tools/diagnostics.js.map +1 -1
- package/dist/tools/drawing.d.ts +2 -2
- package/dist/tools/drawing.d.ts.map +1 -1
- package/dist/tools/drawing.js +94 -10
- package/dist/tools/drawing.js.map +1 -1
- package/dist/tools/enhanced-drawing.d.ts +1 -1
- package/dist/tools/enhanced-drawing.d.ts.map +1 -1
- package/dist/tools/enhanced-drawing.js +10 -13
- package/dist/tools/enhanced-drawing.js.map +1 -1
- package/dist/tools/export.d.ts +1 -1
- package/dist/tools/export.d.ts.map +1 -1
- package/dist/tools/export.js +88 -14
- package/dist/tools/export.js.map +1 -1
- package/dist/tools/extrusion-helper.d.ts +15 -0
- package/dist/tools/extrusion-helper.d.ts.map +1 -0
- package/dist/tools/extrusion-helper.js +61 -0
- package/dist/tools/extrusion-helper.js.map +1 -0
- package/dist/tools/macro-security.d.ts +2 -2
- package/dist/tools/macro-security.d.ts.map +1 -1
- package/dist/tools/macro-security.js +2 -2
- package/dist/tools/macro-security.js.map +1 -1
- package/dist/tools/modeling.d.ts +2 -2
- package/dist/tools/modeling.d.ts.map +1 -1
- package/dist/tools/modeling.js +6 -6
- package/dist/tools/modeling.js.map +1 -1
- package/dist/tools/native-macro.d.ts +1 -1
- package/dist/tools/native-macro.d.ts.map +1 -1
- package/dist/tools/native-macro.js +246 -239
- package/dist/tools/native-macro.js.map +1 -1
- package/dist/tools/sketch.d.ts +28 -28
- package/dist/tools/sketch.d.ts.map +1 -1
- package/dist/tools/sketch.js +202 -136
- package/dist/tools/sketch.js.map +1 -1
- package/dist/tools/template-manager.d.ts +5 -5
- package/dist/tools/template-manager.d.ts.map +1 -1
- package/dist/tools/template-manager.js +66 -65
- package/dist/tools/template-manager.js.map +1 -1
- package/dist/tools/vba-advanced.d.ts +10 -10
- package/dist/tools/vba-advanced.d.ts.map +1 -1
- package/dist/tools/vba-advanced.js +791 -708
- package/dist/tools/vba-advanced.js.map +1 -1
- package/dist/tools/vba-assembly.d.ts +10 -10
- package/dist/tools/vba-assembly.d.ts.map +1 -1
- package/dist/tools/vba-assembly.js +562 -500
- package/dist/tools/vba-assembly.js.map +1 -1
- package/dist/tools/vba-drawing.d.ts +12 -12
- package/dist/tools/vba-drawing.d.ts.map +1 -1
- package/dist/tools/vba-drawing.js +681 -572
- package/dist/tools/vba-drawing.js.map +1 -1
- package/dist/tools/vba-file-management.d.ts +12 -12
- package/dist/tools/vba-file-management.d.ts.map +1 -1
- package/dist/tools/vba-file-management.js +662 -589
- package/dist/tools/vba-file-management.js.map +1 -1
- package/dist/tools/vba-part.d.ts +10 -10
- package/dist/tools/vba-part.d.ts.map +1 -1
- package/dist/tools/vba-part.js +484 -426
- package/dist/tools/vba-part.js.map +1 -1
- package/dist/tools/vba.d.ts +361 -361
- package/dist/tools/vba.d.ts.map +1 -1
- package/dist/tools/vba.js +67 -81
- package/dist/tools/vba.js.map +1 -1
- package/dist/utils/config.js +2 -2
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/environment.d.ts +243 -0
- package/dist/utils/environment.d.ts.map +1 -0
- package/dist/utils/environment.js +207 -0
- package/dist/utils/environment.js.map +1 -0
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +6 -6
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/solidworks-config.d.ts +39 -0
- package/dist/utils/solidworks-config.d.ts.map +1 -0
- package/dist/utils/solidworks-config.js +156 -0
- package/dist/utils/solidworks-config.js.map +1 -0
- package/package.json +84 -84
- package/scripts/setup.js +70 -70
- package/dist/application/services/command-bus.d.ts +0 -39
- package/dist/application/services/command-bus.d.ts.map +0 -1
- package/dist/application/services/command-bus.js +0 -88
- package/dist/application/services/command-bus.js.map +0 -1
- package/dist/application/services/event-bus.d.ts +0 -31
- package/dist/application/services/event-bus.d.ts.map +0 -1
- package/dist/application/services/event-bus.js +0 -83
- package/dist/application/services/event-bus.js.map +0 -1
- package/dist/application/services/query-bus.d.ts +0 -30
- package/dist/application/services/query-bus.d.ts.map +0 -1
- package/dist/application/services/query-bus.js +0 -59
- package/dist/application/services/query-bus.js.map +0 -1
- package/dist/application/services/tool-registry.d.ts +0 -53
- package/dist/application/services/tool-registry.d.ts.map +0 -1
- package/dist/application/services/tool-registry.js +0 -81
- package/dist/application/services/tool-registry.js.map +0 -1
- package/dist/application/use-cases/analysis/index.d.ts +0 -13
- package/dist/application/use-cases/analysis/index.d.ts.map +0 -1
- package/dist/application/use-cases/analysis/index.js +0 -17
- package/dist/application/use-cases/analysis/index.js.map +0 -1
- package/dist/application/use-cases/drawing/index.d.ts +0 -13
- package/dist/application/use-cases/drawing/index.d.ts.map +0 -1
- package/dist/application/use-cases/drawing/index.js +0 -17
- package/dist/application/use-cases/drawing/index.js.map +0 -1
- package/dist/application/use-cases/export/index.d.ts +0 -13
- package/dist/application/use-cases/export/index.d.ts.map +0 -1
- package/dist/application/use-cases/export/index.js +0 -17
- package/dist/application/use-cases/export/index.js.map +0 -1
- package/dist/application/use-cases/macro/index.d.ts +0 -13
- package/dist/application/use-cases/macro/index.d.ts.map +0 -1
- package/dist/application/use-cases/macro/index.js +0 -17
- package/dist/application/use-cases/macro/index.js.map +0 -1
- package/dist/application/use-cases/modeling/index.d.ts +0 -56
- package/dist/application/use-cases/modeling/index.d.ts.map +0 -1
- package/dist/application/use-cases/modeling/index.js +0 -385
- package/dist/application/use-cases/modeling/index.js.map +0 -1
- package/dist/index.refactored.d.ts +0 -7
- package/dist/index.refactored.d.ts.map +0 -1
- package/dist/index.refactored.js +0 -254
- package/dist/index.refactored.js.map +0 -1
- package/dist/infrastructure/config/configuration-manager.d.ts +0 -381
- package/dist/infrastructure/config/configuration-manager.d.ts.map +0 -1
- package/dist/infrastructure/config/configuration-manager.js +0 -566
- package/dist/infrastructure/config/configuration-manager.js.map +0 -1
- package/dist/infrastructure/container/service-locator.d.ts +0 -14
- package/dist/infrastructure/container/service-locator.d.ts.map +0 -1
- package/dist/infrastructure/container/service-locator.js +0 -38
- package/dist/infrastructure/container/service-locator.js.map +0 -1
- package/dist/infrastructure/logging/logger.d.ts +0 -24
- package/dist/infrastructure/logging/logger.d.ts.map +0 -1
- package/dist/infrastructure/logging/logger.js +0 -65
- package/dist/infrastructure/logging/logger.js.map +0 -1
- package/dist/infrastructure/solidworks/solidworks-adapter.d.ts +0 -43
- package/dist/infrastructure/solidworks/solidworks-adapter.d.ts.map +0 -1
- package/dist/infrastructure/solidworks/solidworks-adapter.js +0 -527
- package/dist/infrastructure/solidworks/solidworks-adapter.js.map +0 -1
- package/dist/presentation/mcp/request-handler.d.ts +0 -41
- package/dist/presentation/mcp/request-handler.d.ts.map +0 -1
- package/dist/presentation/mcp/request-handler.js +0 -100
- package/dist/presentation/mcp/request-handler.js.map +0 -1
- package/dist/presentation/transformers/error-transformer.d.ts +0 -16
- package/dist/presentation/transformers/error-transformer.d.ts.map +0 -1
- package/dist/presentation/transformers/error-transformer.js +0 -44
- package/dist/presentation/transformers/error-transformer.js.map +0 -1
- package/dist/presentation/transformers/response-transformer.d.ts +0 -24
- package/dist/presentation/transformers/response-transformer.d.ts.map +0 -1
- package/dist/presentation/transformers/response-transformer.js +0 -102
- package/dist/presentation/transformers/response-transformer.js.map +0 -1
- package/dist/tools/drawing-analysis.d.ts +0 -9
- package/dist/tools/drawing-analysis.d.ts.map +0 -1
- package/dist/tools/drawing-analysis.js +0 -239
- package/dist/tools/drawing-analysis.js.map +0 -1
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced WinAx Adapter for SolidWorks COM Integration
|
|
3
|
+
*
|
|
4
|
+
* This adapter wraps the existing winax-based SolidWorksAPI with:
|
|
5
|
+
* - Parameter limitation workarounds
|
|
6
|
+
* - Automatic fallback to macro execution for complex operations
|
|
7
|
+
* - Robust error handling and retry logic
|
|
8
|
+
* - Connection health monitoring
|
|
9
|
+
*/
|
|
10
|
+
import fs from 'node:fs/promises';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
import winax from 'winax';
|
|
14
|
+
import { logger } from '../utils/logger.js';
|
|
15
|
+
import { MacroGenerator } from './macro-generator.js';
|
|
16
|
+
export class WinAxAdapter {
|
|
17
|
+
swApp = null;
|
|
18
|
+
currentModel = null;
|
|
19
|
+
connected = false;
|
|
20
|
+
errorCount = 0;
|
|
21
|
+
successCount = 0;
|
|
22
|
+
lastHealthCheck = new Date();
|
|
23
|
+
responseTimings = [];
|
|
24
|
+
macroGenerator;
|
|
25
|
+
tempMacroPath;
|
|
26
|
+
constructor() {
|
|
27
|
+
this.macroGenerator = new MacroGenerator();
|
|
28
|
+
this.tempMacroPath = path.join(process.env.TEMP || '/tmp', 'solidworks_mcp_macros');
|
|
29
|
+
}
|
|
30
|
+
async connect() {
|
|
31
|
+
const startTime = Date.now();
|
|
32
|
+
try {
|
|
33
|
+
// Ensure temp macro directory exists
|
|
34
|
+
await fs.mkdir(this.tempMacroPath, { recursive: true });
|
|
35
|
+
// Try primary connection method
|
|
36
|
+
try {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
this.swApp = new winax.Object('SldWorks.Application');
|
|
39
|
+
}
|
|
40
|
+
catch (_error) {
|
|
41
|
+
// Try alternative connection method
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
this.swApp = winax.Object('SldWorks.Application');
|
|
44
|
+
}
|
|
45
|
+
if (!this.swApp) {
|
|
46
|
+
throw new Error('Failed to create SolidWorks COM object');
|
|
47
|
+
}
|
|
48
|
+
// Make SolidWorks visible
|
|
49
|
+
this.swApp.Visible = true;
|
|
50
|
+
// Verify connection by getting process ID
|
|
51
|
+
try {
|
|
52
|
+
const processId = this.swApp.GetProcessID();
|
|
53
|
+
if (processId > 0) {
|
|
54
|
+
this.connected = true;
|
|
55
|
+
this.successCount++;
|
|
56
|
+
logger.info(`Connected to SolidWorks (PID: ${processId})`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (_e) {
|
|
60
|
+
// GetProcessID might not be available, assume connected
|
|
61
|
+
this.connected = true;
|
|
62
|
+
this.successCount++;
|
|
63
|
+
logger.info('Connected to SolidWorks');
|
|
64
|
+
}
|
|
65
|
+
const duration = Date.now() - startTime;
|
|
66
|
+
this.responseTimings.push(duration);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
this.errorCount++;
|
|
70
|
+
this.connected = false;
|
|
71
|
+
logger.error('Failed to connect to SolidWorks', error);
|
|
72
|
+
throw new Error(`Failed to connect to SolidWorks: ${error}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async disconnect() {
|
|
76
|
+
try {
|
|
77
|
+
if (this.currentModel) {
|
|
78
|
+
this.currentModel = null;
|
|
79
|
+
}
|
|
80
|
+
if (this.swApp) {
|
|
81
|
+
// Don't close SolidWorks, just disconnect
|
|
82
|
+
this.swApp = null;
|
|
83
|
+
}
|
|
84
|
+
this.connected = false;
|
|
85
|
+
logger.info('Disconnected from SolidWorks');
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
logger.error('Error during disconnect', error);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
isConnected() {
|
|
93
|
+
return this.connected;
|
|
94
|
+
}
|
|
95
|
+
async healthCheck() {
|
|
96
|
+
const startTime = Date.now();
|
|
97
|
+
let healthy = false;
|
|
98
|
+
let connectionStatus = 'disconnected';
|
|
99
|
+
try {
|
|
100
|
+
if (this.swApp) {
|
|
101
|
+
// Try to get active document or process ID
|
|
102
|
+
try {
|
|
103
|
+
const processId = this.swApp.GetProcessID();
|
|
104
|
+
if (processId > 0) {
|
|
105
|
+
healthy = true;
|
|
106
|
+
connectionStatus = 'connected';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (_e) {
|
|
110
|
+
// Try alternative health check
|
|
111
|
+
try {
|
|
112
|
+
const _docCount = this.swApp.GetDocumentCount();
|
|
113
|
+
healthy = true;
|
|
114
|
+
connectionStatus = 'connected';
|
|
115
|
+
}
|
|
116
|
+
catch (_e2) {
|
|
117
|
+
connectionStatus = 'error';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (_error) {
|
|
123
|
+
connectionStatus = 'error';
|
|
124
|
+
this.errorCount++;
|
|
125
|
+
}
|
|
126
|
+
const duration = Date.now() - startTime;
|
|
127
|
+
this.responseTimings.push(duration);
|
|
128
|
+
// Keep only last 100 timings
|
|
129
|
+
if (this.responseTimings.length > 100) {
|
|
130
|
+
this.responseTimings = this.responseTimings.slice(-100);
|
|
131
|
+
}
|
|
132
|
+
const avgResponseTime = this.responseTimings.length > 0
|
|
133
|
+
? this.responseTimings.reduce((a, b) => a + b, 0) / this.responseTimings.length
|
|
134
|
+
: 0;
|
|
135
|
+
this.lastHealthCheck = new Date();
|
|
136
|
+
return {
|
|
137
|
+
healthy,
|
|
138
|
+
lastCheck: this.lastHealthCheck,
|
|
139
|
+
errorCount: this.errorCount,
|
|
140
|
+
successCount: this.successCount,
|
|
141
|
+
averageResponseTime: avgResponseTime,
|
|
142
|
+
connectionStatus,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async execute(command) {
|
|
146
|
+
const startTime = Date.now();
|
|
147
|
+
try {
|
|
148
|
+
// Validate command
|
|
149
|
+
const validation = command.validate();
|
|
150
|
+
if (!validation.valid) {
|
|
151
|
+
throw new Error(`Command validation failed: ${validation.errors?.join(', ')}`);
|
|
152
|
+
}
|
|
153
|
+
// Execute based on command name
|
|
154
|
+
let result;
|
|
155
|
+
switch (command.name) {
|
|
156
|
+
case 'CreateExtrusion':
|
|
157
|
+
result = await this.createExtrusion(command.parameters);
|
|
158
|
+
break;
|
|
159
|
+
case 'CreateRevolve':
|
|
160
|
+
result = await this.createRevolve(command.parameters);
|
|
161
|
+
break;
|
|
162
|
+
case 'OpenModel':
|
|
163
|
+
result = await this.openModel(command.parameters.filePath);
|
|
164
|
+
break;
|
|
165
|
+
case 'CloseModel':
|
|
166
|
+
result = await this.closeModel(command.parameters.save);
|
|
167
|
+
break;
|
|
168
|
+
case 'CreatePart':
|
|
169
|
+
result = await this.createPart();
|
|
170
|
+
break;
|
|
171
|
+
case 'ExportFile':
|
|
172
|
+
result = await this.exportFile(command.parameters.filePath, command.parameters.format);
|
|
173
|
+
break;
|
|
174
|
+
default:
|
|
175
|
+
// Try generic method execution
|
|
176
|
+
result = await this.executeRaw(command.name, Object.values(command.parameters));
|
|
177
|
+
}
|
|
178
|
+
const endTime = Date.now();
|
|
179
|
+
const duration = endTime - startTime;
|
|
180
|
+
this.successCount++;
|
|
181
|
+
this.responseTimings.push(duration);
|
|
182
|
+
return {
|
|
183
|
+
success: true,
|
|
184
|
+
data: result,
|
|
185
|
+
timing: {
|
|
186
|
+
start: startTime,
|
|
187
|
+
end: endTime,
|
|
188
|
+
duration,
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
this.errorCount++;
|
|
194
|
+
// Try fallback if available
|
|
195
|
+
if (command.fallback) {
|
|
196
|
+
logger.info(`Executing fallback for ${command.name}`);
|
|
197
|
+
return this.execute(command.fallback);
|
|
198
|
+
}
|
|
199
|
+
const endTime = Date.now();
|
|
200
|
+
return {
|
|
201
|
+
success: false,
|
|
202
|
+
error: error instanceof Error ? error.message : String(error),
|
|
203
|
+
timing: {
|
|
204
|
+
start: startTime,
|
|
205
|
+
end: endTime,
|
|
206
|
+
duration: endTime - startTime,
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async executeRaw(method, args) {
|
|
212
|
+
if (!this.swApp) {
|
|
213
|
+
throw new Error('Not connected to SolidWorks');
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
// Get the target object (app or current model)
|
|
217
|
+
const target = this.currentModel || this.swApp;
|
|
218
|
+
// Try to execute the method
|
|
219
|
+
if (typeof target[method] === 'function') {
|
|
220
|
+
return target[method](...args);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
throw new Error(`Method ${method} not found`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
logger.error(`Failed to execute raw method: ${method}`, error);
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async openModel(filePath) {
|
|
232
|
+
if (!this.swApp)
|
|
233
|
+
throw new Error('Not connected to SolidWorks');
|
|
234
|
+
const errors = { value: 0 };
|
|
235
|
+
const warnings = { value: 0 };
|
|
236
|
+
// Determine file type from extension
|
|
237
|
+
const ext = filePath.toLowerCase().split('.').pop();
|
|
238
|
+
let docType = 1; // swDocPART
|
|
239
|
+
if (ext === 'sldasm')
|
|
240
|
+
docType = 2; // swDocASSEMBLY
|
|
241
|
+
if (ext === 'slddrw')
|
|
242
|
+
docType = 3; // swDocDRAWING
|
|
243
|
+
this.currentModel = this.swApp.OpenDoc6(filePath, docType, 1, // swOpenDocOptions_Silent
|
|
244
|
+
'', errors, warnings);
|
|
245
|
+
if (!this.currentModel) {
|
|
246
|
+
throw new Error(`Failed to open model: ${filePath}`);
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
path: filePath,
|
|
250
|
+
name: this.currentModel.GetTitle(),
|
|
251
|
+
type: ['Part', 'Assembly', 'Drawing'][docType - 1],
|
|
252
|
+
isActive: true,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
async closeModel(save = false) {
|
|
256
|
+
if (!this.currentModel)
|
|
257
|
+
return;
|
|
258
|
+
if (save) {
|
|
259
|
+
try {
|
|
260
|
+
this.currentModel.Save3(1, 0, 0); // swSaveAsOptions_Silent
|
|
261
|
+
}
|
|
262
|
+
catch (_e) {
|
|
263
|
+
// Try alternative save
|
|
264
|
+
this.currentModel.Save();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
const modelTitle = this.currentModel.GetTitle();
|
|
268
|
+
if (this.swApp && modelTitle) {
|
|
269
|
+
this.swApp.CloseDoc(modelTitle);
|
|
270
|
+
}
|
|
271
|
+
this.currentModel = null;
|
|
272
|
+
}
|
|
273
|
+
async createPart() {
|
|
274
|
+
if (!this.swApp)
|
|
275
|
+
throw new Error('Not connected to SolidWorks');
|
|
276
|
+
this.currentModel = this.swApp.NewPart();
|
|
277
|
+
if (!this.currentModel) {
|
|
278
|
+
// Fallback to template-based creation
|
|
279
|
+
const template = this.swApp.GetUserPreferenceStringValue(8) || '';
|
|
280
|
+
this.currentModel = this.swApp.NewDocument(template, 0, 0, 0);
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
path: '',
|
|
284
|
+
name: this.currentModel.GetTitle(),
|
|
285
|
+
type: 'Part',
|
|
286
|
+
isActive: true,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
async createAssembly() {
|
|
290
|
+
if (!this.swApp)
|
|
291
|
+
throw new Error('Not connected to SolidWorks');
|
|
292
|
+
this.currentModel = this.swApp.NewAssembly();
|
|
293
|
+
return {
|
|
294
|
+
path: '',
|
|
295
|
+
name: this.currentModel.GetTitle(),
|
|
296
|
+
type: 'Assembly',
|
|
297
|
+
isActive: true,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
async createDrawing() {
|
|
301
|
+
if (!this.swApp)
|
|
302
|
+
throw new Error('Not connected to SolidWorks');
|
|
303
|
+
this.currentModel = this.swApp.NewDrawing();
|
|
304
|
+
return {
|
|
305
|
+
path: '',
|
|
306
|
+
name: this.currentModel.GetTitle(),
|
|
307
|
+
type: 'Drawing',
|
|
308
|
+
isActive: true,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
async createExtrusion(params) {
|
|
312
|
+
if (!this.currentModel)
|
|
313
|
+
throw new Error('No active model');
|
|
314
|
+
// Check if we need to use macro fallback for complex parameters
|
|
315
|
+
const needsMacroFallback = this.requiresMacroFallback(params);
|
|
316
|
+
if (needsMacroFallback) {
|
|
317
|
+
logger.info('Using macro fallback for extrusion due to parameter complexity');
|
|
318
|
+
return this.createExtrusionViaMacro(params);
|
|
319
|
+
}
|
|
320
|
+
try {
|
|
321
|
+
// Use simplified parameters for direct COM call
|
|
322
|
+
const featureMgr = this.currentModel.FeatureManager;
|
|
323
|
+
// Exit sketch mode if active
|
|
324
|
+
const sketchMgr = this.currentModel.SketchManager;
|
|
325
|
+
if (sketchMgr.ActiveSketch) {
|
|
326
|
+
sketchMgr.InsertSketch(true);
|
|
327
|
+
}
|
|
328
|
+
// Clear selections
|
|
329
|
+
this.currentModel.ClearSelection2(true);
|
|
330
|
+
// Select sketch
|
|
331
|
+
this.selectSketchForExtrusion();
|
|
332
|
+
// Convert depth to meters
|
|
333
|
+
const depthInMeters = params.depth / 1000;
|
|
334
|
+
// Try simple extrusion with limited parameters
|
|
335
|
+
let feature = null;
|
|
336
|
+
try {
|
|
337
|
+
// Method 1: Try with minimal parameters using array
|
|
338
|
+
const args = [
|
|
339
|
+
true, // Single direction
|
|
340
|
+
params.reverse || false, // Flip
|
|
341
|
+
false, // Dir (both directions)
|
|
342
|
+
0, // T1 (blind)
|
|
343
|
+
0, // T2
|
|
344
|
+
depthInMeters, // D1 (depth)
|
|
345
|
+
0, // D2
|
|
346
|
+
false, // Dchk1
|
|
347
|
+
false, // Dchk2
|
|
348
|
+
false, // Ddir1
|
|
349
|
+
false, // Ddir2
|
|
350
|
+
params.draft || 0, // Dang1
|
|
351
|
+
0, // Dang2
|
|
352
|
+
];
|
|
353
|
+
// Try direct call with spread operator
|
|
354
|
+
feature = featureMgr.FeatureExtrusion(...args);
|
|
355
|
+
}
|
|
356
|
+
catch (_e) {
|
|
357
|
+
logger.warn('Direct extrusion failed, trying alternative method');
|
|
358
|
+
// Method 2: Try FeatureExtrusion2 if available
|
|
359
|
+
try {
|
|
360
|
+
feature = featureMgr.FeatureExtrusion2(true, // Sd
|
|
361
|
+
params.reverse || false, // Flip
|
|
362
|
+
false, // Dir
|
|
363
|
+
0, // T1
|
|
364
|
+
0, // T2
|
|
365
|
+
depthInMeters, // D1
|
|
366
|
+
0, // D2
|
|
367
|
+
false, // Dchk1
|
|
368
|
+
false, // Dchk2
|
|
369
|
+
false, // Ddir1
|
|
370
|
+
false // Ddir2
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
catch (_e2) {
|
|
374
|
+
// Method 3: Use macro fallback
|
|
375
|
+
logger.warn('All direct methods failed, using macro fallback');
|
|
376
|
+
return this.createExtrusionViaMacro(params);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (!feature) {
|
|
380
|
+
throw new Error('Failed to create extrusion feature');
|
|
381
|
+
}
|
|
382
|
+
// Clear selections and rebuild
|
|
383
|
+
this.currentModel.ClearSelection2(true);
|
|
384
|
+
this.currentModel.EditRebuild3();
|
|
385
|
+
return {
|
|
386
|
+
name: feature.Name || 'Boss-Extrude1',
|
|
387
|
+
type: 'Extrusion',
|
|
388
|
+
suppressed: false,
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
catch (error) {
|
|
392
|
+
logger.error('Extrusion failed', error);
|
|
393
|
+
// Final fallback to macro
|
|
394
|
+
return this.createExtrusionViaMacro(params);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
requiresMacroFallback(params) {
|
|
398
|
+
// Check if parameters exceed what direct COM can handle
|
|
399
|
+
const complexParams = [
|
|
400
|
+
'draftWhileExtruding',
|
|
401
|
+
'offsetDistance',
|
|
402
|
+
'offsetReverse',
|
|
403
|
+
'translateSurface',
|
|
404
|
+
'flipSideToCut',
|
|
405
|
+
'startCondition',
|
|
406
|
+
'endCondition',
|
|
407
|
+
'thinFeature',
|
|
408
|
+
'thinThickness',
|
|
409
|
+
];
|
|
410
|
+
return complexParams.some((param) => params[param] !== undefined);
|
|
411
|
+
}
|
|
412
|
+
async createExtrusionViaMacro(params) {
|
|
413
|
+
// Generate VBA macro for complex extrusion
|
|
414
|
+
const macroCode = this.macroGenerator.generateExtrusionMacro(params);
|
|
415
|
+
// Save macro to temp file
|
|
416
|
+
const macroPath = path.join(this.tempMacroPath, `extrusion_${Date.now()}.swp`);
|
|
417
|
+
await fs.writeFile(macroPath, macroCode);
|
|
418
|
+
try {
|
|
419
|
+
// Execute the macro
|
|
420
|
+
const _result = this.swApp.RunMacro2(macroPath, 'Module1', 'CreateExtrusion', 1, // swRunMacroOption
|
|
421
|
+
0 // error
|
|
422
|
+
);
|
|
423
|
+
// Get the last feature created
|
|
424
|
+
const feature = this.currentModel.FeatureByPositionReverse(0);
|
|
425
|
+
return {
|
|
426
|
+
name: feature?.Name || 'Boss-Extrude1',
|
|
427
|
+
type: 'Extrusion',
|
|
428
|
+
suppressed: false,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
finally {
|
|
432
|
+
// Clean up temp macro file
|
|
433
|
+
try {
|
|
434
|
+
await fs.unlink(macroPath);
|
|
435
|
+
}
|
|
436
|
+
catch (_e) {
|
|
437
|
+
// Ignore cleanup errors
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
selectSketchForExtrusion() {
|
|
442
|
+
// Method 1 (most reliable): Feature tree traversal
|
|
443
|
+
// Avoids SelectByID2 COM type mismatch issues
|
|
444
|
+
try {
|
|
445
|
+
const featureCount = this.currentModel.GetFeatureCount();
|
|
446
|
+
for (let i = 0; i < Math.min(10, featureCount); i++) {
|
|
447
|
+
const feat = this.currentModel.FeatureByPositionReverse(i);
|
|
448
|
+
if (feat) {
|
|
449
|
+
const typeName = feat.GetTypeName2();
|
|
450
|
+
if (typeName === 'ProfileFeature' || typeName?.toLowerCase().includes('sketch')) {
|
|
451
|
+
feat.Select2(false, 0);
|
|
452
|
+
logger.info(`Selected sketch by feature tree: ${feat.Name || feat.GetName()}`);
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
catch (e) {
|
|
459
|
+
logger.warn(`Feature tree search failed: ${e}`);
|
|
460
|
+
}
|
|
461
|
+
// Method 2 (fallback): SelectByID2 with undefined for optional params
|
|
462
|
+
const ext = this.currentModel.Extension;
|
|
463
|
+
const sketchNames = ['Sketch1', 'Sketch2', 'Sketch3', 'Sketch4', 'Sketch5'];
|
|
464
|
+
for (const name of sketchNames) {
|
|
465
|
+
try {
|
|
466
|
+
const selected = ext.SelectByID2(name, 'SKETCH', 0, 0, 0, false, 0, undefined, 0);
|
|
467
|
+
if (selected) {
|
|
468
|
+
logger.info(`Selected sketch via SelectByID2: ${name}`);
|
|
469
|
+
return true;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
catch (_e) {
|
|
473
|
+
// Try next name
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
async createRevolve(params) {
|
|
479
|
+
if (!this.currentModel)
|
|
480
|
+
throw new Error('No active model');
|
|
481
|
+
// For revolve, we'll use macro fallback for now
|
|
482
|
+
const macroCode = this.macroGenerator.generateRevolveMacro(params);
|
|
483
|
+
const macroPath = path.join(this.tempMacroPath, `revolve_${Date.now()}.swp`);
|
|
484
|
+
await fs.writeFile(macroPath, macroCode);
|
|
485
|
+
try {
|
|
486
|
+
this.swApp.RunMacro2(macroPath, 'Module1', 'CreateRevolve', 1, 0);
|
|
487
|
+
const feature = this.currentModel.FeatureByPositionReverse(0);
|
|
488
|
+
return {
|
|
489
|
+
name: feature?.Name || 'Revolve1',
|
|
490
|
+
type: 'Revolution',
|
|
491
|
+
suppressed: false,
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
finally {
|
|
495
|
+
await fs.unlink(macroPath).catch(() => { });
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
async createSweep(params) {
|
|
499
|
+
if (!this.currentModel)
|
|
500
|
+
throw new Error('No active model');
|
|
501
|
+
const macroCode = this.macroGenerator.generateSweepMacro(params);
|
|
502
|
+
const macroPath = path.join(this.tempMacroPath, `sweep_${Date.now()}.swp`);
|
|
503
|
+
await fs.writeFile(macroPath, macroCode);
|
|
504
|
+
try {
|
|
505
|
+
this.swApp.RunMacro2(macroPath, 'Module1', 'CreateSweep', 1, 0);
|
|
506
|
+
const feature = this.currentModel.FeatureByPositionReverse(0);
|
|
507
|
+
return {
|
|
508
|
+
name: feature?.Name || 'Sweep1',
|
|
509
|
+
type: 'Sweep',
|
|
510
|
+
suppressed: false,
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
finally {
|
|
514
|
+
await fs.unlink(macroPath).catch(() => { });
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
async createLoft(params) {
|
|
518
|
+
if (!this.currentModel)
|
|
519
|
+
throw new Error('No active model');
|
|
520
|
+
const macroCode = this.macroGenerator.generateLoftMacro(params);
|
|
521
|
+
const macroPath = path.join(this.tempMacroPath, `loft_${Date.now()}.swp`);
|
|
522
|
+
await fs.writeFile(macroPath, macroCode);
|
|
523
|
+
try {
|
|
524
|
+
this.swApp.RunMacro2(macroPath, 'Module1', 'CreateLoft', 1, 0);
|
|
525
|
+
const feature = this.currentModel.FeatureByPositionReverse(0);
|
|
526
|
+
return {
|
|
527
|
+
name: feature?.Name || 'Loft1',
|
|
528
|
+
type: 'Loft',
|
|
529
|
+
suppressed: false,
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
finally {
|
|
533
|
+
await fs.unlink(macroPath).catch(() => { });
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
async createSketch(plane) {
|
|
537
|
+
if (!this.currentModel)
|
|
538
|
+
throw new Error('No active model');
|
|
539
|
+
const sketchMgr = this.currentModel.SketchManager;
|
|
540
|
+
const ext = this.currentModel.Extension;
|
|
541
|
+
// Select the plane
|
|
542
|
+
const selected = ext.SelectByID2(plane, 'PLANE', 0, 0, 0, false, 0, undefined, 0);
|
|
543
|
+
if (!selected) {
|
|
544
|
+
throw new Error(`Failed to select plane: ${plane}`);
|
|
545
|
+
}
|
|
546
|
+
// Insert sketch
|
|
547
|
+
sketchMgr.InsertSketch(true);
|
|
548
|
+
const sketchName = sketchMgr.ActiveSketch?.Name || `Sketch${Date.now()}`;
|
|
549
|
+
return sketchName;
|
|
550
|
+
}
|
|
551
|
+
async addLine(x1, y1, x2, y2) {
|
|
552
|
+
if (!this.currentModel)
|
|
553
|
+
throw new Error('No active model');
|
|
554
|
+
const sketchMgr = this.currentModel.SketchManager;
|
|
555
|
+
const line = sketchMgr.CreateLine(x1 / 1000, y1 / 1000, 0, x2 / 1000, y2 / 1000, 0);
|
|
556
|
+
if (!line) {
|
|
557
|
+
throw new Error('Failed to create line');
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
async addCircle(centerX, centerY, radius) {
|
|
561
|
+
if (!this.currentModel)
|
|
562
|
+
throw new Error('No active model');
|
|
563
|
+
const sketchMgr = this.currentModel.SketchManager;
|
|
564
|
+
const circle = sketchMgr.CreateCircle(centerX / 1000, centerY / 1000, 0, radius / 1000);
|
|
565
|
+
if (!circle) {
|
|
566
|
+
throw new Error('Failed to create circle');
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
async addRectangle(x1, y1, x2, y2) {
|
|
570
|
+
if (!this.currentModel)
|
|
571
|
+
throw new Error('No active model');
|
|
572
|
+
const _sketchMgr = this.currentModel.SketchManager;
|
|
573
|
+
// Create four lines for rectangle
|
|
574
|
+
await this.addLine(x1, y1, x2, y1);
|
|
575
|
+
await this.addLine(x2, y1, x2, y2);
|
|
576
|
+
await this.addLine(x2, y2, x1, y2);
|
|
577
|
+
await this.addLine(x1, y2, x1, y1);
|
|
578
|
+
}
|
|
579
|
+
async exitSketch() {
|
|
580
|
+
if (!this.currentModel)
|
|
581
|
+
throw new Error('No active model');
|
|
582
|
+
const sketchMgr = this.currentModel.SketchManager;
|
|
583
|
+
sketchMgr.InsertSketch(true);
|
|
584
|
+
}
|
|
585
|
+
async getMassProperties() {
|
|
586
|
+
if (!this.currentModel)
|
|
587
|
+
throw new Error('No active model');
|
|
588
|
+
const ext = this.currentModel.Extension;
|
|
589
|
+
const massProps = ext.CreateMassProperty();
|
|
590
|
+
if (!massProps) {
|
|
591
|
+
throw new Error('Failed to create mass property object');
|
|
592
|
+
}
|
|
593
|
+
// Update mass properties
|
|
594
|
+
massProps.Update();
|
|
595
|
+
const com = massProps.CenterOfMass;
|
|
596
|
+
return {
|
|
597
|
+
mass: massProps.Mass,
|
|
598
|
+
volume: massProps.Volume,
|
|
599
|
+
surfaceArea: massProps.SurfaceArea,
|
|
600
|
+
centerOfMass: {
|
|
601
|
+
x: com[0] * 1000, // Convert to mm
|
|
602
|
+
y: com[1] * 1000,
|
|
603
|
+
z: com[2] * 1000,
|
|
604
|
+
},
|
|
605
|
+
density: massProps.Density,
|
|
606
|
+
momentsOfInertia: {
|
|
607
|
+
Ixx: massProps.MomentOfInertia[0],
|
|
608
|
+
Iyy: massProps.MomentOfInertia[4],
|
|
609
|
+
Izz: massProps.MomentOfInertia[8],
|
|
610
|
+
Ixy: massProps.MomentOfInertia[1],
|
|
611
|
+
Iyz: massProps.MomentOfInertia[5],
|
|
612
|
+
Ixz: massProps.MomentOfInertia[2],
|
|
613
|
+
},
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
async exportFile(filePath, format) {
|
|
617
|
+
if (!this.currentModel)
|
|
618
|
+
throw new Error('No active model');
|
|
619
|
+
const ext = format.toLowerCase();
|
|
620
|
+
let success = false;
|
|
621
|
+
switch (ext) {
|
|
622
|
+
case 'step':
|
|
623
|
+
case 'stp':
|
|
624
|
+
case 'iges':
|
|
625
|
+
case 'igs':
|
|
626
|
+
case 'stl':
|
|
627
|
+
case 'pdf':
|
|
628
|
+
case 'dxf':
|
|
629
|
+
case 'dwg':
|
|
630
|
+
success = this.currentModel.SaveAs3(filePath, 0, 2);
|
|
631
|
+
break;
|
|
632
|
+
default:
|
|
633
|
+
throw new Error(`Unsupported export format: ${format}`);
|
|
634
|
+
}
|
|
635
|
+
if (!success) {
|
|
636
|
+
throw new Error(`Failed to export to ${format}`);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
async getDimension(name) {
|
|
640
|
+
if (!this.currentModel)
|
|
641
|
+
throw new Error('No active model');
|
|
642
|
+
const dimension = this.currentModel.Parameter(name);
|
|
643
|
+
if (!dimension) {
|
|
644
|
+
throw new Error(`Dimension ${name} not found`);
|
|
645
|
+
}
|
|
646
|
+
return dimension.SystemValue * 1000; // Convert to mm
|
|
647
|
+
}
|
|
648
|
+
async setDimension(name, value) {
|
|
649
|
+
if (!this.currentModel)
|
|
650
|
+
throw new Error('No active model');
|
|
651
|
+
const dimension = this.currentModel.Parameter(name);
|
|
652
|
+
if (!dimension) {
|
|
653
|
+
throw new Error(`Dimension ${name} not found`);
|
|
654
|
+
}
|
|
655
|
+
dimension.SystemValue = value / 1000; // Convert to meters
|
|
656
|
+
this.currentModel.EditRebuild3();
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Factory function to create WinAx adapter
|
|
661
|
+
*/
|
|
662
|
+
export async function createWinAxAdapter() {
|
|
663
|
+
const adapter = new WinAxAdapter();
|
|
664
|
+
await adapter.connect();
|
|
665
|
+
return adapter;
|
|
666
|
+
}
|
|
667
|
+
//# sourceMappingURL=winax-adapter.js.map
|