solidworks_mcp.adapters.solidworks.io¶
solidworks_mcp.adapters.solidworks.io ¶
Model I/O mixin for PyWin32 SolidWorks operations.
Attributes¶
_DOC_TYPE_NAMES
module-attribute
¶
_EXTREME_DIRECTIONS
module-attribute
¶
_EXTREME_DIRECTIONS = ((0, False, (-1.0, 0.0, 0.0)), (0, True, (1.0, 0.0, 0.0)), (1, False, (0.0, -1.0, 0.0)), (1, True, (0.0, 1.0, 0.0)), (2, False, (0.0, 0.0, -1.0)), (2, True, (0.0, 0.0, 1.0)))
_FEATURE_WALK_MEMBERS
module-attribute
¶
_FEATURE_WALK_MEMBERS = ('GetTypeName2', 'GetNextFeature', 'GetFirstSubFeature', 'GetNextSubFeature', 'IsSuppressed')
_MATE_ALIGNMENTS
module-attribute
¶
_MATE_TYPES
module-attribute
¶
_MATE_TYPES: dict[str, int] = {'coincident': 0, 'concentric': 1, 'perpendicular': 2, 'parallel': 3, 'tangent': 4, 'distance': 5, 'angle': 6}
_NAMED_VIEWS
module-attribute
¶
_NAMED_VIEWS: dict[str, str] = {'front': '*Front', 'back': '*Back', 'left': '*Left', 'right': '*Right', 'top': '*Top', 'bottom': '*Bottom', 'isometric': '*Isometric', 'iso': '*Isometric', 'trimetric': '*Trimetric', 'dimetric': '*Dimetric', 'current': '*Current'}
_SW_DEFAULT_TEMPLATES
module-attribute
¶
_SW_UNIT_ALIASES
module-attribute
¶
_SW_UNIT_ALIASES: dict[str, str] = {'mm': 'mm', 'millimeter': 'mm', 'millimeters': 'mm', 'millimetre': 'mm', 'millimetres': 'mm', 'cm': 'cm', 'centimeter': 'cm', 'centimeters': 'cm', 'm': 'm', 'meter': 'm', 'meters': 'm', 'metre': 'm', 'metres': 'm', 'in': 'in', 'inch': 'in', 'inches': 'in', '"': 'in', 'ft': 'ft', 'foot': 'ft', 'feet': 'ft', "'": 'ft'}
_SW_UNIT_SYSTEMS
module-attribute
¶
_SW_UNIT_SYSTEMS: dict[str, tuple[int, int]] = {'mm': (5, 0), 'cm': (1, 1), 'm': (2, 2), 'in': (3, 3), 'ft': (4, 4)}
Classes¶
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. |
MassProperties ¶
Bases: BaseModel
Mass properties information.
Attributes:
| Name | Type | Description |
|---|---|---|
center_of_mass |
list[float]
|
The center of mass value. |
mass |
float
|
The mass value. |
moments_of_inertia |
dict[str, float]
|
The moments of inertia value. |
principal_axes |
dict[str, list[float]] | None
|
The principal axes value. |
surface_area |
float
|
The surface area value. |
volume |
float
|
The volume value. |
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
SolidWorksModel ¶
Bases: BaseModel
SolidWorks model information.
Attributes:
| Name | Type | Description |
|---|---|---|
configuration |
str | None
|
The configuration value. |
is_active |
bool
|
The is active value. |
name |
str
|
The name value. |
path |
str
|
The path value. |
properties |
dict[str, Any] | None
|
The properties value. |
type |
str
|
The type value. |
_ByrefFallback ¶
Stand-in for a byref VARIANT when pywin32 is unavailable.
The callers' contract for a byref holder is "an object whose .value
the COM call fills in". Returning a bare 0 or "" broke that: on any
machine without pywin32 (Linux CI, mock runs) _read_material_name could
never read its database out-parameter back, so it silently reported
None. This keeps the contract on both platforms.
Source code in src/solidworks_mcp/adapters/solidworks/io.py
Functions:¶
_apply_unit_system ¶
Set a document's linear unit system and confirm it actually took.
IModelDocExtension::SetUserPreferenceInteger accepts the
swUnitSystem write and returns quietly even on builds where the
document's unit system does not move (observed on SW 2026 / 3DEXPERIENCE
against an assembly). The change is therefore verified by reading the
unit-system preference itself (swUnitSystem = slot 263) back after
a rebuild - not the swUnitsLinear slot, which echoes whatever was
written regardless of whether the document honoured it.
For the mm / cm / m / in presets only swUnitSystem is
set and the preset drives the linear unit. ft has no preset, so it is
applied as swUnitSystem_Custom plus an explicit swUnitsLinear.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter. |
required |
model
|
Any
|
The |
required |
unit_system
|
str
|
Already-normalised token (key of |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
reports afterwards); |
dict[str, Any]
|
and |
dict[str, Any]
|
preference now equals the target; |
Raises:
| Type | Description |
|---|---|
Exception
|
When the extension is unavailable, or the readback shows the document did not adopt the requested unit system. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 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 | |
_as_com ¶
Wrap a raw dispatch and flag its methods for an interface.
Objects handed back inside arrays (GetViews and friends) arrive as raw
PyIDispatch. Method flagging is a no-op on those, so every call
against them raises until they are wrapped through dynamic.Dispatch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
obj
|
Any
|
The raw dispatch. |
required |
interface
|
str
|
Interface name, e.g. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The wrapped, flagged object, or |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_assembly_mate_count ¶
Find the MateGroup feature and count its mates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
model
|
Any
|
The active assembly |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The mate count ( |
int | None
|
|
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_bodies_volume_mm3 ¶
Sum the solid bodies' volumes, independent of the selection.
IModelDocExtension.CreateMassProperty computes for the current
selection and returns no volume while a sketch or plane is selected,
which is the state a feature call runs in. IBody2.GetMassProperties
reads each body directly; element 3 of its array is the volume in m³.
The density argument only affects mass, which is not used here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
bodies
|
list[Any] | None
|
Wrapped |
required |
Returns:
| Type | Description |
|---|---|
float | None
|
float | None: Volume in mm³ ( |
float | None
|
the bodies or any body's volume could not be read. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_box_from_metres ¶
Turn a SolidWorks [x1, y1, z1, x2, y2, z2] box in metres into mm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
Any
|
The six-value box, or anything else. |
required |
method
|
str
|
How the box was measured, reported back to the caller. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
dict[str, Any] | None: |
dict[str, Any] | None
|
or |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_byref_bool ¶
Return a byref bool VARIANT (e.g. IFeature::GetErrorCode2(IsWarning)).
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The byref VARIANT, or a |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_byref_bstr ¶
Return a byref string VARIANT for a SolidWorks String out-parameter.
Under forced late binding an omitted out-parameter raises "Parameter not
optional", and pythoncom.Missing cannot be converted to a COM VARIANT,
so pass VARIANT(VT_BYREF | VT_BSTR, "") and read .value afterwards
(e.g. IPartDoc::GetMaterialPropertyName2's Database; confirmed live
on R2026x).
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The byref VARIANT, or a |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_byref_double ¶
Return a byref double VARIANT for a SolidWorks Double out-parameter.
IBody2::GetExtremePoint reports its point through three of these. See
:func:_byref_bstr for why pythoncom.Missing does not work.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
A |
Any
|
without pywin32. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_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_variant ¶
Return a byref VARIANT for an array/variant out-parameter.
IModelDocExtension::GetWhatsWrong fills three of these (features,
error codes, warning flags); confirmed live on R2026x that late binding
accepts VARIANT(VT_BYREF | VT_VARIANT, None) and exposes the result on
.value. pythoncom.Missing is rejected ("can not be converted to a
COM VARIANT").
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The byref VARIANT, or a |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_coerce_dispatch_sequence ¶
Normalise ISldWorks::GetDocuments output into a list of dispatches.
Depending on the SolidWorks build and how many documents are open,
GetDocuments returns None, a single IModelDoc2, or a
tuple/list of them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
Any
|
Whatever |
required |
Returns:
| Type | Description |
|---|---|
list[Any]
|
list[Any]: Zero or more non- |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_component_names ¶
Return the names of an assembly's top-level components.
AddComponent* can return an object having added nothing, so the
component list is the ground truth for whether an insert worked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
assembly
|
Any
|
The assembly document, flagged for |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: Component names, empty when the assembly holds none. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_component_pairs ¶
Return an assembly's top-level components as (name, dispatch).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
assembly
|
Any
|
The assembly document, flagged for |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[str, Any]]
|
list[tuple[str, Any]]: Component name and its |
list[tuple[str, Any]]
|
dispatch. A component whose dispatch cannot be wrapped is reported |
list[tuple[str, Any]]
|
as |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_component_state ¶
Read what CompConfigProperties5 sets, plus whether it is fixed.
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_component_transforms ¶
Snapshot every component's placement, for before/after comparison.
IComponent2.Transform2 is the component's position relative to the
assembly root, as a MathTransform whose ArrayData is 16 doubles
(a 3x3 rotation, a translation, and a scale). Comparing the snapshot
before and after a mate is what distinguishes a mate that actually
positioned geometry from one that SolidWorks accepted and ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
assembly
|
Any
|
The |
required |
Returns:
| Type | Description |
|---|---|
dict[str, tuple[float, ...]]
|
dict[str, tuple[float, ...]]: Component name to transform matrix. |
dict[str, tuple[float, ...]]
|
Components whose transform cannot be read are omitted rather than |
dict[str, tuple[float, ...]]
|
recorded as unchanged — an unreadable transform is not evidence of |
dict[str, tuple[float, ...]]
|
anything, and treating it as "same" would fake a passing comparison. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_count_mates ¶
Count the unsuppressed mates under the assembly's mate group.
Mates are sub-features whose type name starts with Mate; a mate
folder (any ...Folder type) is entered one level deep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
mate_group
|
Any
|
The |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The number of unsuppressed mates. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_describe_open_document ¶
_describe_open_document(adapter: Any, doc: Any, active_title: str | None, active_path: str | None) -> dict[str, Any]
Summarise one open document: title, path, type and whether it is active.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter (for |
required |
doc
|
Any
|
An |
required |
active_title
|
str | None
|
Title of |
required |
active_path
|
str | None
|
Path of |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_dimension_reading ¶
A dimension's value in the unit its type gives it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
Any
|
|
required |
system_value
|
float
|
|
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: |
dict[str, Any]
|
an angle, and the number with |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_doc_type ¶
Return the active document's type: 1 part, 2 assembly, 3 drawing.
GetType is one of the members pywin32 late binding may expose as either
a bound method or a plain value, so calling it directly returns None on
some documents. _get_attr_or_call handles both shapes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The document type, or |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_extreme_point_box ¶
Tight bounding box from each body's six extreme points.
GetPartBox can be loose on curved faces; GetExtremePoint returns
the actual farthest point of the body in a direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
bodies
|
list[Any]
|
Wrapped |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
dict[str, Any] | None: The box, or |
dict[str, Any] | None
|
or any extreme point could not be read. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_files_to_pack ¶
The assembly and each file it uses, checked before anything is copied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Path
|
The assembly. |
required |
dependencies
|
list[Path]
|
The files |
required |
out_dir
|
Path
|
The folder they are copied into, under their own names. |
required |
Returns:
| Type | Description |
|---|---|
list[Path]
|
list[Path]: The assembly first, then each dependency once. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
A file is not on disk. |
ValueError
|
Two files share a name (renaming one would break the
reference to it), or |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_find_components ¶
The named top-level components of assembly, as IComponent2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
The connected adapter. |
required |
assembly
|
Any
|
The |
required |
names
|
list[str]
|
Instance names, e.g. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Name to wrapped component, one per name. |
Raises:
| Type | Description |
|---|---|
Exception
|
When the components can't be read, or a name isn't there (the message lists what the assembly holds). |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_first ¶
Return the first key present and not None.
The drawing tools disagree on field names for the same thing — a model is
model_path on one schema and model_file on another — so each
adapter method accepts every spelling its callers use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict[str, Any]
|
The tool payload. |
required |
*keys
|
str
|
Candidate key names, in priority order. |
()
|
default
|
Any
|
Returned when no key is present. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The first value found, otherwise |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_interference_details ¶
Describe each interference: the components involved and the overlap.
IInterference::Volume is in cubic metres and is converted to mm^3 to
match every other volume this adapter reports.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
interferences
|
Any
|
The sequence returned by |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: One entry per interference. Empty when the |
list[dict[str, Any]]
|
sequence is absent, which is what SolidWorks returns for a clean |
list[dict[str, Any]]
|
assembly. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_model_volume_mm3 ¶
Read the model's volume without forcing a rebuild.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
model
|
Any
|
The active |
required |
Returns:
| Type | Description |
|---|---|
float | None
|
float | None: Volume in mm³, or |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_normalise_unit_system ¶
Map a user-supplied unit token onto a canonical key of _SW_UNIT_SYSTEMS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit_system
|
str
|
e.g. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: |
str | None
|
the token is not recognised. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_open_or_find_assembly ¶
Open the assembly, or use it when it is already open; never close anything.
OpenDoc6 returns nothing for a file that can't be opened, including
when a document with the same file name is already open. The assembly
itself, if open, is found by its path (ISldWorks.GetOpenDocumentByName)
and used as it is, unsaved changes included.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter. |
required |
source
|
Path
|
The assembly file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The assembly's |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
When it can neither be opened nor found open. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_payload ¶
Coerce a tool payload into a plain dict.
The drawing tools hand the adapter either a model_dump() result or a
raw dict, depending on the tool. Accept a Pydantic model too, so a direct
adapter call from a test or script behaves the same as one through a tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
A dict, a Pydantic model, or an object with attributes. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: The payload as a dict; empty when nothing was given. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_payload_dict ¶
Coerce a tool payload into a plain dict.
tools/analysis.py hands the adapter input_data.model_dump(), but a
direct call from a test or script may pass the model itself or nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
A dict, a Pydantic model, or |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: The payload as a dict; empty when nothing was given. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_pref_int ¶
Read one IModelDocExtension integer user preference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter (for |
required |
ext
|
Any
|
The document's |
required |
pref
|
int
|
A |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The preference value, or |
int | None
|
fails or returns a non-numeric result. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_resolve_drawing_view ¶
Return the IView on the active drawing whose name matches.
Walks IDrawingDoc::GetViews (a list of sheets, each shaped
(sheet, view, view, ...)) the same way :func:_view_names does. The
match is case-insensitive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
drawing
|
Any
|
The drawing document, flagged for |
required |
view_name
|
str
|
The drawing-view name to look for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The flagged |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_select_component_face ¶
_select_component_face(adapter: Any, model: Any, component: Any, component_name: str, point: list[float], append: bool) -> None
Select the face of component at point (its part coordinates, mm).
Only that component's faces are searched, so coincident surfaces of two parts (a pin in its hole) can't be confused.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
The connected adapter. |
required |
model
|
Any
|
The active assembly document. |
required |
component
|
Any
|
The |
required |
component_name
|
str
|
Its instance name, for messages. |
required |
point
|
list[float]
|
|
required |
append
|
bool
|
Add to the current selection. |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
When no face of the component lies at the point, or it won't select. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_solid_bodies ¶
Return the part's solid bodies as wrapped IBody2 dispatches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
part
|
Any
|
The part document, flagged for |
required |
Returns:
| Type | Description |
|---|---|
list[Any] | None
|
list[Any] | None: The bodies (possibly empty), or |
list[Any] | None
|
|
list[Any] | None
|
answers null rather than an empty array, so null without an error |
list[Any] | None
|
is an empty list. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_sub_features ¶
Return a feature's sub-features, each flagged for the tree walk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
parent
|
Any
|
The parent |
required |
Returns:
| Type | Description |
|---|---|
list[Any]
|
list[Any]: The sub-features in tree order. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_variant_array ¶
Wrap a Python sequence as a SAFEARRAY VARIANT for a SolidWorks call.
pywin32 late binding otherwise unpacks a bare list into positional
arguments, so SolidWorks array parameters (CreateSaveBodyFeature's
bodies/paths, sketch entity lists, ...) need a single VT_ARRAY
VARIANT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element_vt
|
int
|
The element type flag, e.g. |
required |
values
|
Any
|
The sequence of elements. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
|
Any
|
list when pywin32 is unavailable (test/mock environments). |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_view_names ¶
Return the drawing's view names, excluding sheet formats.
CreateDrawViewFromModelView3 returns None for a model SolidWorks
could not resolve, and Create3rdAngleViews2 returns a bare boolean, so
the view list is the ground truth for whether views were really added.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
drawing
|
Any
|
The drawing document, flagged for |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: View names in sheet order. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
dependency_paths ¶
The model files in a GetDependencies2 reply, each once, in order.
IModelDoc2.GetDependencies2 returns a flat array that alternates a
document's name and its full path. Only full paths to SolidWorks model
files are kept; a repeated path (compared as Windows does, ignoring case)
is kept once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_dependencies
|
Any
|
The reply; anything other than a list or tuple gives no paths. |
required |
Returns:
| Type | Description |
|---|---|
list[Path]
|
list[Path]: The absolute model-file paths. |
Source code in src/solidworks_mcp/utils/sw_dependencies.py
mate_entity_label ¶
How a mate's reply names one side: the entity, or the face point.
Shared by the live and mock adapters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
str
|
The named entity (used when no face is given). |
required |
face
|
list[float] | None
|
A point on a face, in part coordinates (mm). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
e.g. |