solidworks_mcp.adapters.solidworks.face_selection¶
solidworks_mcp.adapters.solidworks.face_selection ¶
Resolve a face by point / side / plane and multi-select its edges (#106).
Split into three single-purpose pieces so each can be tested on its own:
- Pure geometry (no COM): side-token parsing, picking the furthest planar face facing a direction, matching faces to a reference plane, and input validation shared by the real and mock adapters.
- Edge description (:func:
describe_edge): one place that turns anIEdgeinto a JSON-friendly dict - also used byget_selected_entities. - COM access (:class:
FaceEdgeSelector): reads faces/edges off the active part and performs the multi-selection.
Live behaviour this relies on (R2026x, 2026-10-13) is recorded in
openspec/changes/archive/2026-10-30-wire-unwired-adapter-tools/design.md: every dispatch must
be method-flagged, IFace2.Normal is [0,0,0] for non-planar faces,
IFace2.GetClosestPointOn returns the closest point in its first three
values, a full-circle edge has no vertices, IRefPlane.Transform.ArrayData
holds the plane normal at [6:9] and origin at [9:12], and
IEntity.Select4 needs a real SelectData (None is a type mismatch).
Attributes¶
SIDE_VECTORS
module-attribute
¶
SIDE_VECTORS: dict[str, tuple[float, float, float]] = {'+x': (1.0, 0.0, 0.0), '-x': (-1.0, 0.0, 0.0), '+y': (0.0, 1.0, 0.0), '-y': (0.0, -1.0, 0.0), '+z': (0.0, 0.0, 1.0), '-z': (0.0, 0.0, -1.0), 'right': (1.0, 0.0, 0.0), 'left': (-1.0, 0.0, 0.0), 'top': (0.0, 1.0, 0.0), 'bottom': (0.0, -1.0, 0.0), 'front': (0.0, 0.0, 1.0), 'back': (0.0, 0.0, -1.0)}
_EDGE_MEMBERS
module-attribute
¶
_FACE_MEMBERS
module-attribute
¶
Classes¶
FaceEdgeSelector ¶
Resolve a face on the active part and multi-select its edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
Source code in src/solidworks_mcp/adapters/solidworks/face_selection.py
Methods:¶
component_faces ¶
Return every face of a component's solid bodies.
Measured on SW 2026: these faces report their geometry in the
component's own part coordinates, wherever it sits in the assembly,
and IEntity::GetComponent on them returns the component.
Source code in src/solidworks_mcp/adapters/solidworks/face_selection.py
edges ¶
Return (edge, description) for the faces' edges passing the filter.
Source code in src/solidworks_mcp/adapters/solidworks/face_selection.py
face_at_point ¶
Return the face containing point_mm (closest within 0.01 mm).
Source code in src/solidworks_mcp/adapters/solidworks/face_selection.py
faces ¶
Return every face of every solid body on the active part.
Source code in src/solidworks_mcp/adapters/solidworks/face_selection.py
plane_geometry ¶
Return (origin, normal) of a named reference plane.
Source code in src/solidworks_mcp/adapters/solidworks/face_selection.py
resolve ¶
Resolve the request to one face (or several for plane).
Source code in src/solidworks_mcp/adapters/solidworks/face_selection.py
select ¶
Select every edge; return the selection count afterwards.
All or nothing: if any edge refuses to select, the selection is
cleared before raising, so a following add_chamfer /
add_fillet with empty edge_names cannot silently act on a
partial set.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
When any edge refuses to select. |
Source code in src/solidworks_mcp/adapters/solidworks/face_selection.py
FaceInfo
dataclass
¶
FaceInfo(index: int, normal: tuple[float, float, float], box: tuple[float, float, float, float, float, float], area: float, handle: Any = None)
Geometry of one body face, in metres.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
Position in the body's face list (stable within one call). |
normal |
tuple[float, float, float]
|
Outward unit normal; |
box |
tuple[float, float, float, float, float, float]
|
|
area |
float
|
Face area in m^2. |
handle |
Any
|
The |
Functions:¶
_attempt ¶
Run fn through the adapter's _attempt (exceptions -> default).
_dot ¶
_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
as_list ¶
Normalise a COM array/scalar/None return into a list.
describe_edge ¶
Describe an IEdge in millimetres; unresolvable fields are omitted.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: |
dict[str, Any]
|
|
dict[str, Any]
|
(straight-line length - a curved edge is longer), and |
dict[str, Any]
|
|
Source code in src/solidworks_mcp/adapters/solidworks/face_selection.py
edge_matches ¶
Whether an edge of kind passes the edge_type filter.
faces_on_plane ¶
faces_on_plane(faces: list[FaceInfo], origin: tuple[float, float, float], normal: tuple[float, float, float]) -> list[FaceInfo]
Return the planar faces that lie in the given plane.
Source code in src/solidworks_mcp/adapters/solidworks/face_selection.py
mate_entity_label ¶
How a mate's reply names one side: the entity, or the face point.
Shared by the live and mock adapters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
str
|
The named entity (used when no face is given). |
required |
face
|
list[float] | None
|
A point on a face, in part coordinates (mm). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
e.g. |
Source code in src/solidworks_mcp/adapters/solidworks/face_selection.py
pick_side_face ¶
Return the planar face facing direction that lies furthest along it.
Ties (same offset within 0.1 µm) go to the larger face.
Source code in src/solidworks_mcp/adapters/solidworks/face_selection.py
plane_from_transform ¶
plane_from_transform(array_data: list[float]) -> tuple[tuple[float, float, float], tuple[float, float, float]]
Return (origin, normal) from IRefPlane.Transform.ArrayData.
Source code in src/solidworks_mcp/adapters/solidworks/face_selection.py
selection_count ¶
Number of entities currently selected in model, or None.
Source code in src/solidworks_mcp/adapters/solidworks/com_utils.py
side_vector ¶
Return the unit vector for a side token.
Raises:
| Type | Description |
|---|---|
ValueError
|
When the token is not one of :data: |
Source code in src/solidworks_mcp/adapters/solidworks/face_selection.py
validate_face_query ¶
validate_face_query(point: list[float] | None, side: str | None, plane: str | None, edge_type: str) -> str | None
Check a select_face_edges request; return an error message or None.