solidworks-mcp-python 1.5.0__py3-none-any.whl
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.
- solidworks_mcp/__init__.py +57 -0
- solidworks_mcp/adapters/__init__.py +40 -0
- solidworks_mcp/adapters/base.py +1882 -0
- solidworks_mcp/adapters/circuit_breaker.py +2052 -0
- solidworks_mcp/adapters/com_executor.py +252 -0
- solidworks_mcp/adapters/complexity_analyzer.py +272 -0
- solidworks_mcp/adapters/connection_pool.py +1884 -0
- solidworks_mcp/adapters/factory.py +366 -0
- solidworks_mcp/adapters/intelligent_router.py +218 -0
- solidworks_mcp/adapters/mock_adapter.py +4016 -0
- solidworks_mcp/adapters/pywin32_adapter.py +2842 -0
- solidworks_mcp/adapters/solidworks/__init__.py +17 -0
- solidworks_mcp/adapters/solidworks/bitmap.py +180 -0
- solidworks_mcp/adapters/solidworks/com_utils.py +56 -0
- solidworks_mcp/adapters/solidworks/dimension_layout.py +753 -0
- solidworks_mcp/adapters/solidworks/documentation.py +1476 -0
- solidworks_mcp/adapters/solidworks/drawing_standard.py +1993 -0
- solidworks_mcp/adapters/solidworks/face_selection.py +392 -0
- solidworks_mcp/adapters/solidworks/features.py +3362 -0
- solidworks_mcp/adapters/solidworks/io.py +3649 -0
- solidworks_mcp/adapters/solidworks/rebuild_diagnostics.py +269 -0
- solidworks_mcp/adapters/solidworks/rebuild_inspector.py +146 -0
- solidworks_mcp/adapters/solidworks/selection.py +308 -0
- solidworks_mcp/adapters/solidworks/sketch.py +2545 -0
- solidworks_mcp/adapters/sw_feature_errors.py +66 -0
- solidworks_mcp/adapters/sw_type_info.py +317 -0
- solidworks_mcp/adapters/vba_adapter.py +318 -0
- solidworks_mcp/adapters/vba_macro_executor.py +215 -0
- solidworks_mcp/agents/__init__.py +68 -0
- solidworks_mcp/agents/design_knowledge/assembly_patterns.md +127 -0
- solidworks_mcp/agents/design_knowledge/hinges.md +118 -0
- solidworks_mcp/agents/design_knowledge/snap_fits.md +93 -0
- solidworks_mcp/agents/design_knowledge/solidworks_basics.md +3 -0
- solidworks_mcp/agents/design_knowledge/tolerancing.md +128 -0
- solidworks_mcp/agents/harness.py +216 -0
- solidworks_mcp/agents/history_db.py +1508 -0
- solidworks_mcp/agents/retrieval_index.py +164 -0
- solidworks_mcp/agents/schemas.py +165 -0
- solidworks_mcp/agents/smoke_test.py +285 -0
- solidworks_mcp/agents/soc_exporter.py +650 -0
- solidworks_mcp/agents/soc_pickup.py +332 -0
- solidworks_mcp/agents/soc_rewind.py +221 -0
- solidworks_mcp/agents/vector_rag.py +665 -0
- solidworks_mcp/cache/__init__.py +5 -0
- solidworks_mcp/cache/response_cache.py +164 -0
- solidworks_mcp/config.py +729 -0
- solidworks_mcp/exceptions.py +37 -0
- solidworks_mcp/security/__init__.py +68 -0
- solidworks_mcp/security/auth.py +128 -0
- solidworks_mcp/security/cors.py +27 -0
- solidworks_mcp/security/rate_limiting.py +90 -0
- solidworks_mcp/security/runtime.py +155 -0
- solidworks_mcp/server.py +777 -0
- solidworks_mcp/server_cli_fixed.py +120 -0
- solidworks_mcp/setup/__init__.py +1 -0
- solidworks_mcp/setup/cli.py +399 -0
- solidworks_mcp/setup/clients.py +157 -0
- solidworks_mcp/setup/config_file.py +230 -0
- solidworks_mcp/setup/handshake.py +202 -0
- solidworks_mcp/setup/launcher.py +102 -0
- solidworks_mcp/setup/legacy.py +100 -0
- solidworks_mcp/setup/registration.py +193 -0
- solidworks_mcp/setup/solidworks.py +49 -0
- solidworks_mcp/tools/__init__.py +64 -0
- solidworks_mcp/tools/analysis.py +723 -0
- solidworks_mcp/tools/automation.py +578 -0
- solidworks_mcp/tools/docs_discovery.py +1476 -0
- solidworks_mcp/tools/drawing.py +1015 -0
- solidworks_mcp/tools/drawing_analysis.py +456 -0
- solidworks_mcp/tools/drawing_automation.py +627 -0
- solidworks_mcp/tools/engineering_data.py +466 -0
- solidworks_mcp/tools/error_classifier.py +232 -0
- solidworks_mcp/tools/export.py +833 -0
- solidworks_mcp/tools/file_facts.py +40 -0
- solidworks_mcp/tools/file_management.py +1473 -0
- solidworks_mcp/tools/input_compat.py +17 -0
- solidworks_mcp/tools/macro_recording.py +464 -0
- solidworks_mcp/tools/modeling.py +2360 -0
- solidworks_mcp/tools/sketching.py +1422 -0
- solidworks_mcp/tools/template_management.py +367 -0
- solidworks_mcp/tools/tool_boundary.py +280 -0
- solidworks_mcp/tools/vba_generation.py +1145 -0
- solidworks_mcp/ui/__init__.py +9 -0
- solidworks_mcp/ui/local_llm.py +725 -0
- solidworks_mcp/ui/routers/__init__.py +10 -0
- solidworks_mcp/ui/routers/checkpoint.py +24 -0
- solidworks_mcp/ui/routers/docs.py +47 -0
- solidworks_mcp/ui/routers/llm.py +83 -0
- solidworks_mcp/ui/routers/local_model.py +69 -0
- solidworks_mcp/ui/routers/model.py +75 -0
- solidworks_mcp/ui/routers/preview.py +38 -0
- solidworks_mcp/ui/routers/session.py +161 -0
- solidworks_mcp/ui/routers/viewer.py +154 -0
- solidworks_mcp/ui/schemas.py +502 -0
- solidworks_mcp/ui/server.py +298 -0
- solidworks_mcp/ui/service.py +481 -0
- solidworks_mcp/ui/services/__init__.py +136 -0
- solidworks_mcp/ui/services/_utils.py +958 -0
- solidworks_mcp/ui/services/checkpoint_service.py +1110 -0
- solidworks_mcp/ui/services/docs_service.py +282 -0
- solidworks_mcp/ui/services/llm_service.py +956 -0
- solidworks_mcp/ui/services/model_service.py +459 -0
- solidworks_mcp/ui/services/parameter_repair_service.py +314 -0
- solidworks_mcp/ui/services/preview_service.py +489 -0
- solidworks_mcp/ui/services/session_service.py +1389 -0
- solidworks_mcp/utils/__init__.py +9 -0
- solidworks_mcp/utils/feature_tree_classifier.py +342 -0
- solidworks_mcp/utils/logging.py +76 -0
- solidworks_mcp/utils/validation.py +77 -0
- solidworks_mcp/version.py +8 -0
- solidworks_mcp_python-1.5.0.dist-info/METADATA +410 -0
- solidworks_mcp_python-1.5.0.dist-info/RECORD +115 -0
- solidworks_mcp_python-1.5.0.dist-info/WHEEL +4 -0
- solidworks_mcp_python-1.5.0.dist-info/entry_points.txt +3 -0
- solidworks_mcp_python-1.5.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
"""Automation tools for SolidWorks MCP Server.
|
|
2
|
+
|
|
3
|
+
Use these when the workflow is already defined and you need repeatable execution.
|
|
4
|
+
Recommended order: generate_vba_code for complex steps, record or stop a macro when a
|
|
5
|
+
manual flow should be captured, batch_process_files for many files, manage_design_table
|
|
6
|
+
for configuration-driven variants, execute_workflow for scripted pipelines,
|
|
7
|
+
create_template for reusable standards, and optimize_performance for tuning.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from fastmcp import FastMCP
|
|
13
|
+
from pydantic import Field
|
|
14
|
+
|
|
15
|
+
from ..adapters.base import SolidWorksAdapter
|
|
16
|
+
from .input_compat import CompatInput
|
|
17
|
+
from .tool_boundary import (
|
|
18
|
+
UnsupportedOperationError,
|
|
19
|
+
require_capability,
|
|
20
|
+
require_success,
|
|
21
|
+
with_tool_boundary,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
# Input schemas using Python 3.14 built-in types
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class GenerateVBAInput(CompatInput):
|
|
28
|
+
"""Input schema for generating VBA code.
|
|
29
|
+
|
|
30
|
+
Attributes:
|
|
31
|
+
code_style (str): The code style value.
|
|
32
|
+
include_error_handling (bool): The include error handling value.
|
|
33
|
+
operation_description (str | None): The operation description value.
|
|
34
|
+
operation_type (str | None): The operation type value.
|
|
35
|
+
parameters (dict[str, Any]): The parameters value.
|
|
36
|
+
target_document (str): The target document value.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
operation_description: str | None = Field(
|
|
40
|
+
default=None, description="Description of the operation to generate VBA for"
|
|
41
|
+
)
|
|
42
|
+
operation_type: str | None = Field(default=None, description="Operation type alias")
|
|
43
|
+
parameters: dict[str, Any] = Field(
|
|
44
|
+
default_factory=dict, description="Operation parameters"
|
|
45
|
+
)
|
|
46
|
+
target_document: str = Field(
|
|
47
|
+
default="Part", description="Target document type (Part, Assembly, Drawing)"
|
|
48
|
+
)
|
|
49
|
+
include_error_handling: bool = Field(
|
|
50
|
+
default=True, description="Include error handling in generated code"
|
|
51
|
+
)
|
|
52
|
+
code_style: str = Field(
|
|
53
|
+
default="professional",
|
|
54
|
+
description="Code style (simple, professional, advanced)",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
def model_post_init(self, __context: Any) -> None:
|
|
58
|
+
"""Provide model post init support for the generate vbainput.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
__context (Any): The context value.
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
None: None.
|
|
65
|
+
"""
|
|
66
|
+
if self.operation_description is None:
|
|
67
|
+
self.operation_description = self.operation_type or "SolidWorks Operation"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
VBAGenerationInput = GenerateVBAInput
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class RecordMacroInput(CompatInput):
|
|
74
|
+
"""Input schema for macro recording.
|
|
75
|
+
|
|
76
|
+
Attributes:
|
|
77
|
+
auto_start (bool): The auto start value.
|
|
78
|
+
capture_keyboard (bool): The capture keyboard value.
|
|
79
|
+
capture_mouse (bool): The capture mouse value.
|
|
80
|
+
description (str): The description value.
|
|
81
|
+
macro_name (str | None): The macro name value.
|
|
82
|
+
output_file (str | None): The output file value.
|
|
83
|
+
recording_mode (str | None): The recording mode value.
|
|
84
|
+
recording_name (str | None): The recording name value.
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
macro_name: str | None = Field(
|
|
88
|
+
default=None, description="Name for the recorded macro"
|
|
89
|
+
)
|
|
90
|
+
recording_name: str | None = Field(default=None, description="Recording name alias")
|
|
91
|
+
output_file: str | None = Field(default=None, description="Output file alias")
|
|
92
|
+
recording_mode: str | None = Field(default=None, description="Recording mode alias")
|
|
93
|
+
capture_mouse: bool = Field(default=True, description="Capture mouse actions")
|
|
94
|
+
capture_keyboard: bool = Field(default=True, description="Capture keyboard actions")
|
|
95
|
+
description: str = Field(
|
|
96
|
+
default="", description="Description of the macro functionality"
|
|
97
|
+
)
|
|
98
|
+
auto_start: bool = Field(default=True, description="Automatically start recording")
|
|
99
|
+
|
|
100
|
+
def model_post_init(self, __context: Any) -> None:
|
|
101
|
+
"""Provide model post init support for the record macro input.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
__context (Any): The context value.
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
None: None.
|
|
108
|
+
"""
|
|
109
|
+
if self.macro_name is None:
|
|
110
|
+
self.macro_name = self.recording_name or "Recorded Macro"
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class BatchProcessInput(CompatInput):
|
|
114
|
+
"""Input schema for batch processing.
|
|
115
|
+
|
|
116
|
+
Attributes:
|
|
117
|
+
batch_operation (str | None): The batch operation value.
|
|
118
|
+
file_pattern (str | None): The file pattern value.
|
|
119
|
+
filter_patterns (list[str]): The filter patterns value.
|
|
120
|
+
operation (str | None): The operation value.
|
|
121
|
+
operation_type (str | None): The operation type value.
|
|
122
|
+
parallel_processing (bool): The parallel processing value.
|
|
123
|
+
recursive (bool): The recursive value.
|
|
124
|
+
source_directory (str): The source directory value.
|
|
125
|
+
target_format (str | None): The target format value.
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
source_directory: str = Field(description="Directory containing SolidWorks files")
|
|
129
|
+
operation_type: str | None = Field(
|
|
130
|
+
default=None,
|
|
131
|
+
description="Type of operation (rebuild, save_as, export, update_properties)",
|
|
132
|
+
)
|
|
133
|
+
batch_operation: str | None = Field(
|
|
134
|
+
default=None, description="Batch operation alias"
|
|
135
|
+
)
|
|
136
|
+
target_format: str | None = Field(
|
|
137
|
+
default=None, description="Target format for export operations"
|
|
138
|
+
)
|
|
139
|
+
file_pattern: str | None = Field(default=None, description="File pattern alias")
|
|
140
|
+
parallel_processing: bool = Field(
|
|
141
|
+
default=False, description="Parallel processing alias"
|
|
142
|
+
)
|
|
143
|
+
operation: str | None = Field(default=None, description="Operation alias")
|
|
144
|
+
recursive: bool = Field(
|
|
145
|
+
default=False, description="Process subdirectories recursively"
|
|
146
|
+
)
|
|
147
|
+
filter_patterns: list[str] = Field(
|
|
148
|
+
default=["*.sldprt", "*.sldasm"], description="File patterns to process"
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
def model_post_init(self, __context: Any) -> None:
|
|
152
|
+
"""Provide model post init support for the batch process input.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
__context (Any): The context value.
|
|
156
|
+
|
|
157
|
+
Returns:
|
|
158
|
+
None: None.
|
|
159
|
+
"""
|
|
160
|
+
if self.operation_type is None:
|
|
161
|
+
self.operation_type = self.batch_operation or self.operation or "export"
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
class DesignTableInput(CompatInput):
|
|
165
|
+
"""Input schema for design table operations.
|
|
166
|
+
|
|
167
|
+
Attributes:
|
|
168
|
+
auto_create_configurations (bool): The auto create configurations value.
|
|
169
|
+
auto_update (bool): The auto update value.
|
|
170
|
+
configurations (list[str]): The configurations value.
|
|
171
|
+
create_configurations (bool): The create configurations value.
|
|
172
|
+
excel_file (str | None): The excel file value.
|
|
173
|
+
model_path (str | None): The model path value.
|
|
174
|
+
operation (str | None): The operation value.
|
|
175
|
+
parameters (list[str]): The parameters value.
|
|
176
|
+
table_file (str | None): The table file value.
|
|
177
|
+
table_type (str | None): The table type value.
|
|
178
|
+
"""
|
|
179
|
+
|
|
180
|
+
table_type: str | None = Field(
|
|
181
|
+
default=None, description="Type of design table (create, update, import)"
|
|
182
|
+
)
|
|
183
|
+
model_path: str | None = Field(default=None, description="Model path alias")
|
|
184
|
+
table_file: str | None = Field(default=None, description="Design table file alias")
|
|
185
|
+
operation: str | None = Field(default=None, description="Operation alias")
|
|
186
|
+
auto_update: bool = Field(default=False, description="Auto update alias")
|
|
187
|
+
create_configurations: bool = Field(
|
|
188
|
+
default=False, description="Create configurations alias"
|
|
189
|
+
)
|
|
190
|
+
auto_create_configurations: bool = Field(
|
|
191
|
+
default=False, description="Auto-create alias"
|
|
192
|
+
)
|
|
193
|
+
excel_file: str | None = Field(
|
|
194
|
+
default=None, description="Excel file path for import/export"
|
|
195
|
+
)
|
|
196
|
+
parameters: list[str] = Field(
|
|
197
|
+
default=[], description="Parameters to include in design table"
|
|
198
|
+
)
|
|
199
|
+
configurations: list[str] = Field(default=[], description="Configuration names")
|
|
200
|
+
|
|
201
|
+
def model_post_init(self, __context: Any) -> None:
|
|
202
|
+
"""Provide model post init support for the design table input.
|
|
203
|
+
|
|
204
|
+
Args:
|
|
205
|
+
__context (Any): The context value.
|
|
206
|
+
|
|
207
|
+
Returns:
|
|
208
|
+
None: None.
|
|
209
|
+
"""
|
|
210
|
+
if self.table_type is None:
|
|
211
|
+
self.table_type = self.operation or "create"
|
|
212
|
+
if self.create_configurations:
|
|
213
|
+
self.auto_create_configurations = True
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
class WorkflowInput(CompatInput):
|
|
217
|
+
"""Input schema for workflow automation.
|
|
218
|
+
|
|
219
|
+
Attributes:
|
|
220
|
+
error_handling (str): The error handling value.
|
|
221
|
+
parallel_execution (bool): The parallel execution value.
|
|
222
|
+
steps (list[dict[str, Any]]): The steps value.
|
|
223
|
+
workflow_name (str): The workflow name value.
|
|
224
|
+
"""
|
|
225
|
+
|
|
226
|
+
workflow_name: str = Field(description="Name of the workflow")
|
|
227
|
+
steps: list[dict[str, Any]] = Field(description="List of workflow steps")
|
|
228
|
+
parallel_execution: bool = Field(
|
|
229
|
+
default=False, description="Execute compatible steps in parallel"
|
|
230
|
+
)
|
|
231
|
+
error_handling: str = Field(
|
|
232
|
+
default="stop", description="Error handling strategy (stop, skip, retry)"
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
class TemplateInput(CompatInput):
|
|
237
|
+
"""Input schema for template operations.
|
|
238
|
+
|
|
239
|
+
Attributes:
|
|
240
|
+
base_file (str | None): The base file value.
|
|
241
|
+
include_custom_properties (bool): The include custom properties value.
|
|
242
|
+
include_features (list[str]): The include features value.
|
|
243
|
+
include_materials (bool): The include materials value.
|
|
244
|
+
metadata (dict[str, Any]): The metadata value.
|
|
245
|
+
output_path (str | None): The output path value.
|
|
246
|
+
source_model (str | None): The source model value.
|
|
247
|
+
template_name (str): The template name value.
|
|
248
|
+
template_type (str): The template type value.
|
|
249
|
+
"""
|
|
250
|
+
|
|
251
|
+
template_type: str = Field(description="Type of template (part, assembly, drawing)")
|
|
252
|
+
template_name: str = Field(description="Name for the template")
|
|
253
|
+
base_file: str | None = Field(
|
|
254
|
+
default=None, description="Base file to create template from"
|
|
255
|
+
)
|
|
256
|
+
source_model: str | None = Field(default=None, description="Source model alias")
|
|
257
|
+
output_path: str | None = Field(default=None, description="Output path alias")
|
|
258
|
+
include_custom_properties: bool = Field(
|
|
259
|
+
default=False, description="Include custom properties alias"
|
|
260
|
+
)
|
|
261
|
+
include_materials: bool = Field(
|
|
262
|
+
default=False, description="Include materials alias"
|
|
263
|
+
)
|
|
264
|
+
include_features: list[str] = Field(
|
|
265
|
+
default_factory=list, description="Include features alias"
|
|
266
|
+
)
|
|
267
|
+
metadata: dict[str, Any] = Field(
|
|
268
|
+
default={}, description="Template metadata and properties"
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
async def register_automation_tools(
|
|
273
|
+
mcp: FastMCP, adapter: SolidWorksAdapter, config: dict[str, Any]
|
|
274
|
+
) -> int:
|
|
275
|
+
"""Register automation tools with FastMCP.
|
|
276
|
+
|
|
277
|
+
Registers comprehensive automation tools for SolidWorks workflow orchestration including
|
|
278
|
+
VBA generation, macro recording, batch processing, and template management.
|
|
279
|
+
|
|
280
|
+
Args:
|
|
281
|
+
mcp (FastMCP): The mcp value.
|
|
282
|
+
adapter (SolidWorksAdapter): Adapter instance used for the operation.
|
|
283
|
+
config (dict[str, Any]): Configuration values for the operation.
|
|
284
|
+
|
|
285
|
+
Returns:
|
|
286
|
+
int: The computed numeric result.
|
|
287
|
+
"""
|
|
288
|
+
mcp = with_tool_boundary(mcp)
|
|
289
|
+
tool_count = 0
|
|
290
|
+
|
|
291
|
+
@mcp.tool()
|
|
292
|
+
async def generate_vba_code(input_data: GenerateVBAInput) -> dict[str, Any]:
|
|
293
|
+
"""Generate VBA code for SolidWorks automation.
|
|
294
|
+
|
|
295
|
+
Analyzes operation description and generates appropriate VBA code with SolidWorks API
|
|
296
|
+
calls, error handling, and documentation.
|
|
297
|
+
|
|
298
|
+
Args:
|
|
299
|
+
input_data (GenerateVBAInput): The input data value.
|
|
300
|
+
|
|
301
|
+
Returns:
|
|
302
|
+
dict[str, Any]: A dictionary containing the resulting values.
|
|
303
|
+
|
|
304
|
+
Example:
|
|
305
|
+
```python
|
|
306
|
+
result = await generate_vba_code({
|
|
307
|
+
"operation_description": "Create rectangular extrusion",
|
|
308
|
+
"target_document": "Part",
|
|
309
|
+
"include_error_handling": True
|
|
310
|
+
})
|
|
311
|
+
```
|
|
312
|
+
"""
|
|
313
|
+
if hasattr(adapter, "generate_vba_code"):
|
|
314
|
+
result = await adapter.generate_vba_code(input_data.model_dump())
|
|
315
|
+
require_success(result, "Failed to generate VBA code")
|
|
316
|
+
return {
|
|
317
|
+
"status": "success",
|
|
318
|
+
"message": f"Generated VBA code for: {input_data.operation_description}",
|
|
319
|
+
"data": result.data,
|
|
320
|
+
"execution_time": result.execution_time,
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
# Build a VBA code skeleton from the operation description. This
|
|
324
|
+
# is real, usable output (a labelled template), not a stand-in
|
|
325
|
+
# for a SolidWorks operation that was supposed to run.
|
|
326
|
+
sample_vba = f"""
|
|
327
|
+
' Generated VBA code for: {input_data.operation_description}
|
|
328
|
+
' Target: {input_data.target_document}
|
|
329
|
+
' Generated by: SolidWorks MCP Server
|
|
330
|
+
|
|
331
|
+
Option Explicit
|
|
332
|
+
|
|
333
|
+
Sub {(input_data.operation_description or "").replace(" ", "_")}()
|
|
334
|
+
Dim swApp As SldWorks.SldWorks
|
|
335
|
+
Dim swModel As SldWorks.ModelDoc2
|
|
336
|
+
|
|
337
|
+
{("On Error GoTo ErrorHandler" if input_data.include_error_handling else "")}
|
|
338
|
+
|
|
339
|
+
' Connect to SolidWorks
|
|
340
|
+
Set swApp = Application.SldWorks
|
|
341
|
+
Set swModel = swApp.ActiveDoc
|
|
342
|
+
|
|
343
|
+
If swModel Is Nothing Then
|
|
344
|
+
MsgBox "No active document found"
|
|
345
|
+
Exit Sub
|
|
346
|
+
End If
|
|
347
|
+
|
|
348
|
+
' Main operation code would go here
|
|
349
|
+
' TODO: Implement specific operation
|
|
350
|
+
|
|
351
|
+
MsgBox "Operation completed successfully"
|
|
352
|
+
Exit Sub
|
|
353
|
+
|
|
354
|
+
{("ErrorHandler:" if input_data.include_error_handling else "")}
|
|
355
|
+
{(' MsgBox "Error: " & Err.Description' if input_data.include_error_handling else "")}
|
|
356
|
+
{(" Resume Next" if input_data.include_error_handling else "")}
|
|
357
|
+
|
|
358
|
+
End Sub
|
|
359
|
+
"""
|
|
360
|
+
|
|
361
|
+
return {
|
|
362
|
+
"status": "success",
|
|
363
|
+
"message": f"Generated VBA code for: {input_data.operation_description}",
|
|
364
|
+
"vba_code": {
|
|
365
|
+
"code": sample_vba.strip(),
|
|
366
|
+
"operation": input_data.operation_description,
|
|
367
|
+
"target_document": input_data.target_document,
|
|
368
|
+
"style": input_data.code_style,
|
|
369
|
+
"lines_of_code": len(sample_vba.strip().split("\n")),
|
|
370
|
+
"includes_error_handling": input_data.include_error_handling,
|
|
371
|
+
},
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
@mcp.tool(name="automation_start_macro_recording")
|
|
375
|
+
async def start_macro_recording(input_data: RecordMacroInput) -> dict[str, Any]:
|
|
376
|
+
"""Start recording a macro in SolidWorks.
|
|
377
|
+
|
|
378
|
+
Begins macro recording to capture user actions and generate reusable automation scripts.
|
|
379
|
+
|
|
380
|
+
Args:
|
|
381
|
+
input_data (RecordMacroInput): The input data value.
|
|
382
|
+
|
|
383
|
+
Returns:
|
|
384
|
+
dict[str, Any]: A dictionary containing the resulting values.
|
|
385
|
+
"""
|
|
386
|
+
require_capability(
|
|
387
|
+
adapter,
|
|
388
|
+
"start_macro_recording",
|
|
389
|
+
"Active adapter does not support start_macro_recording; "
|
|
390
|
+
f"no recording of {input_data.macro_name} was started.",
|
|
391
|
+
)
|
|
392
|
+
result = await adapter.start_macro_recording(input_data.model_dump())
|
|
393
|
+
require_success(result, "Failed to start macro recording")
|
|
394
|
+
return {
|
|
395
|
+
"status": "success",
|
|
396
|
+
"message": f"Started recording macro: {input_data.macro_name}",
|
|
397
|
+
"data": result.data,
|
|
398
|
+
"execution_time": result.execution_time,
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
@mcp.tool(name="automation_stop_macro_recording")
|
|
402
|
+
async def stop_macro_recording(input_data: dict[str, Any]) -> dict[str, Any]:
|
|
403
|
+
"""Stop recording the current macro.
|
|
404
|
+
|
|
405
|
+
This tool stops the active macro recording and saves the recorded actions as a VBA
|
|
406
|
+
macro.
|
|
407
|
+
|
|
408
|
+
Args:
|
|
409
|
+
input_data (dict[str, Any]): The input data value.
|
|
410
|
+
|
|
411
|
+
Returns:
|
|
412
|
+
dict[str, Any]: A dictionary containing the resulting values.
|
|
413
|
+
"""
|
|
414
|
+
raise UnsupportedOperationError(
|
|
415
|
+
"No adapter capability exists for stopping a macro "
|
|
416
|
+
"recording; this tool never started a real recording "
|
|
417
|
+
"session, so there is nothing to stop or save."
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
@mcp.tool()
|
|
421
|
+
async def batch_process_files(input_data: BatchProcessInput) -> dict[str, Any]:
|
|
422
|
+
"""Handle batch process files.
|
|
423
|
+
|
|
424
|
+
This tool processes multiple files in a directory, performing operations like rebuild,
|
|
425
|
+
save as, export, or property updates.
|
|
426
|
+
|
|
427
|
+
Args:
|
|
428
|
+
input_data (BatchProcessInput): The input data value.
|
|
429
|
+
|
|
430
|
+
Returns:
|
|
431
|
+
dict[str, Any]: A dictionary containing the resulting values.
|
|
432
|
+
"""
|
|
433
|
+
require_capability(
|
|
434
|
+
adapter,
|
|
435
|
+
"batch_process_files",
|
|
436
|
+
"Active adapter does not support batch_process_files; no "
|
|
437
|
+
f"files in {input_data.source_directory} were processed.",
|
|
438
|
+
)
|
|
439
|
+
result = await adapter.batch_process_files(input_data.model_dump())
|
|
440
|
+
require_success(result, "Batch processing failed")
|
|
441
|
+
return {
|
|
442
|
+
"status": "success",
|
|
443
|
+
"message": f"Batch {input_data.operation_type} completed",
|
|
444
|
+
"data": result.data,
|
|
445
|
+
"execution_time": result.execution_time,
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
@mcp.tool()
|
|
449
|
+
async def manage_design_table(input_data: DesignTableInput) -> dict[str, Any]:
|
|
450
|
+
"""Create or manage design tables for parametric modeling.
|
|
451
|
+
|
|
452
|
+
Design tables allow you to create multiple configurations of a part or assembly by
|
|
453
|
+
driving parameters from an Excel spreadsheet.
|
|
454
|
+
|
|
455
|
+
Args:
|
|
456
|
+
input_data (DesignTableInput): The input data value.
|
|
457
|
+
|
|
458
|
+
Returns:
|
|
459
|
+
dict[str, Any]: A dictionary containing the resulting values.
|
|
460
|
+
"""
|
|
461
|
+
require_capability(
|
|
462
|
+
adapter,
|
|
463
|
+
"manage_design_table",
|
|
464
|
+
"Active adapter does not support manage_design_table; no "
|
|
465
|
+
f"{input_data.table_type} operation was performed.",
|
|
466
|
+
)
|
|
467
|
+
result = await adapter.manage_design_table(input_data.model_dump())
|
|
468
|
+
require_success(result, "Design table management failed")
|
|
469
|
+
return {
|
|
470
|
+
"status": "success",
|
|
471
|
+
"message": f"Design table {input_data.table_type} completed",
|
|
472
|
+
"data": result.data,
|
|
473
|
+
"execution_time": result.execution_time,
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
@mcp.tool()
|
|
477
|
+
async def execute_workflow(input_data: WorkflowInput) -> dict[str, Any]:
|
|
478
|
+
"""Handle execute workflow.
|
|
479
|
+
|
|
480
|
+
This tool executes a series of automated steps in sequence, with support for parallel
|
|
481
|
+
execution and error handling.
|
|
482
|
+
|
|
483
|
+
Args:
|
|
484
|
+
input_data (WorkflowInput): The input data value.
|
|
485
|
+
|
|
486
|
+
Returns:
|
|
487
|
+
dict[str, Any]: A dictionary containing the resulting values.
|
|
488
|
+
"""
|
|
489
|
+
require_capability(
|
|
490
|
+
adapter,
|
|
491
|
+
"execute_workflow",
|
|
492
|
+
"Active adapter does not support execute_workflow; "
|
|
493
|
+
f"workflow '{input_data.workflow_name}' was not run.",
|
|
494
|
+
)
|
|
495
|
+
result = await adapter.execute_workflow(input_data.model_dump())
|
|
496
|
+
require_success(result, "Workflow execution failed")
|
|
497
|
+
return {
|
|
498
|
+
"status": "success",
|
|
499
|
+
"message": f"Workflow '{input_data.workflow_name}' completed",
|
|
500
|
+
"data": result.data,
|
|
501
|
+
"execution_time": result.execution_time,
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
@mcp.tool()
|
|
505
|
+
async def create_template(input_data: TemplateInput) -> dict[str, Any]:
|
|
506
|
+
"""Create a SolidWorks template file.
|
|
507
|
+
|
|
508
|
+
This tool creates templates for parts, assemblies, or drawings with standardized
|
|
509
|
+
settings, materials, and configurations.
|
|
510
|
+
|
|
511
|
+
Args:
|
|
512
|
+
input_data (TemplateInput): The input data value.
|
|
513
|
+
|
|
514
|
+
Returns:
|
|
515
|
+
dict[str, Any]: A dictionary containing the resulting values.
|
|
516
|
+
"""
|
|
517
|
+
require_capability(
|
|
518
|
+
adapter,
|
|
519
|
+
"create_template",
|
|
520
|
+
"Active adapter does not support create_template; no "
|
|
521
|
+
f"{input_data.template_type} template "
|
|
522
|
+
f"'{input_data.template_name}' was created.",
|
|
523
|
+
)
|
|
524
|
+
result = await adapter.create_template(input_data.model_dump())
|
|
525
|
+
require_success(result, "Template creation failed")
|
|
526
|
+
return {
|
|
527
|
+
"status": "success",
|
|
528
|
+
"message": f"Created {input_data.template_type} template: {input_data.template_name}",
|
|
529
|
+
"data": result.data,
|
|
530
|
+
"execution_time": result.execution_time,
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
@mcp.tool()
|
|
534
|
+
async def optimize_performance(input_data: dict[str, Any]) -> dict[str, Any]:
|
|
535
|
+
"""Optimize SolidWorks performance settings.
|
|
536
|
+
|
|
537
|
+
This tool analyzes the current SolidWorks configuration and suggests or applies
|
|
538
|
+
performance optimizations.
|
|
539
|
+
|
|
540
|
+
Args:
|
|
541
|
+
input_data (dict[str, Any]): The input data value.
|
|
542
|
+
|
|
543
|
+
Returns:
|
|
544
|
+
dict[str, Any]: A dictionary containing the resulting values.
|
|
545
|
+
"""
|
|
546
|
+
require_capability(
|
|
547
|
+
adapter,
|
|
548
|
+
"optimize_performance",
|
|
549
|
+
"Active adapter does not support optimize_performance; "
|
|
550
|
+
"no settings were analyzed or changed.",
|
|
551
|
+
)
|
|
552
|
+
result = await adapter.optimize_performance(input_data)
|
|
553
|
+
require_success(result, "Performance optimization failed")
|
|
554
|
+
return {
|
|
555
|
+
"status": "success",
|
|
556
|
+
"message": "Performance optimization completed",
|
|
557
|
+
"data": result.data,
|
|
558
|
+
"execution_time": result.execution_time,
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
tool_count = 8 # Number of tools registered
|
|
562
|
+
return tool_count
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
class PerformanceOptimizationInput(CompatInput):
|
|
566
|
+
"""Input schema for performance optimization.
|
|
567
|
+
|
|
568
|
+
Attributes:
|
|
569
|
+
optimization_type (str): The optimization type value.
|
|
570
|
+
parameters (dict[str, Any]): The parameters value.
|
|
571
|
+
target_metric (str): The target metric value.
|
|
572
|
+
"""
|
|
573
|
+
|
|
574
|
+
optimization_type: str = Field(description="Type of optimization to perform")
|
|
575
|
+
target_metric: str = Field(default="speed", description="Target performance metric")
|
|
576
|
+
parameters: dict[str, Any] = Field(
|
|
577
|
+
default={}, description="Optimization parameters"
|
|
578
|
+
)
|