solidworks_mcp.adapters.solidworks.assembly¶
solidworks_mcp.adapters.solidworks.assembly ¶
Assembly-depth mixin for PyWin32 SolidWorks operations (queue item 33).
Exploded views, component patterns and mirrors, replacing a component, and
balloons on a drawing view. Components are named by their instance name
(pin-1), found with the helpers io.py already uses. COM signatures and
enum values were read from SolidWorks 2026's type library.
Attributes¶
BALLOON_LAYOUTS
module-attribute
¶
_DIRECTION_PLANES
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. |
SolidWorksAssemblyMixin ¶
Exploded views, component patterns, mirrors, replace and balloons.
Methods:¶
add_balloons
async
¶
Number a drawing view's parts with balloons, one per part.
Selects the view and calls IDrawingDoc.AutoBalloon5 with
options from CreateAutoBalloonOptions: the layout,
circular balloons, one per part (IgnoreMultiple).
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The |
AdapterResult[dict[str, Any]]
|
balloon |
Source code in src/solidworks_mcp/adapters/solidworks/assembly.py
create_exploded_view
async
¶
Explode the active assembly, automatically or step by step, and show it.
With no steps, IAssemblyDoc.AutoExplode. Each step moves its
components distance mm along x, y or z
(reverse for the other way): the components are selected under
mark 1 and the default plane normal to the direction under mark 2,
then IConfiguration.AddExplodeStep2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
steps
|
list[dict[str, Any]] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The exploded view's |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
|
Source code in src/solidworks_mcp/adapters/solidworks/assembly.py
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 206 207 208 209 210 211 212 213 214 215 | |
mirror_components
async
¶
Mirror components about a plane, as instances of the same parts.
IAssemblyDoc.MirrorComponents3 with the components as
ComponentsToInstance and nothing mirrored into new files.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The |
AdapterResult[dict[str, Any]]
|
instances' names. |
Source code in src/solidworks_mcp/adapters/solidworks/assembly.py
pattern_components
async
¶
pattern_components(components: list[str], axis: str, count: int, kind: str = 'linear', spacing: float | None = None, angle: float | None = None) -> AdapterResult[dict[str, Any]]
Repeat components along or around a reference axis.
A component pattern feature from a definition
(IFeatureManager.CreateDefinition, local linear or circular):
the seeds, the axis, count (seeds included) and the spacing (mm)
or the angle (degrees; 360 spaces them equally).
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The |
AdapterResult[dict[str, Any]]
|
counts before and after, and the |
Source code in src/solidworks_mcp/adapters/solidworks/assembly.py
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 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 | |
replace_component
async
¶
replace_component(component: str, file_path: str, all_instances: bool = False) -> AdapterResult[dict[str, Any]]
Swap a component for another part or assembly file.
Selects the component and calls IAssemblyDoc.ReplaceComponents2
(the file's active configuration, mates re-attached). The file must
exist; names and files are read back afterwards.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
names before and after. |
Source code in src/solidworks_mcp/adapters/solidworks/assembly.py
set_component_appearance
async
¶
set_component_appearance(component: str, visible: bool | None = None, transparent: bool | None = None) -> AdapterResult[dict[str, Any]]
Hide or show a component, and make it transparent or opaque.
Visibility is IComponent2.Visible (1 shown, 0 hidden);
transparency selects the component and calls
IAssemblyDoc.SetComponentTransparent. Both are read back.
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: |
AdapterResult[dict[str, Any]]
|
after. |
Source code in src/solidworks_mcp/adapters/solidworks/assembly.py
set_exploded_view
async
¶
Show the active configuration's exploded view, or collapse it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exploded
|
bool
|
|
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
AdapterResult[dict[str, Any]]: The |
AdapterResult[dict[str, Any]]
|
( |
Source code in src/solidworks_mcp/adapters/solidworks/assembly.py
Functions:¶
_assembly ¶
_box_from_metres ¶
Turn a SolidWorks [x1, y1, z1, x2, y2, z2] box in metres into mm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
Any
|
The six-value box, or anything else. |
required |
method
|
str
|
How the box was measured, reported back to the caller. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
dict[str, Any] | None: |
dict[str, Any] | None
|
or |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_box_size ¶
The assembly's bounding box size [x, y, z] in mm.
Source code in src/solidworks_mcp/adapters/solidworks/assembly.py
_byref_int ¶
Return a byref long VARIANT for a SolidWorks out-parameter.
See :func:_byref_bstr for why pythoncom.Missing does not work.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
A |
Any
|
unavailable (test/mock environments). |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_component_names ¶
Return the names of an assembly's top-level components.
AddComponent* can return an object having added nothing, so the
component list is the ground truth for whether an insert worked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
assembly
|
Any
|
The assembly document, flagged for |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: Component names, empty when the assembly holds none. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_doc_type ¶
Return the active document's type: 1 part, 2 assembly, 3 drawing.
GetType is one of the members pywin32 late binding may expose as either
a bound method or a plain value, so calling it directly returns None on
some documents. _get_attr_or_call handles both shapes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The document type, or |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_exploded_views ¶
The active configuration's exploded views' names.
Source code in src/solidworks_mcp/adapters/solidworks/assembly.py
_find_components ¶
The named top-level components of assembly, as IComponent2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
The connected adapter. |
required |
assembly
|
Any
|
The |
required |
names
|
list[str]
|
Instance names, e.g. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Name to wrapped component, one per name. |
Raises:
| Type | Description |
|---|---|
Exception
|
When the components can't be read, or a name isn't there (the message lists what the assembly holds). |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_need_assembly ¶
The wrong-document error, or None when an assembly is active.
Source code in src/solidworks_mcp/adapters/solidworks/assembly.py
_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
_resolve_drawing_view ¶
Return the IView on the active drawing whose name matches.
Walks IDrawingDoc::GetViews (a list of sheets, each shaped
(sheet, view, view, ...)) the same way :func:_view_names does. The
match is case-insensitive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
drawing
|
Any
|
The drawing document, flagged for |
required |
view_name
|
str
|
The drawing-view name to look for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The flagged |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
_select_components ¶
Select each component, appending, under mark.
Source code in src/solidworks_mcp/adapters/solidworks/assembly.py
_select_data ¶
An ISelectData carrying mark.
Source code in src/solidworks_mcp/adapters/solidworks/assembly.py
_select_named ¶
Select a plane or axis by its name, appending, under mark.
A default plane (Top Plane, Right...) is found by its place in
the assembly's tree, in any language (#262, fixed in 2.2.0).
Raises:
| Type | Description |
|---|---|
Exception
|
|
Source code in src/solidworks_mcp/adapters/solidworks/assembly.py
_selected ¶
The index-th selected object (1-based).
Source code in src/solidworks_mcp/adapters/solidworks/assembly.py
_view_names ¶
Return the drawing's view names, excluding sheet formats.
CreateDrawViewFromModelView3 returns None for a model SolidWorks
could not resolve, and Create3rdAngleViews2 returns a bare boolean, so
the view list is the ground truth for whether views were really added.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected |
required |
drawing
|
Any
|
The drawing document, flagged for |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: View names in sheet order. |
Source code in src/solidworks_mcp/adapters/solidworks/io.py
as_list ¶
Normalise a COM array/scalar/None return into a list.
dispatch_array ¶
VARIANT(VT_ARRAY | VT_DISPATCH), e.g. edges for a flange (tuple when pywin32 is absent).
Source code in src/solidworks_mcp/adapters/solidworks/com_utils.py
entity_name ¶
The document's own name for a default plane or the origin.
Front, Top, Right, XY, XZ, YZ, Front Plane...
and Origin, in any case, are found by their place in the tree; a
@component@assembly suffix reads that component's tree and is kept.
Any other name is returned unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
A connected adapter with a document open. |
required |
name
|
str
|
The name a tool was given. |
required |
owner
|
Any
|
The document or component to read; by default the active document, or the component the suffix names. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The name to pass to SolidWorks. When the tree can't be read, the |
str
|
English name ( |
Raises:
| Type | Description |
|---|---|
LookupError
|
The tree reached its origin with fewer than three reference planes before it; the message lists them and the install's language. |
Source code in src/solidworks_mcp/adapters/solidworks/default_entities.py
long_array ¶
VARIANT(VT_ARRAY | VT_I4), e.g. one orientation per component (tuple when pywin32 is absent).