Skip to content

solidworks_mcp.adapters.solidworks.configurations

solidworks_mcp.adapters.solidworks.configurations

Configurations: create, activate and delete one, and read the active one.

Configurations give a part or assembly its variants (a long and a short version, a simplified one) without Excel: design tables don't work through COM on SolidWorks 2026 (queue item 10's live check), so this is the path.

COM calls (argument lists from the installed type library):

  • IConfigurationManager.AddConfiguration2(Name, Comment, AlternateName, Options, ParentConfigName, Description, Rebuild); the new configuration becomes active, so the previous one is shown again unless asked otherwise;
  • IModelDoc2.ShowConfiguration2(Name) and DeleteConfiguration2(Name);
  • IModelDoc2.GetConfigurationNames() and GetActiveConfiguration().Name.

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.

Attributes
is_error property
is_error: bool

Check if operation had an error.

Returns:

Name Type Description
bool bool

True if error, otherwise False.

is_success property
is_success: bool

Check if operation was successful.

Returns:

Name Type Description
bool bool

True if success, otherwise False.

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.

SolidWorksConfigurationsMixin

Create, activate and delete configurations, and read the active one.

Methods:
activate_configuration async
activate_configuration(name: str) -> AdapterResult[dict[str, Any]]

Make name the active configuration and rebuild.

Parameters:

Name Type Description Default
name str

The configuration to show.

required

Returns:

Type Description
AdapterResult[dict[str, Any]]

The active configuration and the one before it.

Source code in src/solidworks_mcp/adapters/solidworks/configurations.py
async def activate_configuration(self, name: str) -> AdapterResult[dict[str, Any]]:
    """Make ``name`` the active configuration and rebuild.

    Args:
        name: The configuration to show.

    Returns:
        The active configuration and the one before it.
    """
    adapter: Any = self

    def build() -> dict[str, Any]:
        _require(adapter, name)
        previous = _active(adapter)
        if not adapter.currentModel.ShowConfiguration2(name):
            raise RuntimeError(
                f"SolidWorks refused to show configuration '{name}'."
            )
        adapter._attempt(lambda: adapter.currentModel.ForceRebuild3(False), None)
        return {"active": _active(adapter), "previous": previous}

    return self._run_on_model("activate_configuration", build)
active_configuration async
active_configuration() -> AdapterResult[str]

The active configuration's name.

Returns:

Type Description
AdapterResult[str]

The name, or an error when no model is open or it can't be read.

Source code in src/solidworks_mcp/adapters/solidworks/configurations.py
async def active_configuration(self) -> AdapterResult[str]:
    """The active configuration's name.

    Returns:
        The name, or an error when no model is open or it can't be read.
    """
    adapter: Any = self
    result = self._run_on_model(
        "active_configuration", lambda: {"active": _active(adapter)}
    )
    if not result.is_success:
        return cast(AdapterResult[str], result)
    active = (result.data or {}).get("active")
    if not active:
        return AdapterResult(
            status=AdapterResultStatus.ERROR,
            error="The active configuration's name couldn't be read.",
        )
    return AdapterResult(
        status=AdapterResultStatus.SUCCESS,
        data=active,
        execution_time=result.execution_time,
    )
create_configuration async
create_configuration(name: str, parent: str | None = None, description: str = '', activate: bool = False) -> AdapterResult[dict[str, Any]]

Add a configuration, optionally derived from parent.

Parameters:

Name Type Description Default
name str

The new configuration's name.

required
parent str | None

A configuration to derive it from, or None.

None
description str

Its description.

''
activate bool

Leave it active; otherwise the previous one is shown again.

False

Returns:

Type Description
AdapterResult[dict[str, Any]]

The configuration, its parent, the active one and every name.

Source code in src/solidworks_mcp/adapters/solidworks/configurations.py
async def create_configuration(
    self,
    name: str,
    parent: str | None = None,
    description: str = "",
    activate: bool = False,
) -> AdapterResult[dict[str, Any]]:
    """Add a configuration, optionally derived from ``parent``.

    Args:
        name: The new configuration's name.
        parent: A configuration to derive it from, or None.
        description: Its description.
        activate: Leave it active; otherwise the previous one is shown again.

    Returns:
        The configuration, its parent, the active one and every name.
    """
    adapter: Any = self

    def build() -> dict[str, Any]:
        names = _names(adapter)
        if name in names:
            raise ValueError(f"A configuration named '{name}' already exists.")
        if parent is not None and parent not in names:
            raise LookupError(
                f"No configuration named '{parent}' to derive from; the model "
                f"has {', '.join(names)}."
            )
        previous = _active(adapter)
        manager = sw_type_info.flagged(
            adapter.currentModel.ConfigurationManager, "IConfigurationManager"
        )
        made = manager.AddConfiguration2(
            name, "", "", 0, parent or "", description, True
        )
        if made is None:
            raise RuntimeError(f"AddConfiguration2 made no configuration '{name}'.")
        if not activate and previous:
            adapter.currentModel.ShowConfiguration2(previous)
        return {
            "name": name,
            "parent": parent,
            "active": _active(adapter),
            "configurations": _names(adapter),
        }

    return self._run_on_model("create_configuration", build)
delete_configuration async
delete_configuration(name: str) -> AdapterResult[dict[str, Any]]

Delete a configuration that isn't active and isn't the only one.

Parameters:

Name Type Description Default
name str

The configuration to delete.

required

Returns:

Type Description
AdapterResult[dict[str, Any]]

The deleted name and the configurations left.

Source code in src/solidworks_mcp/adapters/solidworks/configurations.py
async def delete_configuration(self, name: str) -> AdapterResult[dict[str, Any]]:
    """Delete a configuration that isn't active and isn't the only one.

    Args:
        name: The configuration to delete.

    Returns:
        The deleted name and the configurations left.
    """
    adapter: Any = self

    def build() -> dict[str, Any]:
        names = _require(adapter, name)
        if len(names) == 1:
            raise ValueError(f"'{name}' is the model's only configuration.")
        if _active(adapter) == name:
            raise ValueError(
                f"'{name}' is the active configuration; activate another first."
            )
        if not adapter.currentModel.DeleteConfiguration2(name):
            raise RuntimeError(
                f"SolidWorks refused to delete configuration '{name}'."
            )
        return {"deleted": name, "configurations": _names(adapter)}

    return self._run_on_model("delete_configuration", build)

Functions:

_active

_active(adapter: Any) -> str | None

The active configuration's name (IConfiguration.Name is a property).

Source code in src/solidworks_mcp/adapters/solidworks/configurations.py
def _active(adapter: Any) -> str | None:
    """The active configuration's name (``IConfiguration.Name`` is a property)."""
    config = adapter._attempt(
        lambda: adapter.currentModel.GetActiveConfiguration(), None
    )
    name = getattr(config, "Name", None) if config is not None else None
    return str(name) if name else None

_names

_names(adapter: Any) -> list[str]

The active model's configuration names.

Source code in src/solidworks_mcp/adapters/solidworks/configurations.py
def _names(adapter: Any) -> list[str]:
    """The active model's configuration names."""
    raw = adapter._attempt(lambda: adapter.currentModel.GetConfigurationNames(), None)
    return [str(name) for name in as_list(raw)]

_require

_require(adapter: Any, name: str) -> list[str]

The names, after checking name is one of them.

Source code in src/solidworks_mcp/adapters/solidworks/configurations.py
def _require(adapter: Any, name: str) -> list[str]:
    """The names, after checking ``name`` is one of them."""
    names = _names(adapter)
    if name not in names:
        raise LookupError(
            f"No configuration named '{name}'; the model has {', '.join(names) or 'none'}."
        )
    return names

as_list

as_list(value: Any) -> list[Any]

Normalise a COM array/scalar/None return into a list.

Source code in src/solidworks_mcp/adapters/solidworks/com_utils.py
def as_list(value: Any) -> list[Any]:
    """Normalise a COM array/scalar/None return into a list."""
    if value is None:
        return []
    if isinstance(value, (list, tuple)):
        return list(value)
    return [value]

configuration_scope

configuration_scope(adapter: Any, configurations: str | list[str]) -> tuple[int, list[str], Any]

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
def configuration_scope(
    adapter: Any, configurations: str | list[str]
) -> tuple[int, list[str], Any]:
    """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:
        LookupError: For a name the model doesn't have, listing the names.
    """
    names = _names(adapter)
    if configurations == "this":
        active = _active(adapter)
        return THIS_CONFIGURATION, [active] if active else [], None
    if configurations == "all":
        return ALL_CONFIGURATIONS, names, string_array(names)
    unknown = [n for n in configurations if n not in names]
    if unknown:
        raise LookupError(
            f"No configuration named {', '.join(repr(n) for n in unknown)}; the "
            f"model has {', '.join(names) or 'none'}."
        )
    chosen = list(configurations)
    return SPECIFY_CONFIGURATION, chosen, string_array(chosen)

string_array

string_array(values: list[str]) -> Any

VARIANT(VT_ARRAY | VT_BSTR), e.g. configuration names (tuple when pywin32 is absent).

Source code in src/solidworks_mcp/adapters/solidworks/com_utils.py
def string_array(values: list[str]) -> Any:
    """``VARIANT(VT_ARRAY | VT_BSTR)``, e.g. configuration names (tuple when pywin32 is absent)."""
    try:
        import pythoncom
        import win32com.client as w32

        return w32.VARIANT(
            pythoncom.VT_ARRAY | pythoncom.VT_BSTR, [str(v) for v in values]
        )
    except ImportError:  # non-Windows
        return tuple(values)