solidworks_mcp.adapters.pywin32_adapter¶
solidworks_mcp.adapters.pywin32_adapter ¶
PyWin32 SolidWorks adapter for Windows COM integration.
This adapter uses pywin32 to communicate with SolidWorks via COM, providing real SolidWorks automation capabilities on Windows platforms.
Attributes¶
_WALK_MEMBERS
module-attribute
¶
Classes¶
AdapterHealth ¶
Bases: BaseModel
Health status information for adapters.
Attributes:
| Name | Type | Description |
|---|---|---|
average_response_time |
float
|
The average response time value. |
connection_status |
str
|
The connection status value. |
error_count |
int
|
The error count value. |
healthy |
bool
|
The healthy value. |
last_check |
datetime
|
The last check value. |
metrics |
dict[str, Any] | None
|
The metrics value. |
success_count |
int
|
The success count value. |
Methods:¶
__contains__ ¶
Build internal contains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if contains, otherwise False. |
Source code in src/solidworks_mcp/adapters/base.py
__getitem__ ¶
Build internal getitem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
AdapterResult
dataclass
¶
AdapterResult(status: AdapterResultStatus, data: T | None = None, error: str | None = None, execution_time: float | None = None, metadata: dict[str, Any] | None = None)
Bases: Generic[T]
Result wrapper for adapter operations.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
T | None
|
The data value. |
error |
str | None
|
The error value. |
execution_time |
float | None
|
The execution time value. |
metadata |
dict[str, Any] | None
|
The metadata value. |
status |
AdapterResultStatus
|
The status value. |
AdapterResultStatus ¶
Bases: StrEnum
Result status for adapter operations.
Attributes:
| Name | Type | Description |
|---|---|---|
ERROR |
Any
|
The error value. |
SUCCESS |
Any
|
The success value. |
TIMEOUT |
Any
|
The timeout value. |
WARNING |
Any
|
The warning value. |
PyWin32Adapter ¶
Bases: SolidWorksSketchMixin, SolidWorksFeaturesMixin, SolidWorksIOMixin, SolidWorksSelectionMixin, SolidWorksAdapter
SolidWorks adapter using pywin32 COM integration.
This adapter provides direct COM integration with SolidWorks using pywin32, enabling real-time automation and control of SolidWorks applications on Windows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any] | None
|
Configuration values for the operation. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
SolidWorksMCPError
|
PyWin32Adapter requires Windows platform. |
Attributes:
| Name | Type | Description |
|---|---|---|
constants |
Any
|
The constants value. |
Example
Initialize PyWin32Adapter with configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any] | None
|
Configuration values for the operation. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Raises:
| Type | Description |
|---|---|
SolidWorksMCPError
|
PyWin32Adapter requires Windows platform. |
Example
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 | |
Methods:¶
connect
async
¶
Connect to SolidWorks COM and prepare automation-safe session state.
Raises:
| Type | Description |
|---|---|
SolidWorksMCPError
|
If connection or readiness checks fail. |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
disconnect
async
¶
Disconnect from SolidWorks application.
Properly disconnects from SolidWorks COM interface and cleans up resources. This method should always be called when finished to prevent memory leaks.
Note: - Clears references to current model and application - Uninitialize COM apartment - Does not close SolidWorks application itself
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
execute_macro
async
¶
Provide execute macro support for the py win32 adapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict[str, Any]
|
The params value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The result produced by the operation. |
Raises:
| Type | Description |
|---|---|
SolidWorksMCPError
|
If the operation cannot be completed. |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
export_file
async
¶
Export the current model to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the target file. |
required |
format_type
|
str
|
The format type value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[None]
|
AdapterResult[None]: The result produced by the operation. |
Raises:
| Type | Description |
|---|---|
Exception
|
If the operation cannot be completed. |
RuntimeError
|
No active SolidWorks document for export. |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 | |
export_image
async
¶
Export a screenshot of the current model to a PNG/JPG file.
Payload keys (matching ExportImageInput): file_path (str): Output path including extension. format_type (str): "png" or "jpg". Default "png". width (int): Pixel width. Default 1280. height (int): Pixel height. Default 720. view_orientation (str): "front" | "top" | "right" | "isometric" | "current".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict
|
The payload value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict]
|
AdapterResult[dict]: The result produced by the operation. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the operation cannot be completed. |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 | |
health_check
async
¶
Get adapter health status.
Performs comprehensive health check including connection status, operation metrics, and SolidWorks application responsiveness.
Returns:
| Name | Type | Description |
|---|---|---|
AdapterHealth |
AdapterHealth
|
The result produced by the operation. |
Example
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
is_connected ¶
Check if connected to SolidWorks.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if connected, otherwise False. |
Example
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
SolidWorksAdapter ¶
Bases: ABC
Base adapter interface for SolidWorks integration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
object | None
|
Configuration values for the operation. Defaults to None. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
_metrics |
Any
|
The metrics value. |
config |
Any
|
The config value. |
config_dict |
Any
|
The config dict value. |
Initialize adapter with configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
object | None
|
Configuration values for the operation. Defaults to None. |
None
|
Source code in src/solidworks_mcp/adapters/base.py
Methods:¶
add_arc
async
¶
add_arc(center_x: float, center_y: float, start_x: float, start_y: float, end_x: float, end_y: float) -> AdapterResult[str]
Add an arc to the current sketch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center_x
|
float
|
The center x value. |
required |
center_y
|
float
|
The center y value. |
required |
start_x
|
float
|
The start x value. |
required |
start_y
|
float
|
The start y value. |
required |
end_x
|
float
|
The end x value. |
required |
end_y
|
float
|
The end y value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
add_centerline
async
¶
Add a centerline to the current sketch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1
|
float
|
The x1 value. |
required |
y1
|
float
|
The y1 value. |
required |
x2
|
float
|
The x2 value. |
required |
y2
|
float
|
The y2 value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
add_circle
abstractmethod
async
¶
Add a circle to the current sketch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center_x
|
float
|
The center x value. |
required |
center_y
|
float
|
The center y value. |
required |
radius
|
float
|
The radius value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
add_ellipse
async
¶
add_ellipse(center_x: float, center_y: float, major_axis: float, minor_axis: float) -> AdapterResult[str]
Add an ellipse to the current sketch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center_x
|
float
|
The center x value. |
required |
center_y
|
float
|
The center y value. |
required |
major_axis
|
float
|
The major axis value. |
required |
minor_axis
|
float
|
The minor axis value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
add_fillet
async
¶
Add a fillet feature to selected edges.
Rounds the selected edges of the current solid body with the given radius.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Fillet radius in millimeters. |
required |
edge_names
|
list[str]
|
List of edge names to fillet. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AdapterResult |
AdapterResult[Any]
|
Feature result or error. |
Source code in src/solidworks_mcp/adapters/base.py
add_line
abstractmethod
async
¶
Add a line to the current sketch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1
|
float
|
The x1 value. |
required |
y1
|
float
|
The y1 value. |
required |
x2
|
float
|
The x2 value. |
required |
y2
|
float
|
The y2 value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
add_mate
async
¶
add_mate(component_a: str, component_b: str, entity_a: str = 'Front Plane', entity_b: str = 'Front Plane', mate_type: str = 'coincident', alignment: str = 'aligned', distance: float = 0.0, angle: float = 0.0) -> AdapterResult[dict[str, Any]]
Mate two components together in the active assembly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component_a
|
str
|
First component instance name. |
required |
component_b
|
str
|
Second component instance name. |
required |
entity_a
|
str
|
Named feature on the first component. Defaults to "Front Plane". |
'Front Plane'
|
entity_b
|
str
|
Named feature on the second component. Defaults to "Front Plane". |
'Front Plane'
|
mate_type
|
str
|
Mate type, e.g. |
'coincident'
|
alignment
|
str
|
|
'aligned'
|
distance
|
float
|
Distance in millimetres, for a distance mate. Defaults to 0.0. |
0.0
|
angle
|
float
|
Angle in degrees, for an angle mate. Defaults to 0.0. |
0.0
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Mate details, or error. |
Source code in src/solidworks_mcp/adapters/base.py
add_polygon
async
¶
Add a regular polygon to the current sketch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center_x
|
float
|
The center x value. |
required |
center_y
|
float
|
The center y value. |
required |
radius
|
float
|
The radius value. |
required |
sides
|
int
|
The sides value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
add_rectangle
abstractmethod
async
¶
Add a rectangle to the current sketch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1
|
float
|
The x1 value. |
required |
y1
|
float
|
The y1 value. |
required |
x2
|
float
|
The x2 value. |
required |
y2
|
float
|
The y2 value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
add_sketch_circle
async
¶
add_sketch_circle(center_x: float, center_y: float, radius: float, construction: bool = False) -> AdapterResult[str]
Alias for add_circle used by some tool flows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center_x
|
float
|
The center x value. |
required |
center_y
|
float
|
The center y value. |
required |
radius
|
float
|
The radius value. |
required |
construction
|
bool
|
The construction value. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
add_sketch_constraint
async
¶
add_sketch_constraint(entity1: str, entity2: str | None, relation_type: str, entity3: str | None = None) -> AdapterResult[str]
Apply a geometric constraint between sketch entities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity1
|
str
|
The entity1 value. |
required |
entity2
|
str | None
|
The entity2 value. |
required |
relation_type
|
str
|
The relation type value. |
required |
entity3
|
str | None
|
Third entity ID — only used by the
|
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
add_sketch_dimension
async
¶
add_sketch_dimension(entity1: str, entity2: str | None, dimension_type: str, value: float) -> AdapterResult[str]
Add a sketch dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity1
|
str
|
The entity1 value. |
required |
entity2
|
str | None
|
The entity2 value. |
required |
dimension_type
|
str
|
The dimension type value. |
required |
value
|
float
|
The value value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
add_spline
async
¶
Add a spline through the provided points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
list[dict[str, float]]
|
The points value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
check_sketch_fully_defined
async
¶
Check whether a sketch is fully defined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sketch_name
|
str | None
|
Optional sketch name to inspect. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Definition status payload. |
Source code in src/solidworks_mcp/adapters/base.py
close_model
abstractmethod
async
¶
Close the current model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save
|
bool
|
The save value. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
AdapterResult[None]
|
AdapterResult[None]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
connect
abstractmethod
async
¶
create_assembly
abstractmethod
async
¶
Create a new assembly document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The name value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksModel]
|
AdapterResult[SolidWorksModel]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
create_cut
async
¶
Create a cut feature from an existing sketch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sketch_name
|
str
|
The sketch name value. |
required |
depth
|
float
|
The depth value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
create_cut_extrude
async
¶
Create a cut-extrude feature from the active sketch.
Cuts material from the current solid body using the active sketch profile. Equivalent to SolidWorks Insert > Cut > Extrude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
ExtrusionParameters
|
Depth and direction parameters. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AdapterResult |
AdapterResult[Any]
|
Feature result or error. |
Source code in src/solidworks_mcp/adapters/base.py
create_drawing
abstractmethod
async
¶
Create a new drawing document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The name value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksModel]
|
AdapterResult[SolidWorksModel]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
create_extrusion
abstractmethod
async
¶
Create an extrusion feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
ExtrusionParameters
|
The params value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksFeature]
|
AdapterResult[SolidWorksFeature]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
create_loft
abstractmethod
async
¶
Create a loft feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
LoftParameters
|
The params value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksFeature]
|
AdapterResult[SolidWorksFeature]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
create_part
abstractmethod
async
¶
Create a new part document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The name value. Defaults to None. |
None
|
units
|
str | None
|
The units value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksModel]
|
AdapterResult[SolidWorksModel]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
create_revolve
abstractmethod
async
¶
Create a revolve feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
RevolveParameters
|
The params value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksFeature]
|
AdapterResult[SolidWorksFeature]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
create_sketch
abstractmethod
async
¶
Create a new sketch on the specified plane.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plane
|
str
|
The plane value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
create_sweep
abstractmethod
async
¶
Create a sweep feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
SweepParameters
|
The params value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksFeature]
|
AdapterResult[SolidWorksFeature]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
disconnect
abstractmethod
async
¶
exit_sketch
abstractmethod
async
¶
Exit sketch editing mode.
Returns:
| Type | Description |
|---|---|
AdapterResult[None]
|
AdapterResult[None]: The result produced by the operation. |
export_file
abstractmethod
async
¶
Export the current model to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the target file. |
required |
format_type
|
str
|
The format type value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[None]
|
AdapterResult[None]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
export_image
abstractmethod
async
¶
Export a viewport screenshot (PNG/JPG) of the current model.
Payload keys: file_path (str): Absolute output path. width (int): Image width in pixels. height (int): Image height in pixels. view_orientation (str): One of "isometric", "front", "top", "right", "back", "bottom", "current".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict
|
The payload value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict]
|
AdapterResult[dict]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
get_dimension
abstractmethod
async
¶
Get the value of a dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[float]
|
AdapterResult[float]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
get_mass_properties
abstractmethod
async
¶
Get mass properties of the current model.
Returns:
| Type | Description |
|---|---|
AdapterResult[MassProperties]
|
AdapterResult[MassProperties]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
get_metrics ¶
Get adapter metrics.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing the resulting values. |
get_model_info
abstractmethod
async
¶
Get metadata for the active model.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The result produced by the operation. |
health_check
abstractmethod
async
¶
Get adapter health status.
Returns:
| Name | Type | Description |
|---|---|---|
AdapterHealth |
AdapterHealth
|
The result produced by the operation. |
insert_component
async
¶
insert_component(file_path: str, x: float = 0.0, y: float = 0.0, z: float = 0.0) -> AdapterResult[dict[str, Any]]
Insert a part or sub-assembly into the active assembly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Absolute path to the |
required |
x
|
float
|
X position in millimetres. Defaults to 0.0. |
0.0
|
y
|
float
|
Y position in millimetres. Defaults to 0.0. |
0.0
|
z
|
float
|
Z position in millimetres. Defaults to 0.0. |
0.0
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Component name and counts, or error. |
Source code in src/solidworks_mcp/adapters/base.py
is_connected
abstractmethod
¶
Check if connected to SolidWorks.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if connected, otherwise False. |
list_components
async
¶
List the top-level components of the active assembly.
Returns:
| Type | Description |
|---|---|
AdapterResult[list[str]]
|
AdapterResult[list[str]]: Component instance names, or error. |
Source code in src/solidworks_mcp/adapters/base.py
list_configurations
abstractmethod
async
¶
List configuration names for the active model.
Returns:
| Type | Description |
|---|---|
AdapterResult[list[str]]
|
AdapterResult[list[str]]: The result produced by the operation. |
list_features
abstractmethod
async
¶
list_features(include_suppressed: bool = False, max_assembly_depth: int = 2) -> AdapterResult[list[dict[str, Any]]]
List model features from the feature tree.
For a Part document, returns that document's own feature list,
unchanged from prior behavior. For an Assembly document, returns a
single flat list containing the assembly's own top-level features
plus every resolved component's features, recursing into
sub-assemblies up to max_assembly_depth. Every descriptor gains
component, component_path, and component_parent keys:
None for a document's own features (Part features, or an Assembly's
top-level features), or the owning component's name/path for a
component-derived feature. component_parent is the immediate parent
component name when the component is nested inside a sub-assembly,
otherwise None. A component that cannot be resolved (suppressed,
lightweight-and-unloaded, missing file) is represented by one descriptor
with type: "UnresolvedComponent" instead of being silently dropped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_suppressed
|
bool
|
The include suppressed value. Defaults to False. Applied independently to the assembly's own features and to each component's features. |
False
|
max_assembly_depth
|
int
|
How many levels of sub-assembly to recurse into. Defaults to 2. Ignored for Part documents. A component beyond the configured depth still appears in the result as a single descriptor (name + path), not expanded. |
2
|
Returns:
| Type | Description |
|---|---|
AdapterResult[list[dict[str, Any]]]
|
AdapterResult[list[dict[str, Any]]]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
open_model
abstractmethod
async
¶
Open a SolidWorks model (part, assembly, or drawing).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the target file. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksModel]
|
AdapterResult[SolidWorksModel]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
save_file
async
¶
Save the active model to the existing path or the provided path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str | None
|
Path to the target file. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[Any]
|
AdapterResult[Any]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
set_dimension
abstractmethod
async
¶
Set the value of a dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name value. |
required |
value
|
float
|
The value value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[None]
|
AdapterResult[None]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
sketch_circular_pattern
async
¶
Create a circular pattern of sketch entities around the sketch origin.
The rotation axis is always the sketch origin — SW's
CreateCircularSketchStepAndRepeat has no pattern-centre
parameter and derives the axis from the seed's geometry. Place
the seed entity at the desired radius from the origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
list[str]
|
The entities value. |
required |
angle
|
float
|
The angle value. |
required |
count
|
int
|
The count value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
sketch_linear_pattern
async
¶
sketch_linear_pattern(entities: list[str], direction_x: float, direction_y: float, spacing: float, count: int) -> AdapterResult[str]
Create a linear pattern of sketch entities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
list[str]
|
The entities value. |
required |
direction_x
|
float
|
The direction x value. |
required |
direction_y
|
float
|
The direction y value. |
required |
spacing
|
float
|
The spacing value. |
required |
count
|
int
|
The count value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
sketch_mirror
async
¶
Mirror sketch entities about a mirror line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
list[str]
|
The entities value. |
required |
mirror_line
|
str
|
The mirror line value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
sketch_offset
async
¶
sketch_offset(entities: list[str], offset_distance: float, reverse_direction: bool) -> AdapterResult[str]
Offset sketch entities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
list[str]
|
The entities value. |
required |
offset_distance
|
float
|
The offset distance value. |
required |
reverse_direction
|
bool
|
The reverse direction value. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[str]
|
AdapterResult[str]: The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/base.py
update_metrics ¶
Update adapter metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operation_time
|
float
|
The operation time value. |
required |
success
|
bool
|
The success value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/adapters/base.py
SolidWorksFeaturesMixin ¶
Expose SolidWorks feature methods via mixin-local implementation helpers.
SolidWorksIOMixin ¶
Expose model open/save/create/configuration methods through a mixin.
Methods:¶
add_mate
async
¶
add_mate(component_a: str, component_b: str, entity_a: str = 'Front Plane', entity_b: str = 'Front Plane', mate_type: str = 'coincident', alignment: str = 'aligned', distance: float = 0.0, angle: float = 0.0) -> AdapterResult[dict[str, Any]]
Mate two components together.
Wraps IAssemblyDoc::AddMate5. The two entities are selected via
IComponent2::FeatureByName + IFeature::Select2 rather than
SelectByID2, which raises Type mismatch on this build.
That restricts the entities to named tree features — the reference planes and axes of each component. Plane-to-plane mating covers alignment and stacking, which is the common case; mating to a specific face or edge needs entity names this adapter cannot enumerate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component_a
|
str
|
First component instance name, as reported by
:meth: |
required |
component_b
|
str
|
Second component instance name. |
required |
entity_a
|
str
|
Named feature on the first component. |
'Front Plane'
|
entity_b
|
str
|
Named feature on the second component. |
'Front Plane'
|
mate_type
|
str
|
|
'coincident'
|
alignment
|
str
|
|
'aligned'
|
distance
|
float
|
Distance in millimetres, for a distance mate. |
0.0
|
angle
|
float
|
Angle in degrees, for an angle mate. |
0.0
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The mate created, plus the bounding |
AdapterResult[dict[str, Any]]
|
box before and after so the caller can see what moved. |
AdapterResult[dict[str, Any]]
|
when the entities cannot be selected or SolidWorks rejects the |
AdapterResult[dict[str, Any]]
|
mate. |
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Example::
await adapter.add_mate("plate-1", "plate-2")
Source code in src/solidworks_mcp/adapters/solidworks/io.py
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 | |
close_model
async
¶
Close the current SolidWorks model and optionally save first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
AdapterResult[None]
|
AdapterResult[None]: Result of the close operation. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
create_assembly
async
¶
Create a new assembly document and set it as active.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Reserved for future naming policy. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksModel]
|
AdapterResult[SolidWorksModel]: Metadata for the new assembly document. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
create_drawing
async
¶
Create a new drawing document and set it as active.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Reserved for future naming policy. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksModel]
|
AdapterResult[SolidWorksModel]: Metadata for the new drawing document. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
create_part
async
¶
Create a new part document and set it as active.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Reserved for future naming policy. |
None
|
units
|
str | None
|
Reserved for future units policy. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksModel]
|
AdapterResult[SolidWorksModel]: Metadata for the new part document. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
get_dimension
async
¶
Read a named model dimension in millimetres.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Fully-qualified dimension name. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[float]
|
AdapterResult[float]: Dimension value in millimetres. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
get_mass_properties
async
¶
Get mass properties for the active model.
Returns:
| Type | Description |
|---|---|
AdapterResult[MassProperties]
|
AdapterResult[MassProperties]: Computed mass, volume, area, COM, and inertia. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 | |
get_model_info
async
¶
Collect summary metadata about the active model.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Model information payload. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
insert_component
async
¶
insert_component(file_path: str, x: float = 0.0, y: float = 0.0, z: float = 0.0) -> AdapterResult[dict[str, Any]]
Insert a part or sub-assembly into the active assembly.
Wraps IAssemblyDoc::AddComponent4(CompName, ConfigName, X, Y, Z),
falling back to AddComponent5. Position is in millimetres.
The component file must contain solid geometry. SolidWorks
silently refuses to insert an empty part — every overload returns
None and the component count stays put. That behaviour is what
made this look unimplementable until the save_file bug that was
writing empty parts got fixed.
Success is confirmed by the assembly's component count going up, since
AddComponent* gives no usable failure signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Absolute path to the |
required |
x
|
float
|
X position in millimetres. |
0.0
|
y
|
float
|
Y position in millimetres. |
0.0
|
z
|
float
|
Z position in millimetres. |
0.0
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Component name and before/after |
AdapterResult[dict[str, Any]]
|
counts. |
AdapterResult[dict[str, Any]]
|
file is missing, or nothing was inserted. |
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Example::
await adapter.insert_component(r"C:\parts\bracket.sldprt", 0, 0, 0)
Source code in src/solidworks_mcp/adapters/solidworks/io.py
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 | |
list_components
async
¶
List the top-level components of the active assembly.
Returns:
| Type | Description |
|---|---|
AdapterResult[list[str]]
|
AdapterResult[list[str]]: Component names, or an error when the |
AdapterResult[list[str]]
|
active document is not an assembly. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
list_configurations
async
¶
List all configuration names on the active model.
Returns:
| Type | Description |
|---|---|
AdapterResult[list[str]]
|
AdapterResult[list[str]]: Configuration names, or empty list when unavailable. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
open_model
async
¶
Open a SolidWorks model file and set it as active on the adapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to a |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksModel]
|
AdapterResult[SolidWorksModel]: Model metadata for the opened document. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
pack_and_go_assembly
async
¶
Copy an assembly and all its referenced components to a self-contained folder.
Uses IModelDocExtension.GetPackAndGo() → IPackAndGo via the
comtypes vtable interface (bypassing the broken IDispatch path present
in SolidWorks 2026's late-binding layer), then calls
IModelDocExtension.SavePackAndGo() to execute the copy. All file
paths inside the copied assembly are automatically updated by
SolidWorks — this is the native Pack-and-Go mechanism.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_path
|
str
|
Absolute path to the source |
required |
target_dir
|
str
|
Directory where the assembly and parts will be copied. Created if it does not exist. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict]: On success, |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
|
Source code in src/solidworks_mcp/adapters/solidworks/io.py
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 | |
rebuild_model
async
¶
Force a model rebuild.
Returns:
| Type | Description |
|---|---|
AdapterResult[None]
|
AdapterResult[None]: Result of the rebuild operation. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
save_file
async
¶
Save the active model to its current path or to a new file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str | None
|
Optional target path for Save As. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[None]
|
AdapterResult[None]: Result of the save operation. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 | |
set_dimension
async
¶
Set a named model dimension in millimetres and rebuild.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Fully-qualified dimension name. |
required |
value
|
float
|
New value in millimetres. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[None]
|
AdapterResult[None]: Result of the set operation. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
SolidWorksMCPError ¶
Bases: Exception
Base exception for SolidWorks MCP Server errors.
SolidWorksSelectionMixin ¶
Expose feature-selection and feature-list methods through a mixin.
SolidWorksSketchMixin ¶
Expose sketch creation and editing methods via mixin-local implementation.
_ComSessionCoordinator ¶
Coordinate COM apartment initialisation and SolidWorks application lifecycle.
This collaborator is responsible for the low-level mechanics of connecting
to the SolidWorks COM server: initialising the COM apartment, acquiring the
SldWorks.Application object (with retries), waiting for the server to
become ready, toggling automation preferences, and tearing everything down
cleanly on disconnect.
It is instantiated once inside PyWin32Adapter.__init__ and accessed
via self._com_coordinator.
Attributes:
| Name | Type | Description |
|---|---|---|
_adapter |
Back-reference to the owning |
Store a back-reference to the owning adapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
PyWin32Adapter
|
The |
required |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
Methods:¶
acquire_solidworks_application
async
¶
Acquire a live SolidWorks COM application object with retries.
Attempts up to 8 connect-cycles. Each cycle first tries
win32com.client.GetActiveObject("SldWorks.Application") to bind to
a running instance, then falls back to
win32com.client.Dispatch("SldWorks.Application") to start one.
Between cycles the coroutine sleeps 1 second so that a slow
SolidWorks launch has time to register its COM class.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The live |
Raises:
| Type | Description |
|---|---|
SolidWorksMCPError
|
After all retries are exhausted, wraps the
last |
Side Effects
Sets adapter.swApp to the acquired COM object.
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
connect
async
¶
Orchestrate the full SolidWorks connection sequence.
Performs in order:
- Initialise the COM apartment.
- Acquire the
SldWorks.ApplicationCOM object (with retries). - Wait for the server to become ready.
- Make the application window visible.
- Suppress interactive dialogs for automation.
On any failure the adapter state is cleaned up (swApp set to
None, COM apartment uninitialised) before re-raising.
Raises:
| Type | Description |
|---|---|
SolidWorksMCPError
|
Wraps any underlying COM or timeout error. |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
disconnect
async
¶
Clear session state and release the COM apartment.
Resets all adapter model/sketch references to None and always
uninitialises the COM apartment via finally so the apartment is
freed even if the SolidWorks process is already unstable.
Disconnect deliberately avoids additional UI preference COM calls. Real SolidWorks sessions can hit RPC teardown failures when toggles are restored during shutdown, so automation-safe preferences are applied on connect and left untouched during disconnect.
Side Effects
Sets adapter.currentModel, adapter.currentSketch,
adapter.currentSketchManager, and adapter.swApp to
None. Clears the sketch entity registry. Calls
CoUninitialize.
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
initialize_com_apartment ¶
Initialise the COM apartment via pythoncom.CoInitialize.
Safe to call multiple times; subsequent calls are no-ops if the
apartment is already initialised (tracked via
adapter._com_initialized).
Side Effects
Sets adapter._com_initialized to True on first call.
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
set_automation_preferences
staticmethod
¶
Toggle the SolidWorks warning and question dialog preferences.
Sets user preference toggles 150 and 149 to suppress (or restore) popup dialogs during automated workflows. Also manages the sketch-dimension input toggles so sketch dimensions do not require the interactive Modify confirmation while automation is active.
Verified against the SolidWorks 2026 constants type library, the relevant sketch-dimension toggles are:
swInputDimValOnCreate= 10swSketchAcceptNumericInput= 372swSketchCreateDimensionOnlyWhenEntered= 520swScaleSketchOnFirstDimension= 642
These stay disabled for the full automation session instead of being toggled around individual dimension calls, because once SolidWorks enters the modal approval flow, extra COM cleanup chatter tends to make recovery less reliable.
Should be called with interactive=False immediately after
connecting and interactive=True before disconnecting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
Any
|
The live |
required |
interactive
|
bool
|
When |
required |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
uninitialize_com_apartment ¶
Release the COM apartment via pythoncom.CoUninitialize.
Only called when this coordinator was the one that initialised the
apartment (adapter._com_initialized is True). Resets the
flag afterwards so reconnect attempts work correctly.
Side Effects
Sets adapter._com_initialized to False.
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
wait_for_server_ready
async
¶
Poll until the SolidWorks COM server is responsive.
Reads app.RevisionNumber up to 10 times with 0.5-second pauses
between attempts. This guards against race conditions when SolidWorks
is still loading after the COM object is first obtained.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
Any
|
The |
required |
Raises:
| Type | Description |
|---|---|
SolidWorksMCPError
|
If the server does not respond within 10 × 0.5 s = 5 seconds. |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
_DocumentRoutingService ¶
Resolve document identity and select the export-target document.
Provides two helpers that isolate the policy for identifying which COM
document object to use during export operations. The service prefers the
SolidWorks ActiveDoc when it matches the adapter's current model, and
falls back gracefully when path or title data is unavailable.
Attributes:
| Name | Type | Description |
|---|---|---|
_adapter |
Back-reference to the owning |
Store a back-reference to the owning adapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
PyWin32Adapter
|
The |
required |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
Methods:¶
document_identity ¶
Return the normalised absolute path and display title for a COM document.
Tries document.GetPathName() first; falls back to
getattr(document, 'GetPathName', None) for COM objects that expose
the path as a property rather than a method. Applies the same
two-step pattern for GetTitle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document
|
Any
|
A SolidWorks |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
tuple[str | None, str | None]: |
str | None
|
|
tuple[str | None, str | None]
|
|
tuple[str | None, str | None]
|
when the corresponding attribute is absent or empty. |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
resolve_export_target_doc ¶
Resolve the safest document to use for export operations.
Policy (in order):
- If
adapter.currentModelisNone, useswApp.ActiveDoc. - If
swApp.ActiveDocisNone, useadapter.currentModel. - If both have path strings and the paths match, prefer
swApp.ActiveDoc(it may have a more up-to-date state). - If both have title strings that match, prefer
swApp.ActiveDoc. - Otherwise fall back to
adapter.currentModel.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The SolidWorks |
Any
|
or |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
_FeatureSelectionService ¶
Encapsulate feature-selection strategies and name-candidate expansion.
SolidWorks allows features to be selected by bare name or by the
<name>@<document> qualified syntax. Several selection APIs also
exist with different levels of support across SolidWorks versions.
This service centralises all of that complexity so the main adapter
methods stay thin.
Attributes:
| Name | Type | Description |
|---|---|---|
_adapter |
Back-reference to the owning |
Store a back-reference to the owning adapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
PyWin32Adapter
|
The |
required |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
Methods:¶
build_feature_candidate_names ¶
Build a list of bare and document-qualified selection candidates.
SolidWorks requires the "<name>@<document>" syntax for
SelectByID2 on assembly contexts. This method tries to read the
document title and produces both bare and qualified variants so that
callers do not need to duplicate that logic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature_name
|
str
|
The bare feature name as supplied by the caller
(e.g. |
required |
target_doc
|
Any
|
SolidWorks |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: Candidate list, always including |
list[str]
|
the first element. Qualified variants are appended when a non- |
list[str]
|
empty title is available. Example:: ["Boss-Extrude1", "Boss-Extrude1@Part1", "Boss-Extrude1@Part1.SLDPRT"] |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
list_features ¶
list_features(include_suppressed: bool = False, max_assembly_depth: int = 2) -> list[dict[str, Any]]
Enumerate model features, including assembly component trees.
For a Part document, returns that document's own feature list only
(unchanged from prior behavior). For an Assembly document, also
flattens in every resolved top-level component's features — and,
recursively, sub-assembly components' features up to
max_assembly_depth — tagged with component/component_path
so callers can tell which document each descriptor came from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_suppressed
|
bool
|
Include suppressed features when |
False
|
max_assembly_depth
|
int
|
Sub-assembly recursion budget. Ignored for Part documents. |
2
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: Ordered, flattened feature descriptors. |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
normalize_feature_name
staticmethod
¶
Normalise a feature name for case-insensitive comparison.
Strips surrounding whitespace and quotes then converts to
casefold-lowercase so that mixed-case names such as
'Boss-Extrude1', " boss-extrude1 " and '"Boss-Extrude1"'
all compare equal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_name
|
str | None
|
Raw feature name string, or |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Normalised name. Empty string when |
str
|
|
Example::
svc.normalize_feature_name('"Boss-Extrude1"') == 'boss-extrude1'
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
select_feature ¶
Run all feature-selection strategies and return best-effort payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature_name
|
str
|
Feature name requested by caller. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Selection result payload. |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
try_select_by_component ¶
try_select_by_component(target_doc: Any, candidate_names: list[str], feature_name: str) -> dict[str, Any] | None
Attempt component selection for assembly-context features.
Calls target_doc.GetComponentByName (when available) and then
tries three selector methods on the resulting component object:
Select4(False, None, False), Select(False,), and
Select2(False, 0).
This path handles assembly components that are not reachable through
SelectByID2 alone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_doc
|
Any
|
SolidWorks |
required |
candidate_names
|
list[str]
|
List of candidate name strings. Only the part
before the first |
required |
feature_name
|
str
|
Original caller-supplied name for the result payload. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
dict[str, Any] | None: Success dict (same schema as |
dict[str, Any] | None
|
meth: |
dict[str, Any] | None
|
or all attempts fail. |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
try_select_by_extension ¶
try_select_by_extension(target_doc: Any, candidate_names: list[str], feature_name: str) -> dict[str, Any] | None
Attempt feature selection via Extension.SelectByID2.
Iterates the Cartesian product of candidate_names × entity-type
strings. Entity types tried (in order): "BODYFEATURE",
"COMPONENT", "SKETCH", "PLANE", "MATE", "" (auto).
Returns on the first successful selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_doc
|
Any
|
SolidWorks |
required |
candidate_names
|
list[str]
|
Ordered list of name strings to try (bare and
qualified variants from :meth: |
required |
feature_name
|
str
|
The original caller-supplied name, included in the result payload for traceability. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
dict[str, Any] | None: On success, a result dict with keys |
dict[str, Any] | None
|
|
dict[str, Any] | None
|
|
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
try_select_by_feature_tree ¶
try_select_by_feature_tree(target_doc: Any, feature_name: str, candidate_names: list[str]) -> dict[str, Any] | None
Walk the SolidWorks feature tree and select the first matching feature.
Iterates via FirstFeature / GetNextFeature (up to 10 000
features as a runaway guard) and compares each feature's Name
attribute against the normalised candidate set. Matching is
case-insensitive and also strips the @document qualifier.
This is the most expensive selection strategy and is only attempted
after :meth:try_select_by_extension and
:meth:try_select_by_component have both failed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_doc
|
Any
|
SolidWorks |
required |
feature_name
|
str
|
Original caller-supplied name for the result payload. |
required |
candidate_names
|
list[str]
|
Candidate names used to build the normalised match set. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
dict[str, Any] | None: Success dict (same schema as |
dict[str, Any] | None
|
meth: |
dict[str, Any] | None
|
|
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 | |
_SketchGeometryService ¶
Manage transient sketch-entity storage and provide geometry helpers.
Maintains a per-sketch registry that maps stable string IDs (e.g.
"Line_1", "Circle_3") to live SolidWorks COM entity objects. The
registry is reset each time a new sketch is opened or closed.
Also provides geometry primitives used by the sketch-dimension pipeline: coordinate extraction, segment endpoint reading, shared-vertex detection, and smart-dimension placement-point calculation.
Attributes:
| Name | Type | Description |
|---|---|---|
_adapter |
Back-reference to the owning |
Store a back-reference to the owning adapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
PyWin32Adapter
|
The |
required |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
Methods:¶
angular_dimension_placement ¶
Compute the text-placement point for an angular dimension between two lines.
Detects the shared vertex, derives the two ray directions, bisects the angle, offsets the placement point by 15–30 mm along the bisector (clamped to 60 % of the shorter leg), and converts the bisector to a dimension-direction constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity1
|
Any
|
First SolidWorks sketch-line COM object. |
required |
entity2
|
Any
|
Second SolidWorks sketch-line COM object (must share a
vertex with |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float, int] | None
|
tuple[float, float, float, int] | None: |
tuple[float, float, float, int] | None
|
|
tuple[float, float, float, int] | None
|
when no shared vertex is found or segment data is unavailable. |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
point_xyz ¶
Extract the XYZ coordinates from a SolidWorks point-like COM object.
Tries two access patterns:
- Direct attribute access —
point_obj.X,point_obj.Y,point_obj.Z(IMathPoint,IVertex). - Method call —
point_obj.GetCoords()returning a sequence of at least three numbers.
All values are in metres (SolidWorks internal units).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point_obj
|
Any
|
Any COM object that might expose XYZ coordinates.
|
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float] | None
|
tuple[float, float, float] | None: |
tuple[float, float, float] | None
|
|
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
read_segment_endpoints ¶
read_segment_endpoints(entity: Any) -> tuple[tuple[float, float, float], tuple[float, float, float]] | None
Read the start and end coordinates of a sketch line or arc segment.
Accesses entity.GetStartPoint and entity.GetEndPoint (as
properties, not method calls). Both must return sequences of at least
three numeric values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
Any
|
SolidWorks |
required |
Returns:
| Type | Description |
|---|---|
tuple[tuple[float, float, float], tuple[float, float, float]] | None
|
tuple[tuple, tuple] | None: |
tuple[tuple[float, float, float], tuple[float, float, float]] | None
|
metres, or |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
register_entity ¶
Store a COM entity handle and return a stable string identifier.
Increments the counter, derives an ID of the form
"<prefix>_<counter>" (e.g. "Line_3"), stores the entity in
adapter._sketch_entities, and returns the ID so callers can
reference the entity in later dimension or constraint calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Descriptor for the entity type, e.g. |
required |
entity
|
Any
|
Live SolidWorks COM entity object returned by the
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Stable entity ID, e.g. |
Example::
line_id = service.register_entity("Line", sw_line_obj)
# line_id == "Line_1"
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
reset_registry ¶
Clear the sketch entity registry and reset the ID counter.
Should be called at the start of every new sketch (via
adapter._reset_sketch_entity_registry) so that entity IDs from a
previous sketch do not bleed into the current session.
Side Effects
Clears adapter._sketch_entities and sets
adapter._sketch_entity_counter to 0.
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
segment_point_objects ¶
Return the COM point objects at the start and end of a segment.
Unlike :meth:read_segment_endpoints, this returns the raw COM
objects (ISketchPoint) rather than coordinate tuples, so they can
be used in selection calls for angular dimensioning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
Any
|
SolidWorks sketch segment COM object. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
tuple[Any | None, Any | None]: |
Any | None
|
either element may be |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
select_entity ¶
Select a COM entity in the SolidWorks selection manager.
Tries three COM selection methods in decreasing API version order:
Select4 (modern), Select2 (legacy), Select (oldest). The
first call that returns a truthy value terminates the search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
Any
|
Live SolidWorks COM sketch entity object (line, arc, circle, etc.). |
required |
append
|
bool
|
When |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
bool
|
|
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
set_display_dimension_value ¶
Set the numeric value of a display-dimension object.
Converts the value from millimetres to metres and tries three COM paths in order:
GetDimension2(0).SetSystemValue3(value_m, 1, None)— modern.GetDimension().SetSystemValue2(value_m, 1)— legacy.- Direct
SystemValueproperty assignment — oldest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_dim
|
Any
|
SolidWorks display-dimension COM object returned by
|
required |
value_mm
|
float
|
Desired dimension value in millimetres. Converted to metres internally. |
required |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
set_point_xyz ¶
Set coordinates on a SolidWorks point-like COM object.
Tries SetCoords(x, y, z) first (modern API), then
SetCoords2(x, y, z) (older variant). All values should be in
metres.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point_obj
|
Any
|
COM point object to update, or |
required |
x
|
float
|
New X coordinate in metres. |
required |
y
|
float
|
New Y coordinate in metres. |
required |
z
|
float
|
New Z coordinate in metres. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
bool
|
(including when |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
shared_segment_vertex ¶
Find a vertex point shared by two sketch segments.
Compares all four endpoint-object pairs (2 from each segment) using a coordinate tolerance of 1e-6 m. Used by the angular-dimension pipeline to locate the pivot vertex between two lines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity1
|
Any
|
First SolidWorks sketch segment COM object. |
required |
entity2
|
Any
|
Second SolidWorks sketch segment COM object. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Any, Any, Any] | None
|
tuple[Any, Any, Any] | None: ``(shared_point_obj, point1_obj, |
tuple[Any, Any, Any] | None
|
point2_obj) |
tuple[Any, Any, Any] | None
|
(same object as |
tuple[Any, Any, Any] | None
|
|
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
single_line_dimension_placement ¶
Compute the text-placement point and direction for a linear dimension.
Reads the segment midpoint, computes the outward normal (perpendicular to the segment direction), offsets the placement point by 35 % of the segment length (clamped to 10–20 mm), and converts the normal to a SolidWorks dimension-direction constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
Any
|
SolidWorks |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float, int] | None
|
tuple[float, float, float, int] | None: |
tuple[float, float, float, int] | None
|
|
tuple[float, float, float, int] | None
|
when endpoint data is unavailable. |
Example::
placement = service.single_line_dimension_placement(line_obj)
if placement:
text_x, text_y, text_z, direction = placement
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
smart_dimension_direction ¶
Map a 2-D direction vector to a SolidWorks dimension-direction constant.
The dominant axis determines horizontal vs vertical; within each axis the sign selects left/right or up/down.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dx
|
float
|
Horizontal component of the dimension normal vector. |
required |
dy
|
float
|
Vertical component of the dimension normal vector. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
One of the four |
int
|
from |
|
int
|
|
|
int
|
|
|
int
|
|
|
int
|
|
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
Functions:¶
_dynamic_dispatch ¶
Forward to win32com.client.dynamic.Dispatch via the imported
module reference. Forces late binding so VARIANT pass-by-ref params
used by OpenDoc6 keep working even when the makepy gen_py
wrapper is loaded.
Tests that need to stub dispatch should monkeypatch
win32com.client.dynamic.Dispatch directly — the monkeypatch
propagates through this module reference because Python modules
are singletons.
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
_parse_vb_module_name ¶
Read Attribute VB_Name = "..." from a SolidWorks text macro file.
Falls back to the file stem (e.g. paper_airplane for paper_airplane.swp), then
to "SolidWorksMacro" which is the name used by the macro recorder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
macro_path
|
str
|
The macro path value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The resulting text value. |