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')}
_EXTRUSION_END_CONDITIONS
module-attribute
¶
_EXTRUSION_END_CONDITIONS = {'blind': ('Blind', 'swEndCondBlind'), 'midplane': ('MidPlane', 'swEndCondMidPlane'), 'throughall': ('ThroughAll', 'swEndCondThroughAll'), 'uptonext': ('UpToNext', 'swEndCondUpToNext')}
_THIN_SIDES
module-attribute
¶
_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)
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. |
thin_side |
str
|
Which side of the sketch a thin wall grows on:
|
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. |
sketch_name |
str | None
|
The sketch to revolve, by its tree name;
|
axis_entity |
str | None
|
A reference axis to revolve about, by its
tree name; |
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:¶
add_fillet
async
¶
Fillet edges, then confirm the model's volume actually changed.
IModelDoc2.FeatureFillet3 can report success without building
anything, so besides the feature-count check inside
:func:_add_fillet_impl the volume is compared before and after,
here in the async layer for the same reason as mirror_feature.
An unreadable volume is not treated as failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Fillet radius in millimetres. |
required |
edge_names
|
list[str]
|
Edge names, |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[SolidWorksFeature]
|
AdapterResult[SolidWorksFeature]: The fillet, with |
AdapterResult[SolidWorksFeature]
|
|
AdapterResult[SolidWorksFeature]
|
could be read. |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
create_reference_point
async
¶
create_reference_point(mode: str, x: float, y: float, z: float, distance: float | None = None, percent: float | None = None) -> AdapterResult[dict[str, Any]]
Create a reference point on the active part.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
|
required |
x
|
float
|
X of a point on the target edge/face, in millimetres. |
required |
y
|
float
|
Y of a point on the target edge/face, in millimetres. |
required |
z
|
float
|
Z of a point on the target edge/face, in millimetres. |
required |
distance
|
float | None
|
For |
None
|
percent
|
float | None
|
For |
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Delegates to |
AdapterResult[dict[str, Any]]
|
func: |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
delete_feature
async
¶
Delete a feature and report every feature that went with it.
The tree is listed before and after with list_features, the read
path that works on SolidWorks, and the names that disappeared become
removed_features: the named feature and its dependents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The feature or sketch to delete. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The delete's data plus |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
can't be listed). |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
mirror_feature
async
¶
mirror_feature(features: list[str], mirror_plane: str, merge: bool = True, mirror_bodies: bool = True) -> AdapterResult[dict[str, Any]]
Mirror solid bodies or features about a plane.
InsertMirrorFeature returns a Feature object even when it mirrored
nothing, so the model's volume is measured before and after and the
call is reported as failed if the volume did not change (a mirrored
cut lowers it, a mirrored boss or body raises it). That check runs
here rather than inside the COM closure because get_mass_properties
is the read path known to work - reading CreateMassProperty().Volume
inline returns None when a plane is still in the selection set,
which silently disables the check.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list[str]
|
Names of the bodies (or features) to mirror. For a body mirror these are the names as they appear under Solid Bodies, which for a lofted wing is the loft's own name. |
required |
mirror_plane
|
str
|
Plane to mirror about, e.g. |
required |
merge
|
bool
|
Merge the mirrored result with the original. |
True
|
mirror_bodies
|
bool
|
Mirror whole solid bodies rather than features.
Defaults to |
True
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: What was mirrored, and the volume |
AdapterResult[dict[str, Any]]
|
before, after and its change. |
AdapterResult[dict[str, Any]]
|
the call failed, or the volume did not change. |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
pattern_circular
async
¶
pattern_circular(features: list[str], axis: str, count: int, angle: float = 360.0, equal_spacing: bool = True) -> AdapterResult[dict[str, Any]]
Pattern features around an axis.
FeatureCircularPattern5 returns a Feature object whether or not it
produced anything, so the model volume is measured before and after
here - in the async layer, using get_mass_properties, which is the
read path that works. Reading volume inline inside the COM closure
returns None while a selection is active.
Note that instances landing off the parent body are silently dropped
by SolidWorks, so the volume changes by less than count - 1 times
the seed. That is correct behaviour, not a failure - only no change
at all means the pattern did nothing. A pattern of a cut lowers the
volume, a pattern of a boss raises it; both count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list[str]
|
Names of the features to pattern. |
required |
axis
|
str
|
Name of the axis to rotate about, e.g. |
required |
count
|
int
|
Total number of instances including the original. |
required |
angle
|
float
|
Total angle in degrees to spread them over. Defaults to a full 360. |
360.0
|
equal_spacing
|
bool
|
Space instances evenly across |
True
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: What was patterned and the volume |
AdapterResult[dict[str, Any]]
|
before, after and its change. |
AdapterResult[dict[str, Any]]
|
selected or the volume did not change. |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
rename_feature
async
¶
Rename a feature on the active model's tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_name
|
str
|
The feature's current name. |
required |
new_name
|
str
|
The name to give it. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: Delegates to |
AdapterResult[dict[str, Any]]
|
func: |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
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. |
_BodyEntityPicker ¶
Find the body edge or face nearest a point, by true closest distance.
SelectByID2("", "EDGE", x, y, z, ...) picks along the view direction
through the point, so on a 12 mm plate seen from the front an edge at
z=-6 is hidden behind the matching edge at z=+6 and the front one is
selected instead - silently. This walks every solid body's edges (or
faces) and measures the distance from the point to the closest point
on each (IEdge / IFace2.GetClosestPointOn), which does not
depend on the view, vertices or midpoints.
The entity lists are read once per picker, so one fillet over many edges costs one body walk, not one per edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
Methods:¶
entities ¶
Return every solid body's GetEdges() or GetFaces().
Source code in src/solidworks_mcp/adapters/solidworks/features.py
nearest ¶
Return (entity, distance_m) for the closest entity, or None.
Source code in src/solidworks_mcp/adapters/solidworks/features.py
select ¶
Select entity with IEntity.Select4 under mark.
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_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], angle: float = 45.0, flip: bool = False) -> AdapterResult[SolidWorksFeature]
Create an angle-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 with swChamferAngleDistance (type 1; equal distance is
16). At 45 degrees the two legs are equal, which is what this call has
always made. Options 1 is swFeatureChamferFlipDirection, kept as
the default so existing chamfers are unchanged; flip clears it. 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, along one face. Converted to metres internally. |
required |
angle
|
float
|
Chamfer angle in degrees (0-90 exclusive). Defaults to 45. |
45.0
|
flip
|
bool
|
Measure |
False
|
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
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 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 2349 2350 2351 2352 2353 | |
_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
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 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 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 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 | |
_attempt ¶
Run fn through the adapter's _attempt (exceptions -> default).
_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
3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 | |
_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
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 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 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 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 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 | |
_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
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 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 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 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
_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
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 | |
_create_reference_plane_impl ¶
_create_reference_plane_impl(adapter: Any, reference: str, offset: float, angle: float, flip: bool, axis: str | None = None, face_point: list[float] | None = None) -> AdapterResult[dict[str, Any]]
Create a reference plane offset from, angled to, or on a plane or face.
Wraps IFeatureManager::InsertRefPlane(FirstConstraint,
FirstConstraintAngleOrDistance, Second, value, Third, value). The
reference (a named plane, or the flat face at face_point) is selected
under mark 0; for an angled plane, axis is selected under
mark 1 with the Coincident constraint, which is the second reference
an angled plane needs (an angle constraint on one plane alone adds
nothing, measured on SW 2025).
create_sketch 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; ignored when |
required |
offset
|
float
|
Offset distance in millimetres, converted to metres. |
required |
angle
|
float
|
Angle in degrees about |
required |
flip
|
bool
|
Reverse the offset or angle direction. |
required |
axis
|
str | None
|
Named axis to rotate about (e.g. |
None
|
face_point
|
list[float] | None
|
|
None
|
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("Top Plane", angle=40, axis="Axis1")
await adapter.create_sketch(plane.data["name"])
Source code in src/solidworks_mcp/adapters/solidworks/features.py
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 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 | |
_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
3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 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 3406 | |
_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
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 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 | |
_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
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 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 | |
_delete_feature_impl ¶
Delete a named feature or sketch from the active model.
Selects the feature, then removes it with
IModelDocExtension::DeleteSelection2(swDelete_Children), which takes
the features built on it too ("erase this and what depends on it"), so
the number of features removed is reported, not assumed to be one.
IModelDoc2::EditDelete left a sketch in place when a cut used it
(measured on SolidWorks 2026). A feature's own sketch is "absorbed", not
a child, so deleting a cut leaves its sketch. A sketch a feature uses
can't be deleted on its own at all, so its users are deleted instead,
taking it with them (:func:_delete_users_of).
Success is confirmed by the feature being absent from the tree afterwards, not by the call's return value.
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
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 2558 2559 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 | |
_delete_users_of ¶
Delete the features built from feature, with their absorbed sketch.
SolidWorks won't delete a sketch a feature still uses: DeleteSelection2
returns False even with swDelete_Children (measured on 2026). Deleting
the features that use it (IFeature::GetChildren) with
swDelete_Absorbed takes the sketch with them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
feature
|
Any
|
The |
required |
Returns:
| Type | Description |
|---|---|
Any
|
tuple[Any, Exception | None]: |
Exception | None
|
what it raised; |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_extrusion_end_condition ¶
_extrusion_end_condition(adapter: Any, end_condition: str, both_directions: bool) -> tuple[str, int]
Resolve a boss extrusion's first-direction end condition.
both_directions=True means mid-plane whatever end_condition says,
which is what the thin-wall branch always did. Before this was shared,
the solid branch passed swEndCondBlind unconditionally, so a
"both directions" extrusion silently came out one-sided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
Adapter whose |
required |
end_condition
|
str
|
Requested condition, e.g. |
required |
both_directions
|
bool
|
Extrude symmetrically about the sketch plane. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, int]
|
tuple[str, int]: The canonical name and its |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_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 ¶
Flag just names as methods on obj (no-op for None/fakes).
Flagging a whole interface costs ~27 ms per fresh dispatch (see
_WALK_MEMBERS in pywin32_adapter); SolidWorks hands back a fresh
dispatch on most calls, so flag only what is about to be read.
Source code in src/solidworks_mcp/adapters/solidworks/com_utils.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
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 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 | |
_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. It is the robust way to reach a
hole's rim: the rim is one edge of the face the hole opens onto, and
a point well inside that face is clear of every boundary, whereas an
edge point has to land on the rim itself.
Every coordinate pick must lie within _PICK_TOLERANCE_M of the edge
or face it resolves to. (A 2026-09-18 note here said an edge pick aimed
at a hole rim landed on a 30 mm outer edge; the test's point was on that
outer edge, because it assumed the wrong height axis. See #199.)
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
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 3668 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 | |
_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
_removed_names ¶
_removed_names(before: AdapterResult[list[dict[str, Any]]], after: AdapterResult[list[dict[str, Any]]]) -> list[str]
The feature names listed before a delete and missing after it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
before
|
AdapterResult[list[dict[str, Any]]]
|
|
required |
after
|
AdapterResult[list[dict[str, Any]]]
|
|
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The names that went, in tree order; empty when either |
list[str]
|
listing failed. |
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
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 | |
_resolve_profile_sketch ¶
Find the sketch a feature is built from, and select it.
Sketch resolution never guesses: sketch_name is matched against the
live feature tree without regard to case; without it, the sketch the
session closed last is used only if that name is really in the tree.
Anything else raises, listing the sketches that exist. The sketch is then
selected with SelectByID2 so the feature call never relies on
SolidWorks' implicit active-sketch state. Runs inside the caller's
_handle_com_operation closure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
sketch_name
|
str | None
|
The sketch to use, or |
required |
purpose
|
str
|
How the error messages name the use, e.g. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The sketch's name as the tree spells it. |
Raises:
| Type | Description |
|---|---|
Exception
|
The sketch isn't in the tree, or can't be selected. |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
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 | |
_select_by_view_pick ¶
_select_by_view_pick(adapter: Any, x: float, y: float, z: float, append: bool, mark: int, entity_type: str) -> bool
Fallback pick through SelectByID2 when no body geometry is readable.
Tries the point plus small radial/Y offsets. View-dependent (see
:class:_BodyEntityPicker), so only used when the body walk found
nothing to measure.
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_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', picker: _BodyEntityPicker | None = None) -> bool
Select the edge (or face) nearest to (x, y, z) in metres.
Calls ForceRebuild3 on the first entity in the selection set so that
recent features are fully tessellated and selectable, then resolves the
point with :class:_BodyEntityPicker - the entity whose closest point is
nearest, independent of the view. Only when no body edge/face can be read
at all does it fall back to the view-dependent SelectByID2 pick.
entity_type is normally "EDGE", but pass "FACE" to select a
whole face instead. Any other type ("VERTEX" from
measure_entities) goes straight to the SelectByID2 pick: a vertex
lies on its edges at distance 0, so the edge walk would select an edge
in its place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
x
|
float
|
X in metres. |
required |
y
|
float
|
Y in metres. |
required |
z
|
float
|
Z in metres. |
required |
append
|
bool
|
Add to the current selection instead of replacing it. |
required |
mark
|
int
|
Selection mark. |
0
|
entity_type
|
str
|
|
'EDGE'
|
picker
|
_BodyEntityPicker | None
|
Reuse a picker (and its body walk) across several picks. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if an entity was selected; False otherwise. |
Raises:
| Type | Description |
|---|---|
LookupError
|
When the nearest entity is further than
|
Source code in src/solidworks_mcp/adapters/solidworks/features.py
1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 | |
_select_face_at_point ¶
Select the planar face of the active part at point_mm under mark.
The face is found as select_face_edges finds it (the face whose
closest point is within 0.01 mm), then selected with IEntity.Select4
and a SelectData carrying the mark InsertRefPlane reads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a part open. |
required |
point_mm
|
list[float]
|
|
required |
mark
|
int
|
Selection mark for this reference. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True when the face was selected. |
Raises:
| Type | Description |
|---|---|
LookupError
|
When no face lies at the point, or the face isn't flat. |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_select_face_edges_by_coord ¶
_select_face_edges_by_coord(adapter: Any, x: float, y: float, z: float, append: bool, picker: _BodyEntityPicker) -> bool
Select every edge bounding the face through (x, y, z) in metres.
IModelDoc2.FeatureFillet3 (SW 2025+) given a selected face returns
success but builds nothing - no feature, no volume change (seen live on
SW 2026). Expanding the face to its edges first gives it what it can
fillet.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True when the face was found and all of its edges selected. |
Raises:
| Type | Description |
|---|---|
LookupError
|
When no face lies within |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_select_feature_by_name ¶
Select a feature or sketch by name and return it.
Resolves the entity with IModelDoc2::FeatureByName and selects it with
IFeature::Select2(append, 0) - the same path used elsewhere in this
adapter. SelectByID2 is avoided here because it needs an entity-type
string that differs between sketches and solid features, and because its
Callout argument raises Type mismatch unless passed an explicit
VT_DISPATCH null. Any name@document qualifier is stripped first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
name
|
str
|
Feature or sketch name, e.g. |
required |
append
|
bool
|
Add to the current selection instead of clearing it first. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The selected |
Any
|
could not be selected. |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
_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
_select_revolve_inputs ¶
Select a revolve's sketch and axis when they are named.
With neither named, nothing is selected: the sketch exit_sketch just
closed and its centreline are used, as before. A named axis needs the
sketch selected first (mark 0), then the axis appended with mark 4, the
mark FeatureRevolve2 reads the axis from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a valid |
required |
params
|
RevolveParameters
|
The revolve's parameters. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The sketch's tree name, or |
Raises:
| Type | Description |
|---|---|
Exception
|
The sketch or the axis isn't in the model. |
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
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 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 | |
_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
_with_volume_change ¶
_with_volume_change(result: AdapterResult[dict[str, Any]], before: float, after: float) -> AdapterResult[dict[str, Any]]
A pattern or mirror's result, with the volume it changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
AdapterResult[dict[str, Any]]
|
The feature call's successful result. |
required |
before
|
float
|
The part's volume before, in mm³. |
required |
after
|
float
|
The part's volume after, in mm³. |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
cut) and |
Source code in src/solidworks_mcp/adapters/solidworks/features.py
as_list ¶
Normalise a COM array/scalar/None return into a list.
reference_plane_refusal ¶
reference_plane_refusal(reference: str, offset: float, angle: float, axis: str | None, face_point: list[float] | None) -> str | None
Why a reference-plane request can't be made, or None when it can.
Shared by the live and mock adapters so both refuse the same requests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
str
|
Named reference plane (unused with |
required |
offset
|
float
|
Offset in mm. |
required |
angle
|
float
|
Angle in degrees. |
required |
axis
|
str | None
|
Axis to rotate about, for an angle. |
required |
face_point
|
list[float] | None
|
Point on a flat face to use as the reference. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The refusal message, or None. |