solidworks_mcp.adapters.solidworks.equations¶
solidworks_mcp.adapters.solidworks.equations ¶
Equations and global variables: list, add or change, and delete them.
Since 2.2.0 every IEquationMgr call goes through compat (#265: they
failed with "Member not found" on SolidWorks 2024).
One value ("Width" = 60mm) can drive several dimensions
("D1@Sketch1" = "Width" / 2), which is how a SolidWorks part becomes
parametric.
COM calls (argument lists from the installed 2026 type library), all on
IModelDoc2.GetEquationMgr(). What each returns was measured on
SolidWorks 2026 (the equations live probe, 2026-11-18):
GetCount(), and the indexed propertiesEquation(i),Value(i)andGlobalVariable(i);Equation(i)reads the active configuration's text;Add2(Index, Equation, Solve)returns the new index, or -1 when SolidWorks refuses the text. It adds to every configuration;- writing the
Equation(i)property changes an equation in every configuration (its scope goes back to all). A text SolidWorks can't use is refused:Statusbecomes -1 and the stored text doesn't change; SetEquationAndConfigurationOption(Index, Equation, 1, None)(this configuration) returns 0 when it worked. Named configurations are set one at a time, each made active in turn, then the active one is shown again. Given any array of configuration names it returns -1, and with option 2 (all) it returns -1 on a part with many equations (19 in the wrench demo), which is why "all" writes the property instead.Add3takes names too and fails the same way, so it isn't used;Delete(Index);EvaluateAll(), whose return value isn't used (it returned -1 on a part that solved);Status, the last operation's result: -1 when it failed, so an added equation SolidWorks couldn't solve is deleted again.
IModelDoc2.Parameter(name) checks a dimension name before anything is
written.
Attributes¶
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. |
SolidWorksEquationsMixin ¶
List, add or change, and delete equations and global variables.
Methods:¶
delete_equation
async
¶
Delete the equation for name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The equation's name (its left-hand side). |
required |
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
The deleted name and the names left. |
Source code in src/solidworks_mcp/adapters/solidworks/equations.py
list_equations
async
¶
Every equation and global variable of the active model.
Returns:
| Type | Description |
|---|---|
AdapterResult[list[dict[str, Any]]]
|
Each with |
AdapterResult[list[dict[str, Any]]]
|
|
Source code in src/solidworks_mcp/adapters/solidworks/equations.py
set_equation
async
¶
set_equation(name: str, expression: str, configurations: str | list[str] = 'all') -> AdapterResult[dict[str, Any]]
Add an equation for name, or change the one there is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A global variable, or a dimension such as |
required |
expression
|
str
|
The right-hand side, e.g. |
required |
configurations
|
str | list[str]
|
|
'all'
|
Returns:
| Type | Description |
|---|---|
AdapterResult[dict[str, Any]]
|
The stored equation, its value, |
AdapterResult[dict[str, Any]]
|
|
AdapterResult[dict[str, Any]]
|
configurations, the expression set and |
AdapterResult[dict[str, Any]]
|
value in each of them. |
Source code in src/solidworks_mcp/adapters/solidworks/equations.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 363 364 365 366 367 368 369 | |
Functions:¶
_active ¶
The active configuration's name (IConfiguration.Name is a property).
Source code in src/solidworks_mcp/adapters/solidworks/configurations.py
_add ¶
Add text at index (-1: at the end); its index, or -1 if refused.
An equation Add2 accepts but can't solve leaves Status negative;
it is deleted again so nothing half-made stays in the model.
Source code in src/solidworks_mcp/adapters/solidworks/equations.py
_failed ¶
Whether the last operation failed: Status is negative then.
_kind ¶
global_variable, dimension (a name with @) or other.
_put_everywhere ¶
Write the Equation(index) property: the text in every configuration.
pywin32's late binding reads indexed properties but can't assign one, so
the property put goes through IDispatch.Invoke.
Source code in src/solidworks_mcp/adapters/solidworks/equations.py
_same ¶
Whether two equation texts match, ignoring spaces and case.
_set_here ¶
Set equation index to text in the active configuration only.
Source code in src/solidworks_mcp/adapters/solidworks/equations.py
_took ¶
Whether SolidWorks kept text for equation index.
Status isn't negative and the stored text reads back the same
(SolidWorks may respace it).
Source code in src/solidworks_mcp/adapters/solidworks/equations.py
configuration_scope ¶
Where a change applies: the COM option, the names, and their array.
"this" is the active configuration, "all" every one, a list those
named (each checked first).
Raises:
| Type | Description |
|---|---|
LookupError
|
For a name the model doesn't have, listing the names. |
Source code in src/solidworks_mcp/adapters/solidworks/configurations.py
equation_text ¶
split_equation ¶
An equation's name and expression, from its text.
Text with no quoted name (not one SolidWorks writes) gives an empty name and the whole text as the expression.