solidworks_mcp.adapters.solidworks.features¶
solidworks_mcp.adapters.solidworks.features ¶
Feature-domain mixin for PyWin32 SolidWorks operations.
Attributes¶
_AXIS_PLANE_PAIRS
module-attribute
¶
_AXIS_PLANE_PAIRS: dict[str, tuple[str, str]] = {'x': ('Top Plane', 'Front Plane'), 'y': ('Front Plane', 'Right Plane'), 'z': ('Top Plane', 'Right Plane')}
_TREE_WALK_MEMBERS
module-attribute
¶
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)
Bases: Generic[T]
Result wrapper for adapter operations.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
T | None
|
The data value. |
error |
str | None
|
The error value. |
execution_time |
float | None
|
The execution time value. |
metadata |
dict[str, Any] | None
|
The metadata value. |
status |
AdapterResultStatus
|
The status value. |
AdapterResultStatus ¶
Bases: StrEnum
Result status for adapter operations.
Attributes:
| Name | Type | Description |
|---|---|---|
ERROR |
Any
|
The error value. |
SUCCESS |
Any
|
The success value. |
TIMEOUT |
Any
|
The timeout value. |
WARNING |
Any
|
The warning value. |
ExtrusionParameters ¶
Bases: BaseModel
Parameters for extrusion operations.
Attributes:
| Name | Type | Description |
|---|---|---|
auto_select |
bool
|
The auto select value. |
both_directions |
bool
|
The both directions value. |
depth |
float
|
The depth value. |
draft_angle |
float
|
The draft angle value. |
end_condition |
str
|
The end condition value. |
feature_scope |
bool
|
The feature scope value. |
merge_result |
bool
|
The merge result value. |
reverse_direction |
bool
|
The reverse direction value. |
sketch_name |
str | None
|
Explicit sketch to operate on. When set, callers (e.g. create_cut_extrude) must select exactly this sketch and fail with a clear error if it doesn't exist rather than silently falling back to some other sketch. |
thin_feature |
bool
|
The thin feature value. |
thin_thickness |
float | None
|
The thin thickness value. |
up_to_surface |
str | None
|
The up to surface value. |
LoftParameters ¶
Bases: BaseModel
Parameters for loft operations.
Attributes:
| Name | Type | Description |
|---|---|---|
end_tangent |
str | None
|
The end tangent value. |
guide_curves |
list[str] | None
|
The guide curves value. |
merge_result |
bool
|
The merge result value. |
profiles |
list[str]
|
The profiles value. |
start_tangent |
str | None
|
The start tangent value. |
RevolveParameters ¶
Bases: BaseModel
Parameters for revolve operations.
Attributes:
| Name | Type | Description |
|---|---|---|
angle |
float
|
The angle value. |
both_directions |
bool
|
The both directions value. |
merge_result |
bool
|
The merge result value. |
reverse_direction |
bool
|
The reverse direction value. |
thin_feature |
bool
|
The thin feature value. |
thin_thickness |
float | None
|
The thin thickness value. |
SolidWorksFeature ¶
Bases: BaseModel
SolidWorks feature information.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str | None
|
The id value. |
name |
str
|
The name value. |
parameters |
dict[str, Any] | None
|
The parameters value. |
parent |
str | None
|
The parent value. |
properties |
dict[str, Any] | None
|
The properties value. |
type |
str
|
The type value. |
SolidWorksFeaturesMixin ¶
Expose SolidWorks feature methods via mixin-local implementation helpers.
Methods:¶
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
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 grow. 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 and after. |
AdapterResult[dict[str, Any]]
|
failed, or the volume did not grow. |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
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 282 283 284 285 286 287 288 289 290 291 | |
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 rises by less than count - 1 times the
seed. That is correct behaviour, not a failure - only no growth at
all means the pattern did nothing.
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 and after. |
AdapterResult[dict[str, Any]]
|
volume did not grow. |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
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
SweepParameters ¶
Bases: BaseModel
Parameters for sweep operations.
Attributes:
| Name | Type | Description |
|---|---|---|
merge_result |
bool
|
The merge result value. |
path |
str
|
The path value. |
twist_along_path |
bool
|
The twist along path value. |
twist_angle |
float
|
The twist angle value. |
_NullCalloutSentinel ¶
Stand-in for VARIANT(VT_DISPATCH, None) when pywin32 is absent.
Never passed to a real COM call (if pywin32 isn't importable, no live
SolidWorks call can happen either), but must still be distinguishable
from a bare None so callers can't accidentally regress to passing
plain None as SelectByID2's Callout argument.
Functions:¶
_add_chamfer_impl ¶
_add_chamfer_impl(adapter: Any, distance: float, edge_names: list[str]) -> AdapterResult[SolidWorksFeature]
Create an equal-distance chamfer on one or more named edges.
Each edge in edge_names is selected by name using
Extension.SelectByID2 with entity type "EDGE". After all edges
are in the selection set, IFeatureManager::InsertFeatureChamfer is
called in equal-distance mode (type 1). A version-gated
IModelDoc2::FeatureChamferType path was tried for SW 2025+ but
live-verified to silently create an empty, zero-volume feature -- see
the comment at its call site for how this was confirmed and why
InsertFeatureChamfer is used unconditionally instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A fully connected |
required |
distance
|
float
|
Chamfer distance in millimetres. Converted to metres internally. |
required |
edge_names
|
list[str]
|
List of SolidWorks edge entity names, e.g.
|
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksFeature]
|
AdapterResult[SolidWorksFeature]: On success, |
AdapterResult[SolidWorksFeature]
|
|
AdapterResult[SolidWorksFeature]
|
|
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Example::
result = pywin32_feature_ops.add_chamfer(
adapter, distance=2.0, edge_names=["Edge<2>"]
)
print(result.data.name) # e.g. "Chamfer1"
Source code in src/solidworks_mcp/adapters/solidworks/features.py
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 | |
_add_fillet_impl ¶
_add_fillet_impl(adapter: Any, radius: float, edge_names: list[str]) -> AdapterResult[SolidWorksFeature]
Create a constant-radius fillet on one or more named edges.
Each edge in edge_names is selected by name using
Extension.SelectByID2 with entity type "EDGE". After all edges
are in the selection set, FeatureFillet3 is called to build the
feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A fully connected |
required |
radius
|
float
|
Fillet radius in millimetres. Converted to metres internally before the COM call. |
required |
edge_names
|
list[str]
|
List of SolidWorks edge entity names to fillet, e.g.
|
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksFeature]
|
AdapterResult[SolidWorksFeature]: On success, |
AdapterResult[SolidWorksFeature]
|
|
AdapterResult[SolidWorksFeature]
|
|
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Example::
result = pywin32_feature_ops.add_fillet(
adapter, radius=3.0, edge_names=["Edge<1>", "Edge<3>"]
)
print(result.data.name) # e.g. "Fillet1"
Source code in src/solidworks_mcp/adapters/solidworks/features.py
1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 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 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 | |
_create_axis_impl ¶
Create a reference axis along a principal direction.
Wraps IModelDoc2::InsertAxis2(AutoSize) - note the interface: it is on
IModelDoc2, not IFeatureManager. It builds an axis from two
selected planes, so an axis is requested by naming the direction and the
matching plane pair is selected here.
InsertAxis2 returns a plain boolean rather than the axis, so success is
confirmed by the feature count rising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
reference
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The planes used and how the tree |
AdapterResult[dict[str, Any]]
|
changed. |
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 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 | |
_create_cut_extrude_impl ¶
_create_cut_extrude_impl(adapter: Any, params: ExtrusionParameters) -> AdapterResult[SolidWorksFeature]
Create a cut-extrude feature from an explicit or unambiguously-tracked sketch.
Sketch resolution never guesses:
params.sketch_name, if given, is matched (case-insensitively) against the live feature tree via :func:_profile_feature_names. No match -> immediate error listing the sketches that do exist. No COM cut is attempted.- Otherwise,
adapter._last_sketch_name(set by the most recentcreate_sketch/exit_sketchcall in this session) is used only if it also matches a real name in the current tree — this catches the case wherecreate_sketchhad to fall back to a syntheticSketch_Nguess (SolidWorks didn't hand back a usable sketch object synchronously) and that guess doesn't correspond to anything real. - Otherwise: immediate error asking the caller to pass
sketch_nameexplicitly, listing available sketches. There is no third guess (no "most recentProfileFeaturein the tree", no blindSketch<N>enumeration) — a wrong silent guess would cut the wrong profile.
Once resolved, the sketch is explicitly selected via SelectByID2
before any FeatureCut call — SolidWorks' own "implicit" active-sketch
state (whatever was last open before this call) is never relied upon,
since that is exactly the racy behavior that made this feature
intermittently cut nothing.
Two COM API variants are attempted in order of preference:
FeatureCut4— most modern (SolidWorks 2015+).FeatureCut3— SolidWorks 2010–2014, and any install lackingFeatureCut4. Same 26-parameter order asFeatureCut4minus the trailingOptimizeGeometryargument (confirmed against SolidWorks API help and live macro examples — there is no separate "legacy" argument order; an earlier version of this fallback invented one and it always raisedDISP_E_PARAMNOTOPTIONALbecause it was missing theNormalCutargument and hadD2missing entirely).
All depth values are in millimetres and converted to metres internally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A fully connected |
required |
params
|
ExtrusionParameters
|
Extrusion parameter bag reused for cut parameters:
- |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksFeature]
|
AdapterResult[SolidWorksFeature]: On success, |
AdapterResult[SolidWorksFeature]
|
|
AdapterResult[SolidWorksFeature]
|
failure, |
AdapterResult[SolidWorksFeature]
|
which stage failed: sketch-not-found (with the list of sketches that |
AdapterResult[SolidWorksFeature]
|
do exist), sketch-selection-failed (the resolved name plus why |
AdapterResult[SolidWorksFeature]
|
|
AdapterResult[SolidWorksFeature]
|
own error text — and, when every COM call returned falsy without |
AdapterResult[SolidWorksFeature]
|
raising at all, an explicit note that the profile likely isn't a |
AdapterResult[SolidWorksFeature]
|
valid closed loop intersecting solid geometry, rather than a bare |
AdapterResult[SolidWorksFeature]
|
"failed" with no diagnostic content. |
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Example::
from solidworks_mcp.adapters.base import ExtrusionParameters
from solidworks_mcp.adapters import pywin32_feature_ops
params = ExtrusionParameters(depth=10.0, end_condition="ThroughAll")
result = pywin32_feature_ops.create_cut_extrude(adapter, params)
print(result.data.name) # e.g. "Cut-Extrude1"
Source code in src/solidworks_mcp/adapters/solidworks/features.py
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 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 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 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 1521 1522 | |
_create_extrusion_impl ¶
_create_extrusion_impl(adapter: Any, params: ExtrusionParameters) -> AdapterResult[SolidWorksFeature]
Create a boss-extrude feature from the active sketch profile.
Attempts the modern FeatureExtrusion3 COM call first; falls back to the
legacy FeatureExtrusion2 signature when the newer overload is absent.
When params.thin_feature is truthy, the thin-wall variants
(FeatureExtrusionThin2 / FeatureExtruThin2) are used instead.
All depth and thickness values are provided in millimetres and converted to metres internally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A fully connected |
required |
params
|
ExtrusionParameters
|
Extrusion parameter bag. Relevant fields:
- |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksFeature]
|
AdapterResult[SolidWorksFeature]: On success, |
AdapterResult[SolidWorksFeature]
|
|
AdapterResult[SolidWorksFeature]
|
|
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Example::
from solidworks_mcp.adapters.base import ExtrusionParameters
from solidworks_mcp.adapters import pywin32_feature_ops
params = ExtrusionParameters(depth=25.0, draft_angle=2.0)
result = pywin32_feature_ops.create_extrusion(adapter, params)
print(result.data.name) # e.g. "Boss-Extrude1"
Source code in src/solidworks_mcp/adapters/solidworks/features.py
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 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 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 463 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 | |
_create_loft_impl ¶
Create a lofted boss/protrusion between two or more profile sketches.
Uses IFeatureManager::InsertProtrusionBlend2. Each profile named in
params.profiles is selected under mark 1 (in order — the selection
order determines the loft direction), and any params.guide_curves are
selected under mark 2. Because a solid is produced, every profile must be
a closed contour.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A fully connected |
required |
params
|
LoftParameters
|
Loft parameter bag. Relevant fields:
- |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksFeature]
|
AdapterResult[SolidWorksFeature]: On success, |
AdapterResult[SolidWorksFeature]
|
|
AdapterResult[SolidWorksFeature]
|
|
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Example::
from solidworks_mcp.adapters.base import LoftParameters
params = LoftParameters(profiles=["Sketch1", "Sketch2"])
result = await adapter.create_loft(params)
print(result.data.name) # e.g. "Loft1"
Source code in src/solidworks_mcp/adapters/solidworks/features.py
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 | |
_create_reference_plane_impl ¶
_create_reference_plane_impl(adapter: Any, reference: str, offset: float, angle: float, flip: bool) -> AdapterResult[dict[str, Any]]
Create a reference plane offset from, or angled to, an existing plane.
Wraps IFeatureManager::InsertRefPlane(FirstConstraint,
FirstConstraintAngleOrDistance, Second, 0, Third, 0). The reference
entity must be selected under mark 0 first, which is what the
SolidWorks documentation example does before the identical call.
This is what lets a sketch be opened anywhere other than the six built-in
planes. create_sketch already accepts a plane by its tree name, so the
name returned here can be passed straight to it - verified live: a plane
76.2 mm off the Front Plane came back as "Plane1", and a circle
sketched on it extruded to exactly the expected volume.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
reference
|
str
|
Name of the reference plane or planar face. |
required |
offset
|
float
|
Offset distance in millimetres, converted to metres. |
required |
angle
|
float
|
Angle in degrees; used instead of |
required |
flip
|
bool
|
Reverse the offset or angle direction. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The new plane's name and the parameters |
AdapterResult[dict[str, Any]]
|
used. |
AdapterResult[dict[str, Any]]
|
selected, or no plane was added to the tree. |
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Example::
plane = await adapter.create_reference_plane("Front Plane", offset=76.2)
await adapter.create_sketch(plane.data["name"])
Source code in src/solidworks_mcp/adapters/solidworks/features.py
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 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 | |
_create_reference_point_impl ¶
_create_reference_point_impl(adapter: Any, mode: str, x: float, y: float, z: float, distance: float | None, percent: float | None) -> AdapterResult[dict[str, Any]]
Create a reference point on the active part.
Two modes:
"along_curve"- selects the edge under the millimetre coordinate(x, y, z)and places a pointdistancemm, orpercent(0-100) of the edge length, from the edge start."face_center"- selects the face under(x, y, z)and places a point at its centroid.
Coordinate selection uses IModelDocExtension::SelectByID2; per this
repo's runbook a ForceRebuild3 is issued first so freshly created
edges are tessellated, and the Callout argument is passed an explicit
VT_DISPATCH null. InsertReferencePoint returns a Feature whether
or not it produced anything, so the feature count is compared before and
after.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
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 |
required |
percent
|
float | None
|
For |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The mode, the coordinate and resolved |
AdapterResult[dict[str, Any]]
|
parameter, and how the feature tree changed. |
AdapterResult[dict[str, Any]]
|
mode, a bad distance/percent combination, a failed selection, or when |
AdapterResult[dict[str, Any]]
|
no new feature appeared. |
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
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 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 | |
_create_revolve_impl ¶
Create a revolve feature from the active sketch profile around a centre axis.
Uses FeatureRevolve2 from the SolidWorks COM API. The sketch must
already contain a centre-line that SolidWorks will use as the rotation axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A fully connected |
required |
params
|
RevolveParameters
|
Revolve parameter bag. Relevant fields:
- |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksFeature]
|
AdapterResult[SolidWorksFeature]: On success, |
AdapterResult[SolidWorksFeature]
|
|
AdapterResult[SolidWorksFeature]
|
|
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Example::
from solidworks_mcp.adapters.base import RevolveParameters
from solidworks_mcp.adapters import pywin32_feature_ops
params = RevolveParameters(angle=360.0, merge_result=True)
result = pywin32_feature_ops.create_revolve(adapter, params)
print(result.data.name) # e.g. "Revolve1"
Source code in src/solidworks_mcp/adapters/solidworks/features.py
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 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 | |
_create_sweep_impl ¶
Create a swept boss/protrusion from a profile sketch along a path sketch.
Uses IFeatureManager::InsertProtrusionSwept4. Two sketches are
required in the active part: a closed profile sketch and an open
path sketch named by params.path. The path is selected under
mark 4 and the profile under mark 1, per the SolidWorks selection-mark
contract for sweeps.
Because :class:SweepParameters only names the path, the profile is
inferred as the first ProfileFeature sketch in the feature tree whose
name is not the path. In the common "draw profile, draw path, sweep"
workflow this is unambiguous (exactly two sketches exist).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A fully connected |
required |
params
|
SweepParameters
|
Sweep parameter bag. Relevant fields:
- |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksFeature]
|
AdapterResult[SolidWorksFeature]: On success, |
AdapterResult[SolidWorksFeature]
|
|
AdapterResult[SolidWorksFeature]
|
|
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Example::
from solidworks_mcp.adapters.base import SweepParameters
params = SweepParameters(path="Sketch2", merge_result=True)
result = await adapter.create_sweep(params)
print(result.data.name) # e.g. "Sweep1"
Source code in src/solidworks_mcp/adapters/solidworks/features.py
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 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 | |
_delete_feature_impl ¶
Delete a named feature or sketch from the active model.
Selects the feature, then removes it with IModelDoc2::EditDelete.
Deleting a parent also removes its children, which is SolidWorks' normal
cascade and the intended "erase this and what depends on it" behaviour -
so the number of features removed is reported, not assumed to be one.
EditDelete returns nothing useful, so success is confirmed by the
feature being absent from the tree afterwards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
name
|
str
|
Name of the feature or sketch to delete. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: What was deleted and how the tree |
AdapterResult[dict[str, Any]]
|
changed. |
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
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 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 | |
_feature_count ¶
Return how many features the active model has, or None.
Used to confirm an edit changed the tree rather than trusting a COM call that reports success without doing anything.
IFeatureManager::GetFeatureCount is used rather than walking
FirstFeature/GetNextFeature: the walk needs each dispatch flagged
for IFeature before Name and GetNextFeature resolve, and on
SW 2025 it still yields nothing, while the count is a single reliable
call. FeatureByPositionReverse was measured returning nothing usable
on the same document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The feature count, or |
int | None
|
which is deliberately distinct from |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_flag_feature_members ¶
Flag only the named members on obj.
Cheaper than :func:_flag_feature_methods inside a loop: flagging a
whole interface (IFeature is ~100 names, ~27 ms) costs a fixed price
per object, and sw_type_info's flag cache is keyed by id(obj), so
a walk over fresh dispatches — one per feature — never hits it. Flagging
just the handful of members about to be read avoids that cost.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
The COM object (or test double) to flag. |
required |
*names
|
str
|
Member names about to be read. |
()
|
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_flag_feature_methods ¶
Best-effort method flagging for a COM object via sw_type_info.
Flagging tells pywin32 late binding to resolve names like GetTypeName2
/ GetNextFeature / FirstFeature as methods. No-ops on plain test
doubles (and any environment without the gen_py wrapper).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
The COM object (or test double) to flag. |
required |
interface
|
str
|
SolidWorks interface name (e.g. |
required |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_is_suppressed ¶
Return a feature's suppression state, or None when unreadable.
None is deliberately distinct from False: it means the state could
not be read, which is not evidence that the feature is unsuppressed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter. |
required |
feature
|
Any
|
An |
required |
Returns:
| Type | Description |
|---|---|
bool | None
|
bool | None: |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_mirror_feature_impl ¶
_mirror_feature_impl(adapter: Any, features: list[str], mirror_plane: str, merge: bool, mirror_bodies: bool) -> AdapterResult[dict[str, Any]]
Select the sources and the plane, then call InsertMirrorFeature.
Wraps IFeatureManager::InsertMirrorFeature(BMirrorBody,
BGeometryPattern, BMerge, BKnit). There is no ...2 overload of this
call. Everything it acts on must be pre-selected under the right mark, so
the marks are the whole game - see _MIRROR_MARK_*.
Whether the mirror actually produced geometry is checked by the caller,
which can read volume through get_mass_properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
features
|
list[str]
|
Body or feature names to mirror. |
required |
mirror_plane
|
str
|
Plane name to mirror about. |
required |
merge
|
bool
|
Merge the result with the original. |
required |
mirror_bodies
|
bool
|
Select and mirror whole bodies rather than features. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The mirror feature's name and inputs. |
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
2802 2803 2804 2805 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 | |
_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
_offset_plane_distance ¶
Resolve an offset-plane Distance constraint to (distance_m, flip_bits).
IFeatureManager.InsertRefPlane's Distance constraint takes a positive
magnitude; the side of the base plane is chosen by the OptionFlip
bit, not by the sign of the distance. Passing a negative distance does
not place the plane on the opposite side - SolidWorks clamps it to 0,
collapsing the new plane onto the base. So a negative offset_mm must
be converted to a positive magnitude with the flip bit toggled relative
to the caller's flip request (a negative offset plus flip=True
cancel out).
Credit: this fix (and the pure-helper extraction for direct unit
coverage) ports the sign-resolution logic independently found and fixed
by contributor @pedropaulovc in their fork (commit 3c091fd). See
issue #84.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
offset_mm
|
float
|
Signed offset from the base plane, in millimetres. |
required |
base_flip
|
bool
|
Whether the caller requested |
required |
Returns:
| Type | Description |
|---|---|
float
|
tuple[float, int]: A non-negative distance in metres, and the flip |
int
|
bits ( |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_parse_edge_spec ¶
Parse an edge/face specification string into (name, x, y, z, entity_type).
Supports three formats:
- "Edge<1>" — name-based EDGE selection (x=y=z=0.0, SW looks up by
topology name)
- "x,y,z" — coordinate-based EDGE selection (name="", coordinate hint
in metres)
- "face:x,y,z" (case-insensitive prefix) — coordinate-based FACE
selection. Selecting a whole face and handing it to
InsertFeatureChamfer/FeatureFillet3 chamfers/fillets every
edge bounding that face in one call. This is more robust than
targeting a single edge by coordinate: a point exactly on a shared
boundary between two faces (e.g. a hole rim flush with the top
surface) can have its nearest-edge resolution silently shift to an
unrelated edge after another feature is added earlier in the tree,
picking a face interior point has no such ambiguity. Confirmed live
2026-09-18: an edge-coordinate hole-rim chamfer silently landed on
the block's 30mm outer edge instead (volume delta matched the
straight-edge formula, not the circular-rim one); selecting the face
instead reliably chamfers the real rim.
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_pattern_circular_impl ¶
_pattern_circular_impl(adapter: Any, features: list[str], axis: str, count: int, angle: float, equal_spacing: bool) -> AdapterResult[dict[str, Any]]
Select the axis and features, then call FeatureCircularPattern5.
This build exposes FeatureCircularPattern through ...5; v5 is used, with
the 14 arguments it declares. DName is a direction name string, so
the axis is both selected under mark 1 and named in the call.
Whether anything was produced is checked by the caller, which can read
volume through get_mass_properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
features
|
list[str]
|
Feature names to pattern. |
required |
axis
|
str
|
Axis name to rotate about. |
required |
count
|
int
|
Total instances including the original. |
required |
angle
|
float
|
Total spread in degrees. |
required |
equal_spacing
|
bool
|
Space instances evenly across |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The pattern's name and inputs. |
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
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 2992 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 | |
_profile_feature_names ¶
Return sketch (ProfileFeature) names in feature-tree order.
Walks FirstFeature -> GetNextFeature reading GetTypeName2 and
collecting features whose type is "ProfileFeature" (a 2D/3D sketch).
Mirrors the tree walk used by :func:_create_cut_extrude_impl, but flags
each feature for IFeature and reads members through
:func:_read_member so it is robust to pywin32's method-vs-property
late-binding ambiguity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: Bare sketch names, earliest first. Empty when the walk |
list[str]
|
finds no sketches or the tree is inaccessible. |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_read_member ¶
Read a COM member that pywin32 may expose as a property or a method.
Late-bound pywin32 dispatches are inconsistent: an unflagged zero-arg
accessor may come back as a bound method (needing a call) or as the
already-resolved value — and when that value is itself a COM object it is
also callable, so a naive "call if callable" check wrongly invokes its
default dispatch (Member not found). This helper calls the member and
falls back to the raw member if the call raises, so it yields the value in
every case (flagged method, unflagged method, property-returning-object,
or plain test double).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
The COM object (or test double) to read from. |
required |
name
|
str
|
Member name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The member's value, or |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_rename_feature_impl ¶
Rename a named feature in the active model.
IFeature::Name is a settable property, not a method - it is assigned
directly, never called (see the property-vs-method flagging note in the
COM threading section of CLAUDE.md). SolidWorks silently refuses a
rename onto a name another feature already uses, so a clash is checked
for first and the new name is read back afterwards; a mismatch is
reported as a failure rather than a quiet success.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
old_name
|
str
|
The feature's current name. Any |
required |
new_name
|
str
|
The name to give it. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
names are the same. |
AdapterResult[dict[str, Any]]
|
absent, the target name is taken, or the rename did not take. |
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 | |
_select_edge_by_coord ¶
_select_edge_by_coord(adapter: Any, x: float, y: float, z: float, append: bool, mark: int = 0, entity_type: str = 'EDGE') -> bool
Select the edge (or face) nearest to (x, y, z) in metres via SelectByID2.
Calls ForceRebuild3 on the first entity in the selection set so that
recent features are fully tessellated and selectable. Tries the primary
coordinate and several small radial/Y offsets to improve hit probability
on curved edges.
entity_type is normally "EDGE", but pass "FACE" to select a
whole face instead — InsertFeatureChamfer/FeatureFillet3 then
chamfer/fillet every edge bounding that face. Face selection has no
equivalent to the edge case's boundary ambiguity (see _parse_edge_spec).
The Callout parameter of SelectByID2 requires a VT_DISPATCH null
VARIANT — passing plain Python None triggers DISP_E_TYPEMISMATCH.
Returns True if an entity was successfully selected; False otherwise.
Source code in src/solidworks_mcp/adapters/solidworks/features.py
1570 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 | |
_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(False, 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 |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The selected |
Any
|
could not be selected. |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_select_named_feature ¶
Select a named feature under a specific selection mark via Select2.
Sweep and loft rely on selection marks to tell SolidWorks which selection
is the profile (1), guide curve (2), or sweep path (4). We resolve the
feature with IModelDoc2::FeatureByName and select it with
IFeature::Select2(append, mark) — the same proven path the rest of the
adapter uses for plane/sketch selection. IModelDocExtension::SelectByID2
is avoided deliberately: late-bound SelectByID2 raises
Type mismatch on some SolidWorks builds, whereas FeatureByName +
Select2 is reliable, works for sketches and reference curves such as
a helix, and needs no entity-type string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
name
|
str
|
Feature name (e.g. |
required |
mark
|
int
|
Selection mark — 1=profile, 2=guide curve, 4=sweep path. |
required |
append
|
bool
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_select_reference_entity ¶
Select a named plane or planar face under a given selection mark.
Prefers FeatureByName + IFeature::Select2, which is reliable
across builds, and falls back to SelectByID2 for planar faces that are
not named tree features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
reference
|
str
|
Plane or face name, e.g. |
required |
mark
|
int
|
Selection mark the SolidWorks call expects for this role. |
required |
append
|
bool
|
Add to the current selection rather than replacing it. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True when the entity was selected. |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_suppress_feature_impl ¶
Suppress or unsuppress a named feature in the active model.
Suppressing rolls a feature and its children out of the model without deleting it - the reversible way to turn off a bad feature.
EditSuppress2 and EditUnsuppress2 report through the error channel
only, so the resulting state is read back from IFeature::IsSuppressed
rather than inferred from the call returning quietly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
name
|
str
|
Feature name to toggle. |
required |
suppress
|
bool
|
|
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The feature and its state afterwards. |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
which is not the same as "not suppressed". |
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
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 2107 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 | |
_undo_impl ¶
Undo the last count operations in the active model.
IModelDoc2::EditUndo2(Steps) is a Sub - it returns nothing - so a
quiet call means only that it was made, not that anything was undone.
SolidWorks accepts an undo with an empty stack without complaint. The
feature tree is therefore compared before and after, and the payload says
plainly whether it changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
count
|
int
|
Number of operations to undo; values below 1 are clamped. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: How many steps were requested and |
AdapterResult[dict[str, Any]]
|
whether the feature tree actually changed. |
Raises:
| Type | Description |
|---|---|
Exception
|
Propagated through |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
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 | |