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¶
_DOCUMENT_OPERATIONS
module-attribute
¶
_DOCUMENT_OPERATIONS = frozenset({'activate_document', 'close_model', 'create_assembly', 'create_drawing', 'create_part', 'create_technical_drawing', 'open_model', 'pack_and_go_assembly', 'save_body_as_part', 'standard_drawing_views'})
_SW_RUN_MACRO_ERROR
module-attribute
¶
_SW_RUN_MACRO_ERROR = {0: 'NoError', 1: 'InvalidArg', 2: 'MacrosAreDisabled', 3: 'NotInDesignMode', 4: 'OnlyCodeModules', 5: 'OutOfMemory', 6: 'InvalidProcname', 7: 'InvalidPropertyType', 8: 'SuborfuncExpected', 9: 'BadParmCount', 10: 'BadVarType', 11: 'UserInterrupt', 12: 'Exception', 13: 'Overflow', 14: 'TypeMismatch', 15: 'ParmNotOptional', 16: 'UnknownLcid', 17: 'Busy', 18: 'ConnectionTerminated', 19: 'CallRejected', 20: 'CallFailed', 21: 'Zombied', 22: 'Invalidindex', 23: 'NoPermission', 24: 'Reverted', 25: 'TooManyOpenFiles', 26: 'DiskError', 27: 'CantSave', 28: 'OpenFileFailed'}
_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)
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: SolidWorksDrawingStandardMixin, SolidWorksDocumentationMixin, 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
1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 | |
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
2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 | |
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
2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 | |
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:¶
activate_document
async
¶
Make an already-open document the active one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title_or_path
|
str
|
Title, full path, or file name of an open document. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: What was activated, or error. |
Source code in src/solidworks_mcp/adapters/base.py
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_chamfer
async
¶
add_chamfer(distance: float, edge_names: list[str], angle: float = 45.0, flip: bool = False) -> AdapterResult[Any]
Add an angle-distance chamfer to the named or selected edges.
At the default 45 degrees both legs equal distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distance
|
float
|
Chamfer distance in millimeters, along one face. |
required |
edge_names
|
list[str]
|
List of edge names to chamfer. |
required |
angle
|
float
|
Chamfer angle in degrees. Defaults to 45. |
45.0
|
flip
|
bool
|
Measure |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
AdapterResult |
AdapterResult[Any]
|
Feature result or error. |
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_datum_tag
async
¶
add_datum_tag(label: str, attach_at_mm: tuple[float, float], x_mm: float, y_mm: float) -> AdapterResult[dict[str, Any]]
Add a datum feature symbol on a drawing edge.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Error unless the adapter implements it. |
Source code in src/solidworks_mcp/adapters/base.py
add_drawing_view
async
¶
Add a view of a model to the active drawing sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
Any
|
Tool payload carrying the model path, orientation, position in millimetres and optional view scale. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The new view's details, or error. |
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_gtol
async
¶
add_gtol(characteristic: str, tolerance: float, x_mm: float, y_mm: float, diameter_zone: bool = False, material_condition: str = 'none', datums: list[str] | None = None, attach_at_mm: tuple[float, float] | None = None, dimension: tuple[str, str] | None = None) -> AdapterResult[dict[str, Any]]
Add a GD&T feature control frame to the active drawing.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Error unless the adapter implements it. |
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, face_a: list[float] | None = None, face_b: list[float] | None = None) -> 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
|
face_a
|
list[float] | None
|
A point on a face of the first
component, in its part coordinates (mm), used instead of
|
None
|
face_b
|
list[float] | None
|
The same for the second component. |
None
|
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_note
async
¶
Place a text note on the active drawing sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
Any
|
Tool payload carrying the note text, its position in millimetres and an optional font size in points. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The note's 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
arrange_dimensions
async
¶
Move drawing dimensions so none overlaps, then verify.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Error unless the adapter implements it. |
Source code in src/solidworks_mcp/adapters/base.py
auto_center_marks
async
¶
auto_center_marks(view_name: str, mark_holes: bool = True, mark_fillets: bool = False, mark_slots: bool = True) -> AdapterResult[dict[str, Any]]
Auto-insert centre marks on circular features in a drawing view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_name
|
str
|
Name of a view on the active drawing. |
required |
mark_holes
|
bool
|
Mark holes / bores. |
True
|
mark_fillets
|
bool
|
Mark fillets. |
False
|
mark_slots
|
bool
|
Mark slots. |
True
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The view and before/after centre-mark |
AdapterResult[dict[str, Any]]
|
counts, or error. |
Source code in src/solidworks_mcp/adapters/base.py
check_interference
async
¶
Check the active assembly for interfering components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Any
|
Optional settings; |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Interference details, or error. |
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_assembly(name: str | None = None, template: str | None = None) -> AdapterResult[SolidWorksModel]
Create a new assembly document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The name value. Defaults to None. |
None
|
template
|
str | None
|
Template file path. 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_axis
async
¶
Create a reference axis along a principal direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
str
|
"x", "y" or "z" (case-insensitive, leading ± stripped). |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The plane pair used and feature counts, or error. |
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_drawing(name: str | None = None, template: str | None = None) -> AdapterResult[SolidWorksModel]
Create a new drawing document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The name value. Defaults to None. |
None
|
template
|
str | None
|
Template file path. 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_drawing_view
async
¶
Place a view of a model on the active drawing sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
Any
|
Tool payload carrying the model path, orientation, position in millimetres and optional view scale. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The new view's details, or error. |
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_part(name: str | None = None, units: str | None = None, template: str | None = None) -> AdapterResult[SolidWorksModel]
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
|
template
|
str | None
|
Template file path. 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_reference_plane
async
¶
create_reference_plane(reference: str, offset: float = 0.0, angle: float = 0.0, flip: bool = False, axis: str | None = None, face_point: list[float] | None = None) -> AdapterResult[dict[str, Any]]
Create a reference plane offset from, angled to, or on a plane or face.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
str
|
Name of the reference plane. |
required |
offset
|
float
|
Offset distance in millimetres. Defaults to 0.0. |
0.0
|
angle
|
float
|
Angle in degrees about |
0.0
|
flip
|
bool
|
Reverse the offset or angle direction. Defaults to False. |
False
|
axis
|
str | None
|
Named axis to rotate about; needed with |
None
|
face_point
|
list[float] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The new plane's name and parameters, or error. |
Source code in src/solidworks_mcp/adapters/base.py
create_reference_point
async
¶
create_reference_point(mode: str, x: float, y: float, z: float, distance: float | None = None, percent: float | None = None) -> AdapterResult[dict[str, Any]]
Create a reference point on the active part.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
"along_curve" or "face_center". |
required |
x
|
float
|
X of a point on the target edge/face, in millimetres. |
required |
y
|
float
|
Y of a point on the target edge/face, in millimetres. |
required |
z
|
float
|
Z of a point on the target edge/face, in millimetres. |
required |
distance
|
float | None
|
For "along_curve", offset from the edge start in millimetres. |
None
|
percent
|
float | None
|
For "along_curve", position as 0-100 of the edge length. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The mode and feature counts, or error. |
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_standard_drawing
async
¶
create_standard_drawing(model_path: str, output_dir: str | None = None, title: str | None = None, subtitle: str | None = None, drawing_number: str | None = None, author: str = '', revision: str = 'A', company: str = '', drawn_date: str | None = None, notes: list[str] | None = None, include_isometric: bool = True, write_model_properties: bool = True, title_block_text_height_mm: float | None = None, include_bom: bool = False) -> AdapterResult[dict[str, Any]]
Create a complete standard A3 drawing.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Error unless the adapter implements it. |
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
create_technical_drawing
async
¶
Lay out the standard views of a model on the active sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
Any
|
Tool payload carrying the model path and the projection angle. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The view names created, or error. |
Source code in src/solidworks_mcp/adapters/base.py
delete_feature
async
¶
Delete a named feature or sketch from the active model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Feature or sketch name. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: What was deleted, or error. |
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_flat_pattern
async
¶
Export the active sheet-metal part's flat pattern.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Error unless the adapter implements it. |
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_application_info
async
¶
Describe the connected SolidWorks without changing anything.
Only file names leave the adapter, never full paths, so the result
can be pasted into a public report. A value that cannot be read is
None, never guessed.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
|
Source code in src/solidworks_mcp/adapters/base.py
get_custom_properties
async
¶
Read the custom properties of the active document.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Error unless the adapter implements it. |
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[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
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_material
async
¶
Read the material assigned to the active part.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Error unless the adapter implements it. |
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_geometry_summary
async
¶
Summarise the active part or assembly without changing it.
Must not rebuild the model, modify it, or clear the selection, so
callers can read it around a feature call. Values the adapter cannot
determine are None, never guessed.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
|
Source code in src/solidworks_mcp/adapters/base.py
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. |
get_selected_entities
async
¶
Report the faces/edges/vertices currently selected in the live UI.
Lets an agent see exactly what the user has clicked on in SolidWorks (e.g. "chamfer THIS face") instead of inferring it from a screenshot.
Returns:
| Type | Description |
|---|---|
AdapterResult[list[dict[str, Any]]]
|
AdapterResult[list[dict[str, Any]]]: One descriptor per selected |
AdapterResult[list[dict[str, Any]]]
|
entity. See the PyWin32 adapter's implementation for the field |
AdapterResult[list[dict[str, Any]]]
|
set (varies by entity type). |
Source code in src/solidworks_mcp/adapters/base.py
health_check
abstractmethod
async
¶
Get adapter health status.
Returns:
| Name | Type | Description |
|---|---|---|
AdapterHealth |
AdapterHealth
|
The result produced by the operation. |
insert_bom_table
async
¶
insert_bom_table(view_name: str, template_path: str | None = None, bom_type: str = 'top_level_only', x_mm: float | None = None, y_mm: float | None = None) -> AdapterResult[dict[str, Any]]
Insert a BOM table anchored to an assembly drawing view.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Error unless the adapter implements it. |
Source code in src/solidworks_mcp/adapters/base.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.
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
insert_model_dimensions
async
¶
insert_model_dimensions(view_name: str | None = None, include_hole_wizard: bool = True) -> AdapterResult[dict[str, Any]]
Bring model dimensions into drawing views.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Error unless the adapter implements it. |
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_available_materials
async
¶
List materials from the configured material libraries.
Returns:
| Type | Description |
|---|---|
AdapterResult[list[dict[str, str]]]
|
AdapterResult[list[dict[str, str]]]: Error unless the adapter implements it. |
Source code in src/solidworks_mcp/adapters/base.py
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_drawing_views
async
¶
List the views on the active drawing.
Returns:
| Type | Description |
|---|---|
AdapterResult[list[str]]
|
AdapterResult[list[str]]: View names, or error. |
Source code in src/solidworks_mcp/adapters/base.py
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
list_model_dimensions
async
¶
List every dimension in the active part or assembly.
Returns:
| Type | Description |
|---|---|
AdapterResult[list[dict[str, Any]]]
|
AdapterResult[list[dict[str, Any]]]: Error unless the adapter implements it. |
Source code in src/solidworks_mcp/adapters/base.py
list_open_documents
async
¶
Enumerate every document currently open in SolidWorks.
Returns:
| Type | Description |
|---|---|
AdapterResult[list[dict[str, Any]]]
|
AdapterResult[list[dict[str, Any]]]: One entry per open document |
AdapterResult[list[dict[str, Any]]]
|
( |
Source code in src/solidworks_mcp/adapters/base.py
measure_entities
async
¶
Measure one or two selected entities.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Error unless the adapter implements it. |
Source code in src/solidworks_mcp/adapters/base.py
mirror_feature
async
¶
mirror_feature(features: list[str], mirror_plane: str, merge: bool = True, mirror_bodies: bool = True) -> AdapterResult[dict[str, Any]]
Mirror solid bodies or features about a plane.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list[str]
|
Body or feature names to mirror. |
required |
mirror_plane
|
str
|
Plane name to mirror about. |
required |
merge
|
bool
|
Merge the mirrored result with the original. Defaults to True. |
True
|
mirror_bodies
|
bool
|
Mirror whole bodies rather than features. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The mirror feature's name, inputs and volume |
AdapterResult[dict[str, Any]]
|
before/after, or error. |
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
pattern_circular
async
¶
pattern_circular(features: list[str], axis: str, count: int, angle: float = 360.0, equal_spacing: bool = True) -> AdapterResult[dict[str, Any]]
Pattern features around an axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list[str]
|
Names of the features to pattern. |
required |
axis
|
str
|
Name of the axis to rotate about. |
required |
count
|
int
|
Total number of instances including the original. |
required |
angle
|
float
|
Total angle in degrees to spread them over. Defaults to 360.0. |
360.0
|
equal_spacing
|
bool
|
Space instances evenly across |
True
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: What was patterned and the volume |
AdapterResult[dict[str, Any]]
|
before/after, or error. |
Source code in src/solidworks_mcp/adapters/base.py
rebuild_model
async
¶
Force a rebuild and report per-feature rebuild errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top_level_only
|
bool
|
Rebuild only the top level of an assembly. Defaults to False (full rebuild). |
False
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
ERROR (still carrying |
AdapterResult[dict[str, Any]]
|
remains. |
Source code in src/solidworks_mcp/adapters/base.py
rename_feature
async
¶
Rename an existing feature on the feature tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_name
|
str
|
Current feature name. |
required |
new_name
|
str
|
New feature name. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The old and new names, or error. |
Source code in src/solidworks_mcp/adapters/base.py
reset_circuit_breakers
async
¶
Re-open operations a circuit breaker paused.
An adapter without a circuit breaker has nothing paused; the breaker and the connection pool override this.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operation
|
str | None
|
The operation to reset; |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, list[str]]]
|
AdapterResult[dict[str, list[str]]]: |
Source code in src/solidworks_mcp/adapters/base.py
save_body_as_part
async
¶
Extract one solid body from the active multibody part to a new file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
body_name
|
str
|
Name of a solid body in the active part. |
required |
file_path
|
str
|
Absolute path for the new |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The body, the written path, and the |
AdapterResult[dict[str, Any]]
|
solid-body names found, or error. |
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
select_face_edges
async
¶
select_face_edges(point: list[float] | None = None, side: str | None = None, plane: str | None = None, edge_type: str = 'all', append: bool = False) -> AdapterResult[dict[str, Any]]
Multi-select every edge bounding one face of the active part.
Exactly one of point/side/plane identifies the face.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
list[float] | None
|
|
None
|
side
|
str | None
|
|
None
|
plane
|
str | None
|
Reference plane name; the body face(s) lying on it. |
None
|
edge_type
|
str
|
|
'all'
|
append
|
bool
|
Add to the current selection. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
(one descriptor per selected edge) and |
Source code in src/solidworks_mcp/adapters/base.py
select_feature
async
¶
Select a named feature, sketch, plane or component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature_name
|
str
|
The feature name, optionally |
required |
append
|
bool
|
Add to the current selection instead of replacing it. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: On success |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
SUCCESS with |
Source code in src/solidworks_mcp/adapters/base.py
set_component_state
async
¶
set_component_state(component: str, fixed: bool | None = None, flexible: bool | None = None) -> AdapterResult[dict[str, Any]]
Fix or float a component, and make a sub-assembly rigid or flexible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
str
|
Instance name, as |
required |
fixed
|
bool | None
|
True fixes it, False floats it. |
None
|
flexible
|
bool | None
|
True flexible, False rigid. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The state before and after, or error. |
Source code in src/solidworks_mcp/adapters/base.py
set_custom_property
async
¶
set_custom_property(name: str, value: str, configuration: str | None = None) -> AdapterResult[dict[str, Any]]
Create or overwrite one custom property.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Error unless the adapter implements it. |
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
set_material
async
¶
set_material(material_name: str, database: str | None = None, configuration: str | None = None) -> AdapterResult[dict[str, Any]]
Assign a material to the active part.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Error unless the adapter implements it. |
Source code in src/solidworks_mcp/adapters/base.py
set_sheet_scale
async
¶
Set the active drawing sheet's scale.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Error unless the adapter implements it. |
Source code in src/solidworks_mcp/adapters/base.py
set_units
async
¶
Set the active document's linear unit system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit_system
|
str
|
One of |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: What was applied, or error. |
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
suppress_feature
async
¶
Suppress or unsuppress a named feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Feature name. |
required |
suppress
|
bool
|
True to suppress, False to unsuppress. |
True
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The resulting state, or error. |
Source code in src/solidworks_mcp/adapters/base.py
undo
async
¶
Undo the last operations in the active model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int
|
Number of steps to undo. |
1
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Whether the tree changed, or error. |
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
SolidWorksDocumentationMixin ¶
Expose model-data and drawing-documentation methods through a mixin.
Methods:¶
arrange_dimensions
async
¶
Move drawing dimensions so none overlaps another, then verify.
Reads every dimension's text box and lines, plans positions outside
the views with :func:dimension_layout.plan_layout, applies them with
IAnnotation::SetPosition, rebuilds, then re-reads the real
geometry and checks the rule with :func:dimension_layout.find_overlaps.
The check covers every view on the sheet, even when only one view is
rearranged, because neighbouring views' dimensions can collide.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_name
|
str | None
|
Only move this view's dimensions; all views when omitted. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
(each violation listed), |
AdapterResult[dict[str, Any]]
|
overlap remains - the rule is not met - with the same data, so the |
AdapterResult[dict[str, Any]]
|
caller can see which dimensions still collide. |
Source code in src/solidworks_mcp/adapters/solidworks/documentation.py
export_flat_pattern
async
¶
Export the active sheet-metal part's flat pattern to DXF or DWG.
Wraps IPartDoc::ExportToDWG2 with swExportToDWG_ExportSheetMetal.
SheetMetalOptions 1 exports the flat-pattern geometry only (no bend
lines or sketches).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Output |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The written path and its size. |
Source code in src/solidworks_mcp/adapters/solidworks/documentation.py
get_custom_properties
async
¶
Read the custom properties of the active document.
Wraps IModelDocExtension::CustomPropertyManager(config) with
GetNames + Get6. "" reads the file-level properties a
drawing title block usually links to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
configuration
|
str | None
|
Configuration name; file-level when omitted. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
|
Source code in src/solidworks_mcp/adapters/solidworks/documentation.py
get_material
async
¶
Read the material assigned to the active part.
Wraps IPartDoc::GetMaterialPropertyName2; see
:func:_read_material for its Database out-parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
configuration
|
str | None
|
Configuration name; the active one when omitted. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
in its |
Source code in src/solidworks_mcp/adapters/solidworks/documentation.py
insert_model_dimensions
async
¶
insert_model_dimensions(view_name: str | None = None, include_hole_wizard: bool = True) -> AdapterResult[dict[str, Any]]
Bring model dimensions into drawing views, each dimension shown once.
Imports the model's "marked for drawing" dimensions view by view with
IDrawingDoc::InsertModelAnnotations3 (UsePlacementInSketch off,
so SolidWorks places them rather than copying sketch positions).
Drafting rules applied:
- pictorial views (isometric, dimetric, trimetric) are not dimensioned unless named explicitly;
- a model dimension already shown in an earlier view is deleted from later views, so each dimension appears exactly once on the sheet.
Falls back to IDrawingDoc::AutoDimension only when nothing at all
could be imported. Placement is then made overlap-free by
:meth:arrange_dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_name
|
str | None
|
One view to dimension; every orthographic view when omitted. |
None
|
include_hole_wizard
|
bool
|
Also import Hole Wizard location dimensions. |
True
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Per-view counts, duplicates removed, |
AdapterResult[dict[str, Any]]
|
skipped pictorial views and the |
Source code in src/solidworks_mcp/adapters/solidworks/documentation.py
list_available_materials
async
¶
List materials from the configured SolidWorks material libraries.
Reads the custom library folders from
swFileLocationsMaterialDatabases (a ;-separated list) plus the
install's built-in sldmaterials folder, and parses every
.sldmat file in them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search
|
str | None
|
Case-insensitive substring filter on name or classification. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[list[dict[str, str]]]
|
AdapterResult[list[dict[str, str]]]: |
AdapterResult[list[dict[str, str]]]
|
and |
AdapterResult[list[dict[str, str]]]
|
read and the |
AdapterResult[list[dict[str, str]]]
|
told apart from an unexpected library location. |
Source code in src/solidworks_mcp/adapters/solidworks/documentation.py
list_model_dimensions
async
¶
List every dimension in the active part or assembly.
Walks IModelDoc2::FirstFeature / IFeature::GetNextFeature and
each feature's GetFirstDisplayDimension chain. full_name (e.g.
"D1@Sketch1") is the name set_dimension accepts, so the pair
gives edit-by-name access to every driving parameter in the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature_name
|
str | None
|
Only list dimensions of this feature (case-insensitive). |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[list[dict[str, Any]]]
|
AdapterResult[list[dict[str, Any]]]: |
AdapterResult[list[dict[str, Any]]]
|
|
AdapterResult[list[dict[str, Any]]]
|
and |
Source code in src/solidworks_mcp/adapters/solidworks/documentation.py
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 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
measure_entities
async
¶
Measure one or more entities with SolidWorks' Measure tool.
Selects each entity by spec (see :func:_parse_measure_spec), then runs
IModelDocExtension::CreateMeasure + IMeasure::Calculate(None),
which measures the current selection. Values SolidWorks reports as
-1 (not applicable to the selection) are dropped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
list[str]
|
One or two entity specs, e.g. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Measured values in metres, square |
AdapterResult[dict[str, Any]]
|
metres and radians, plus |
AdapterResult[dict[str, Any]]
|
two entities. |
Source code in src/solidworks_mcp/adapters/solidworks/documentation.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
set_custom_property
async
¶
set_custom_property(name: str, value: str, configuration: str | None = None) -> AdapterResult[dict[str, Any]]
Create or overwrite one text custom property on the active document.
Wraps ICustomPropertyManager::Add3(name, swCustomInfoText, value,
swCustomPropertyReplaceValue) and reads the value back.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Property name, e.g. |
required |
value
|
str
|
Text value; may be a |
required |
configuration
|
str | None
|
Configuration name; file-level when omitted. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The stored and resolved value. |
Source code in src/solidworks_mcp/adapters/solidworks/documentation.py
set_material
async
¶
set_material(material_name: str, database: str | None = None, configuration: str | None = None) -> AdapterResult[dict[str, Any]]
Assign a material to the active part.
Wraps IPartDoc::SetMaterialPropertyName2 (a void call), then
reads the material back - the read-back is the only proof it applied.
A name the library does not hold leaves the part unchanged and is
reported as not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
material_name
|
str
|
Material name exactly as in the library, e.g.
|
required |
database
|
str | None
|
Library name; |
None
|
configuration
|
str | None
|
Configuration name; |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Requested and applied material. |
Source code in src/solidworks_mcp/adapters/solidworks/documentation.py
SolidWorksDrawingStandardMixin ¶
Create complete standard A3 drawings, BOM tables and the sheet scale.
Methods:¶
add_datum_tag
async
¶
add_datum_tag(label: str, attach_at_mm: tuple[float, float], x_mm: float, y_mm: float) -> AdapterResult[dict[str, Any]]
Add a datum feature symbol (a datum tag) on a drawing edge.
IModelDoc2::InsertDatumTag2 attaches the tag to the edge picked at
attach_at_mm; IDatumTag::SetLabel names it, and the label is
read back with GetLabel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The datum letter, e.g. |
required |
attach_at_mm
|
tuple[float, float]
|
A sheet point on the edge or face line it marks. |
required |
x_mm
|
float
|
Where the tag goes on the sheet. |
required |
y_mm
|
float
|
Where the tag goes on the sheet. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The label as read back. |
Source code in src/solidworks_mcp/adapters/solidworks/drawing_standard.py
add_gtol
async
¶
add_gtol(characteristic: str, tolerance: float, x_mm: float, y_mm: float, diameter_zone: bool = False, material_condition: str = 'none', datums: list[str] | None = None, attach_at_mm: tuple[float, float] | None = None, dimension: tuple[str, str] | None = None) -> AdapterResult[dict[str, Any]]
Add a feature control frame (GD&T) to the active drawing.
IModelDoc2::InsertGtol creates the frame on whatever is selected:
a drawing dimension (dimension; the frame sits under its text and
moves with it, the usual place for a hole's position tolerance), the
edge picked at attach_at_mm (with a leader), or nothing
(free-standing);
IGtol::SetFrameSymbols2 sets the characteristic, the Ø zone and
the material condition, and IGtol::SetFrameValues the tolerance
and datums. The values are read back with GetFrameValues, so a
frame SolidWorks did not fill in is an error, not a success.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
characteristic
|
str
|
|
required |
tolerance
|
float
|
The tolerance value, in drawing units. |
required |
x_mm
|
float
|
Where the frame goes on the sheet. |
required |
y_mm
|
float
|
Where the frame goes on the sheet. |
required |
diameter_zone
|
bool
|
Prefix the tolerance with Ø (a cylindrical zone). |
False
|
material_condition
|
str
|
|
'none'
|
datums
|
list[str] | None
|
Up to three datum letters, primary first. |
None
|
attach_at_mm
|
tuple[float, float] | None
|
A sheet point on the edge the leader points to. |
None
|
dimension
|
tuple[str, str] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The frame as read back. |
Source code in src/solidworks_mcp/adapters/solidworks/drawing_standard.py
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 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 | |
create_standard_drawing
async
¶
create_standard_drawing(model_path: str, output_dir: str | None = None, title: str | None = None, subtitle: str | None = None, drawing_number: str | None = None, author: str = '', revision: str = 'A', company: str = '', drawn_date: str | None = None, notes: list[str] | None = None, include_isometric: bool = True, write_model_properties: bool = True, title_block_text_height_mm: float | None = None, include_bom: bool = False) -> AdapterResult[dict[str, Any]]
Create a complete A3 drawing that follows the drawing standard.
Opens the model (or uses its open copy), writes the title-block
properties into it, makes a drawing on the A3 ISO format, builds the
sheet in separate COM steps, writes the drawing properties, saves
<drawing_number>.SLDDRW and exports a PDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path
|
str
|
Part (.SLDPRT) or assembly (.SLDASM) to draw. |
required |
output_dir
|
str | None
|
Folder for the .SLDDRW and PDF; the model's folder by default. |
None
|
title
|
str | None
|
Title block TITLE; the model file name by default. |
None
|
subtitle
|
str | None
|
Company field when |
None
|
drawing_number
|
str | None
|
DWG NO.; also the drawing file name. Default
|
None
|
author
|
str
|
DRAWN name. |
''
|
revision
|
str
|
Revision letter. |
'A'
|
company
|
str
|
Company name field. |
''
|
drawn_date
|
str | None
|
DRAWN date; today (e.g. "17 Oct 2026") by default. |
None
|
notes
|
list[str] | None
|
Extra note lines (at most seven lines in total are shown). |
None
|
include_isometric
|
bool
|
Add the isometric view in its cell. |
True
|
write_model_properties
|
bool
|
Write Description/Material/Weight custom properties into the model (the format reads them from there) and save the model. |
True
|
title_block_text_height_mm
|
float | None
|
Largest text height for the DWG NO. and TITLE fields, e.g. 3 for smaller text; they are shrunk further when they still do not fit. |
None
|
include_bom
|
bool
|
Assemblies only: a top-level BOM in the top of the isometric's cell, the isometric fitted below it. |
False
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Files, scale, views, dimension |
AdapterResult[dict[str, Any]]
|
counts, the overlap check, every property written and each step's |
AdapterResult[dict[str, Any]]
|
outcome. ERROR, with that data, when a step fails, the drawing or |
AdapterResult[dict[str, Any]]
|
PDF could not be saved, or any overlap remains. |
Source code in src/solidworks_mcp/adapters/solidworks/drawing_standard.py
1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 | |
insert_bom_table
async
¶
insert_bom_table(view_name: str, template_path: str | None = None, bom_type: str = 'top_level_only', x_mm: float | None = None, y_mm: float | None = None) -> AdapterResult[dict[str, Any]]
Insert a bill-of-materials table anchored to an assembly drawing view.
Wraps IView::InsertBomTable4. With no position the table snaps to
the sheet format's BOM anchor, or to the sheet's bottom-left corner
when the sheet has no format. Its stationary corner is the
bottom-left, so the table grows up onto the sheet; with the top-left
it hung below the sheet (measured live on SW 2026). The table's box is
read back and must lie on the sheet. An anchor near the top of the
sheet (the ISO A3 format's) makes it grow off the top, so a table
placed by the anchor is slid back onto the sheet; one placed at a
given x_mm/y_mm is never moved. With no template the library
default bom-standard.sldbomtbt from the BOM templates folder is
used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_name
|
str
|
A view of an assembly on the active drawing. |
required |
template_path
|
str | None
|
|
None
|
bom_type
|
str
|
|
'top_level_only'
|
x_mm
|
float | None
|
Optional table position on the sheet. |
None
|
y_mm
|
float | None
|
Optional table position on the sheet. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The view, BOM type, template, row |
AdapterResult[dict[str, Any]]
|
count, |
AdapterResult[dict[str, Any]]
|
the box when the table still runs off the sheet. |
Source code in src/solidworks_mcp/adapters/solidworks/drawing_standard.py
set_sheet_scale
async
¶
Set the active drawing sheet's scale, e.g. 1:2 (ISheet::SetScale).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
numerator
|
float
|
Scale numerator. |
required |
denominator
|
float
|
Scale denominator. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The sheet name, the |
AdapterResult[dict[str, Any]]
|
back from the sheet and the |
Source code in src/solidworks_mcp/adapters/solidworks/drawing_standard.py
SolidWorksFeaturesMixin ¶
Expose SolidWorks feature methods via mixin-local implementation helpers.
Methods:¶
add_fillet
async
¶
Fillet edges, then confirm the model's volume actually changed.
IModelDoc2.FeatureFillet3 can report success without building
anything, so besides the feature-count check inside
:func:_add_fillet_impl the volume is compared before and after,
here in the async layer for the same reason as mirror_feature.
An unreadable volume is not treated as failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Fillet radius in millimetres. |
required |
edge_names
|
list[str]
|
Edge names, |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksFeature]
|
AdapterResult[SolidWorksFeature]: The fillet, with |
AdapterResult[SolidWorksFeature]
|
|
AdapterResult[SolidWorksFeature]
|
could be read. |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
create_reference_point
async
¶
create_reference_point(mode: str, x: float, y: float, z: float, distance: float | None = None, percent: float | None = None) -> AdapterResult[dict[str, Any]]
Create a reference point on the active part.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
|
required |
x
|
float
|
X of a point on the target edge/face, in millimetres. |
required |
y
|
float
|
Y of a point on the target edge/face, in millimetres. |
required |
z
|
float
|
Z of a point on the target edge/face, in millimetres. |
required |
distance
|
float | None
|
For |
None
|
percent
|
float | None
|
For |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Delegates to |
AdapterResult[dict[str, Any]]
|
func: |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
delete_feature
async
¶
Delete a feature and report every feature that went with it.
The tree is listed before and after with list_features, the read
path that works on SolidWorks, and the names that disappeared become
removed_features: the named feature and its dependents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The feature or sketch to delete. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The delete's data plus |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
can't be listed). |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
mirror_feature
async
¶
mirror_feature(features: list[str], mirror_plane: str, merge: bool = True, mirror_bodies: bool = True) -> AdapterResult[dict[str, Any]]
Mirror solid bodies or features about a plane.
InsertMirrorFeature returns a Feature object even when it mirrored
nothing, so the model's volume is measured before and after and the
call is reported as failed if the volume did not change (a mirrored
cut lowers it, a mirrored boss or body raises it). That check runs
here rather than inside the COM closure because get_mass_properties
is the read path known to work - reading CreateMassProperty().Volume
inline returns None when a plane is still in the selection set,
which silently disables the check.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list[str]
|
Names of the bodies (or features) to mirror. For a body mirror these are the names as they appear under Solid Bodies, which for a lofted wing is the loft's own name. |
required |
mirror_plane
|
str
|
Plane to mirror about, e.g. |
required |
merge
|
bool
|
Merge the mirrored result with the original. |
True
|
mirror_bodies
|
bool
|
Mirror whole solid bodies rather than features.
Defaults to |
True
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: What was mirrored, and the volume |
AdapterResult[dict[str, Any]]
|
before, after and its change. |
AdapterResult[dict[str, Any]]
|
the call failed, or the volume did not change. |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
pattern_circular
async
¶
pattern_circular(features: list[str], axis: str, count: int, angle: float = 360.0, equal_spacing: bool = True) -> AdapterResult[dict[str, Any]]
Pattern features around an axis.
FeatureCircularPattern5 returns a Feature object whether or not it
produced anything, so the model volume is measured before and after
here - in the async layer, using get_mass_properties, which is the
read path that works. Reading volume inline inside the COM closure
returns None while a selection is active.
Note that instances landing off the parent body are silently dropped
by SolidWorks, so the volume changes by less than count - 1 times
the seed. That is correct behaviour, not a failure - only no change
at all means the pattern did nothing. A pattern of a cut lowers the
volume, a pattern of a boss raises it; both count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list[str]
|
Names of the features to pattern. |
required |
axis
|
str
|
Name of the axis to rotate about, e.g. |
required |
count
|
int
|
Total number of instances including the original. |
required |
angle
|
float
|
Total angle in degrees to spread them over. Defaults to a full 360. |
360.0
|
equal_spacing
|
bool
|
Space instances evenly across |
True
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: What was patterned and the volume |
AdapterResult[dict[str, Any]]
|
before, after and its change. |
AdapterResult[dict[str, Any]]
|
selected or the volume did not change. |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
rename_feature
async
¶
Rename a feature on the active model's tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_name
|
str
|
The feature's current name. |
required |
new_name
|
str
|
The name to give it. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Delegates to |
AdapterResult[dict[str, Any]]
|
func: |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
SolidWorksIOMixin ¶
Expose model open/save/create/configuration methods through a mixin.
Methods:¶
activate_document
async
¶
Make an already-open document the active one.
Matches title_or_path against the open documents by exact title,
by full path, or by file name (all case-insensitive), then calls
ISldWorks::ActivateDoc3 and updates the adapter's tracked
currentModel. The resulting ActiveDoc is read back and a
mismatch is reported as an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title_or_path
|
str
|
A window title ( |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
to) and |
AdapterResult[dict[str, Any]]
|
not be performed). |
AdapterResult[dict[str, Any]]
|
blank, or nothing open matches. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 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 | |
add_drawing_view
async
¶
Add a view of a model to the active drawing sheet.
The same operation as create_drawing_view; both tool entry points
exist upstream and reach this one implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
Any
|
Tool payload; see |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The new view's name and position. |
Source code in src/solidworks_mcp/adapters/solidworks/io.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, face_a: list[float] | None = None, face_b: list[float] | None = None) -> AdapterResult[dict[str, Any]]
Mate two components together.
Wraps IAssemblyDoc::AddMate5. A named entity (a reference plane or
axis) is selected via IComponent2::FeatureByName +
IFeature::Select2. A face is given as a point on it in the
component's own part coordinates: the face is found among that
component's faces only (IComponent2::GetBodies2, which report
part coordinates; measured on SW 2026) and selected with
IEntity::Select4. Searching one component means a pin and the
hole it sits in, whose surfaces share points, can't be confused.
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
|
face_a
|
list[float] | None
|
|
None
|
face_b
|
list[float] | None
|
The same for the second component. |
None
|
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
2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 | |
add_note
async
¶
Place a text note on the active drawing sheet.
Wraps IModelDoc2::InsertNote(Text) and then positions the returned
annotation: InsertNote places the note wherever SolidWorks likes,
so the position is applied afterwards via IAnnotation::SetPosition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
Any
|
Tool payload. Reads |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The note text and where it landed. |
Example::
await adapter.add_note(
{"text": "MATERIAL: AISI 1018", "position_x": 200.0,
"position_y": 50.0}
)
Source code in src/solidworks_mcp/adapters/solidworks/io.py
3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 | |
auto_center_marks
async
¶
auto_center_marks(view_name: str, mark_holes: bool = True, mark_fillets: bool = False, mark_slots: bool = True) -> AdapterResult[dict[str, Any]]
Auto-insert centre marks on circular features in a drawing view.
Wraps IView::AutoInsertCenterMarks2 (falling back to
AutoInsertCenterMarks on older builds) using the document's
default size/gap/font. IView::GetCenterMarkCount() returns 0
regardless of marks actually present on SW 3DEXPERIENCE R2026x, so
the count is derived instead from IView::GetAnnotations(): the
view's annotations are enumerated and those flagged as
swCenterMarkSym (swAnnotationType_e) are counted.
center_marks_before == center_marks_after == 0 is reported when
the annotation enumeration cannot be performed (COM unavailable or
older builds).
Adding nothing is still a success - the view may simply have no un-marked circular features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_name
|
str
|
Name of a view on the active drawing. |
required |
mark_holes
|
bool
|
Mark holes / bores. Defaults to |
True
|
mark_fillets
|
bool
|
Mark fillets. Defaults to |
False
|
mark_slots
|
bool
|
Mark slots. Defaults to |
True
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The view, the feature types acted |
AdapterResult[dict[str, Any]]
|
on, and |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
a drawing, no feature type is selected, or the view is not found. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 | |
check_interference
async
¶
Run SolidWorks' interference detection on the active assembly.
Uses IAssemblyDoc::InterferenceDetectionManager
(IInterferenceDetectionMgr), not the older
ToolsCheckInterference2. That call is declared Sub with two
ByRef out-parameters, and on SW 2025 through pywin32 late binding
it could not be made to report anything: pythoncom.Missing raises
PyOleMissing can not be converted to a COM VARIANT, a plain
None or a typed array VARIANT raises Type mismatch, passing a
component array throws server-side, and a byref VT_VARIANT pair is
accepted but leaves both out-parameters None for an assembly that
demonstrably interferes. An inspection tool that always answers "no
interference" is worse than one that refuses.
GetInterferenceCount is an ordinary return value, so 0 is a
real measurement rather than a swallowed failure, and each
IInterference carries the overlap Volume.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Any
|
Optional settings. |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
overlap volumes in mm^3. |
AdapterResult[dict[str, Any]]
|
or the active document is not an assembly. |
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Example::
await adapter.check_interference({"coincident": False})
Source code in src/solidworks_mcp/adapters/solidworks/io.py
3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 | |
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_assembly(name: str | None = None, template: str | None = None) -> AdapterResult[SolidWorksModel]
Create a new assembly document and set it as active.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Reserved for future naming policy. |
None
|
template
|
str | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksModel]
|
AdapterResult[SolidWorksModel]: Metadata for the new assembly document. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 | |
create_drawing
async
¶
create_drawing(name: str | None = None, template: str | None = None) -> AdapterResult[SolidWorksModel]
Create a new drawing document and set it as active.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Reserved for future naming policy. |
None
|
template
|
str | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksModel]
|
AdapterResult[SolidWorksModel]: Metadata for the new drawing document. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 | |
create_drawing_view
async
¶
Place a view of a model on the active drawing sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
Any
|
Tool payload; see |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The new view's name and position. |
Example::
await adapter.create_drawing_view(
{"model_path": r"C:\parts\bracket.sldprt", "orientation": "front"}
)
Source code in src/solidworks_mcp/adapters/solidworks/io.py
create_part
async
¶
create_part(name: str | None = None, units: str | None = None, template: str | None = None) -> AdapterResult[SolidWorksModel]
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
|
Optional linear unit system for the new part - |
None
|
template
|
str | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksModel]
|
AdapterResult[SolidWorksModel]: Metadata for the new part document. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 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 | |
create_technical_drawing
async
¶
Lay out the three standard views of a model on the active sheet.
Wraps IDrawingDoc::Create3rdAngleViews2 (or
Create1stAngleViews2), which places front, top and side in one
call. Both return a bare boolean, so the view list before and after is
what actually confirms the views exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
Any
|
Tool payload. Reads |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The view names that appeared. |
Example::
await adapter.create_technical_drawing(
{"model_file": r"C:\parts\bracket.sldprt"}
)
Source code in src/solidworks_mcp/adapters/solidworks/io.py
3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 | |
get_application_info
async
¶
Read SolidWorks' revision, language and default templates.
Each value is read on its own, so one unreadable value is None
and the rest still come back. Templates are reported by file name
only, so no path under the user's profile leaves the adapter.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: See |
AdapterResult[dict[str, Any]]
|
|
Source code in src/solidworks_mcp/adapters/solidworks/io.py
get_dimension
async
¶
Read a named model dimension in the unit its type gives it.
IDimension.SystemValue is metres for a length, radians for an
angle and the number itself for a count; IDimension.GetType says
which (:func:_dimension_reading). GetValue3 is not used: it is
in the document's units, which this can't convert without reading
the document's unit system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Fully-qualified dimension name, e.g. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
"deg", or |
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
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 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 | |
get_model_geometry_summary
async
¶
Summarise the active part or assembly without rebuilding it.
Unlike get_mass_properties this never calls ForceRebuild3, so
it leaves the live selection intact (COM pitfall #23) and can be read
right before a feature call. A value that cannot be read is None.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: See |
AdapterResult[dict[str, Any]]
|
|
Source code in src/solidworks_mcp/adapters/solidworks/io.py
2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 | |
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
2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 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 | |
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
2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 | |
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
list_drawing_views
async
¶
List the views on the active drawing.
Returns:
| Type | Description |
|---|---|
AdapterResult[list[str]]
|
AdapterResult[list[str]]: View names, sheet formats excluded. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
list_open_documents
async
¶
Enumerate every document currently open in SolidWorks.
Read-only: uses ISldWorks::GetDocuments and does not touch the
active-document selection. Each entry carries title, path,
type (Part / Assembly / Drawing / Unknown) and
is_active.
Returns:
| Type | Description |
|---|---|
AdapterResult[list[dict[str, Any]]]
|
AdapterResult[list[dict[str, Any]]]: One entry per open document |
AdapterResult[list[dict[str, Any]]]
|
(possibly empty). |
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
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 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 | |
pack_and_go_assembly
async
¶
Copy an assembly and every file it uses into one folder.
SolidWorks lists the files (IModelDoc2.GetDependencies2) and each
is copied, as saved on disk, into target_dir under its own name.
The copy opens with its own parts: SolidWorks looks for a referenced
file in the assembly's folder before the stored path. (SolidWorks'
own Pack and Go, IPackAndGo, listed only the assembly on
SolidWorks 2026.) No document is closed or changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_path
|
str
|
The |
required |
target_dir
|
str
|
The folder to copy into; created if needed. A file already there with a copied file's name is replaced. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict]: |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
files open with changes the copy doesn't have). |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 | |
rebuild_model
async
¶
Force a rebuild and report exactly which features fail and why.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top_level_only
|
bool
|
Rebuild only the top level of an assembly. Defaults to False (full rebuild). |
False
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
carrying that |
AdapterResult[dict[str, Any]]
|
SolidWorks reports the rebuild itself failed. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 | |
save_body_as_part
async
¶
Extract one solid body from the active multibody part to a new file.
Wraps IFeatureManager::CreateSaveBodyFeature - the API behind
Insert > Features > Save Bodies. body_name is matched against
IPartDoc::GetBodies2(swSolidBody) by IBody2::Name; a Save
Bodies feature is added and the standalone part is written to
file_path. CreateSaveBodyFeature returns the feature (or
None) but no write status, so success is confirmed by the file
existing afterwards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
body_name
|
str
|
Name of a solid body in the active part. |
required |
file_path
|
str
|
Absolute path for the new |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The body, the written path, the new |
AdapterResult[dict[str, Any]]
|
feature's name, and every solid-body name found. |
AdapterResult[dict[str, Any]]
|
the active document is not a part, the body is absent, the parent |
AdapterResult[dict[str, Any]]
|
directory is missing, or no file was written. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 | |
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
1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 | |
set_component_state
async
¶
set_component_state(component: str, fixed: bool | None = None, flexible: bool | None = None) -> AdapterResult[dict[str, Any]]
Fix or float a component, and make a sub-assembly rigid or flexible.
Fixing selects the component and calls IAssemblyDoc::FixComponent
or UnfixComponent. Solving goes through
IAssemblyDoc::CompConfigProperties5, which also sets suppression,
visibility, configuration, BOM and envelope for the selected
component: each is read from the component first and passed back, so
only solving changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
str
|
Instance name, as |
required |
fixed
|
bool | None
|
True fixes it, False floats it. |
None
|
flexible
|
bool | None
|
True flexible, False rigid (sub-assemblies). |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The state before and after. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 | |
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
set_units
async
¶
Set the active document's linear unit system.
Accepts mm, cm, m, in or ft (plus common aliases
such as inch / millimeters). The choice is applied by setting
both swUnitSystem and the exact swUnitsLinear preference, then
reading the linear unit back - a mismatch is reported as an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit_system
|
str
|
The target unit token. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: What was applied and whether the |
AdapterResult[dict[str, Any]]
|
readback confirmed it. |
AdapterResult[dict[str, Any]]
|
the token is not recognised. |
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.
Methods:¶
get_selected_entities
async
¶
Report the faces/edges/vertices currently highlighted in the live SolidWorks UI, so an agent can see exactly what the user clicked on instead of guessing from a screenshot (see com-api-pitfalls.md #21 for why a screenshot alone is not reliable proof of document/view state).
Refreshes currentModel from swApp.ActiveDoc first, the same
way list_features does, since the user's selection lives on
whatever document is actually active in the UI right now -- which
may not be the document this adapter last created or touched.
Returns:
| Type | Description |
|---|---|
AdapterResult[list[dict[str, Any]]]
|
AdapterResult[list[dict[str, Any]]]: One entry per selected |
AdapterResult[list[dict[str, Any]]]
|
entity, each with at least |
AdapterResult[list[dict[str, Any]]]
|
( |
AdapterResult[list[dict[str, Any]]]
|
additionally carry |
AdapterResult[list[dict[str, Any]]]
|
|
AdapterResult[list[dict[str, Any]]]
|
|
AdapterResult[list[dict[str, Any]]]
|
(the true length of a curved edge will be longer). Vertices |
AdapterResult[list[dict[str, Any]]]
|
carry |
AdapterResult[list[dict[str, Any]]]
|
omitted rather than failing the whole call -- a partial |
AdapterResult[list[dict[str, Any]]]
|
description is more useful than none. |
Source code in src/solidworks_mcp/adapters/solidworks/selection.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
select_face_edges
async
¶
select_face_edges(point: list[float] | None = None, side: str | None = None, plane: str | None = None, edge_type: str = 'all', append: bool = False) -> AdapterResult[dict[str, Any]]
Multi-select every edge bounding one face of the active part.
See SolidWorksAdapter.select_face_edges for the contract; the face
resolution and selection live in face_selection.FaceEdgeSelector.
Source code in src/solidworks_mcp/adapters/solidworks/selection.py
select_feature
async
¶
Select a named feature, sketch, plane or component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature_name
|
str
|
Feature name, optionally |
required |
append
|
bool
|
Add to the current selection instead of replacing it. |
False
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The selector payload plus |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
|
Source code in src/solidworks_mcp/adapters/solidworks/selection.py
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.
- Show the application window (hidden instead when
SOLIDWORKS_MCP_HEADLESSis set). - 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 the feature-selection strategies in order; first success wins.
Order: FeatureByName (cheapest, proven live), SelectByID2
over candidate names x entity types (planes, mates), component
selection (assemblies), then a feature-tree walk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature_name
|
str
|
Feature name requested by caller. |
required |
append
|
bool
|
Add to the current selection. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Selection payload; |
dict[str, Any]
|
every strategy failed (the adapter maps that to an ERROR). |
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, append: bool = False) -> 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 |
append
|
bool
|
Add to the current selection. Defaults to False. |
False
|
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
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 1286 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 | |
try_select_by_extension ¶
try_select_by_extension(target_doc: Any, candidate_names: list[str], feature_name: str, append: bool = False) -> 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 |
append
|
bool
|
Add to the current selection. Defaults to False. |
False
|
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_name ¶
try_select_by_feature_name(target_doc: Any, feature_name: str, append: bool = False) -> dict[str, Any] | None
Select via FeatureByName + IFeature::Select2 (first strategy).
Delegates to the shared features._select_feature_by_name helper -
the path suppress/rename already rely on, and the one confirmed live
on R2026x for solid features, sketches and reference planes. It does
not resolve assembly components, which fall through to
:meth:try_select_by_component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_doc
|
Any
|
SolidWorks |
required |
feature_name
|
str
|
Feature name; any |
required |
append
|
bool
|
Add to the current selection. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
dict[str, Any] | None: Success payload (same schema as |
dict[str, Any] | None
|
meth: |
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], append: bool = False) -> 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 |
append
|
bool
|
Add to the current selection. Defaults to False. |
False
|
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
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 | |
_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:¶
_byref_int ¶
Return a byref long VARIANT for a SolidWorks out-parameter.
See :func:_byref_bstr for why pythoncom.Missing does not work.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
A |
Any
|
unavailable (test/mock environments). |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_byref_long ¶
Return a VT_BYREF | VT_I4 VARIANT for a SolidWorks ByRef Long
out-parameter.
pywin32 late binding will not marshal a plain Python int into a
ByRef Long argument - the call fails with DISP_E_TYPEMISMATCH
(0x80020005). RunMacro2's trailing nRetval needs the same
treatment as OpenDoc6's errors/warnings (issue #91).
Falls back to initial (a plain int) when pywin32 is unavailable so
the mock/CI test path keeps working.
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
_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
_headless_requested ¶
True when SOLIDWORKS_MCP_HEADLESS asks the SW window to stay hidden.
Off by default - a normal MCP session keeps the SolidWorks window visible.
The live test suite sets it so connect() does not re-show the window on
every per-test reconnect (each show/hide is a full window relayout).
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
_null_callout ¶
Return a VT_DISPATCH null for SelectByID2's Callout parameter.
A plain Python None marshals as VT_NULL, which SolidWorks rejects
with DISP_E_TYPEMISMATCH - measured as
(-2147352571, 'Type mismatch.', None, 8). See runbook item 11.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
A |
Any
|
when pywin32 is unavailable (mock/Linux runs, where no real COM call |
|
Any
|
will be made anyway, but the value must still never be bare |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_parse_vb_module_name ¶
Resolve the VB module name RunMacro2 needs for a macro file.
RunMacro2(path, ModuleName, ProcedureName, ...) fails with
swRunMacroError_Invalidindex (22) when ModuleName does not match a
module in the project, so the guess matters:
- A real
.swpauthored by SOLIDWORKS is an OLE compound file. Its plaintextPROJECTstream carriesModule=<name>, and SW names that module<stem>1(sample_macro->sample_macro1) - the file stem is the wrong guess. Read the real name out of the raw bytes. - A hand-written text macro carries
Attribute VB_Name = "...". - Otherwise fall back to the file stem, then
"SolidWorksMacro"(the name the macro recorder uses).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
macro_path
|
str
|
The macro path value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The resulting text value. |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
_run_macro_error_name ¶
Render a swRunMacroError_e code as "<n> (<Name>)" when known.
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
_select_feature_by_name ¶
Select a feature or sketch by name and return it.
Resolves the entity with IModelDoc2::FeatureByName and selects it with
IFeature::Select2(append, 0) - the same path used elsewhere in this
adapter. SelectByID2 is avoided here because it needs an entity-type
string that differs between sketches and solid features, and because its
Callout argument raises Type mismatch unless passed an explicit
VT_DISPATCH null. Any name@document qualifier is stripped first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
name
|
str
|
Feature or sketch name, e.g. |
required |
append
|
bool
|
Add to the current selection instead of clearing it first. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The selected |
Any
|
could not be selected. |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_settle_after ¶
Pause after a COM operation so SolidWorks can finish its UI work.
SolidWorks does part of each operation's work later, in its idle loop
(CommandManager/task-pane refresh). Firing the next call while that is in
progress re-enters it, and SolidWorks 2026 crashed there repeatedly under
back-to-back API calls (COM pitfall #26). A human never drives it that
fast. Tunable via SOLIDWORKS_MCP_COM_SETTLE_SECONDS (every operation)
and SOLIDWORKS_MCP_DOC_SETTLE_SECONDS (document open/create/close).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operation_name
|
str
|
The |
required |
Source code in src/solidworks_mcp/adapters/pywin32_adapter.py
_settle_seconds ¶
Read a non-negative settle pause from the environment.