solidworks_mcp.adapters.solidworks.feature_walk¶
solidworks_mcp.adapters.solidworks.feature_walk ¶
The one walk of a document's top-level feature tree.
list_features and list_model_dimensions both read the tree through
:func:walk_feature_tree, so they always see the same features in the same
order.
SolidWorks can stop IFeature.GetNextFeature at the system folders even
though later sketches and features exist, so the walk always makes a second
pass with IModelDoc2.FeatureByPositionReverse. Both passes number a
feature by its place in the tree (the forward pass counts from 0, the
reverse pass uses count - reverse_position - 1), so a feature found by
both gets one number, and sorting by it gives tree order, oldest first.
Attributes¶
WALK_MEMBERS
module-attribute
¶
Classes¶
TreeFeature
dataclass
¶
One top-level feature found by the walk.
Attributes:
| Name | Type | Description |
|---|---|---|
position |
int
|
Its place in the tree, 0 for the first. |
name |
str
|
The feature's name. |
type_name |
str
|
Its |
feature |
Any
|
The |
Functions:¶
_describe ¶
Read one feature's name and type into a :class:TreeFeature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
The adapter, for |
required |
feature
|
Any
|
The |
required |
position
|
int
|
Its place in the tree. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TreeFeature |
TreeFeature
|
The feature with its name and type. |
Source code in src/solidworks_mcp/adapters/solidworks/feature_walk.py
attempt ¶
Run fn through the adapter's _attempt (exceptions -> default).
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 feature_walk); 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
walk_feature_tree ¶
Every top-level feature of document, once each, in tree order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
The adapter, for |
required |
document
|
Any
|
The |
required |
Returns:
| Type | Description |
|---|---|
list[TreeFeature]
|
list[TreeFeature]: The features, sorted by tree position. A feature |
list[TreeFeature]
|
found by both passes (same name and type) is kept once. |