Skip to content

feat(adapter): implement sweep and loft COM operations in pywin32_adapter #4

Closed

Description

@andrewbartels1

Problem / motivation

create_sweep and create_loft in src/solidworks_mcp/adapters/pywin32_adapter.py currently return an error immediately without attempting any COM call:

# pywin32_adapter.py ~L1052
return AdapterResult(
    status=AdapterResultStatus.ERROR,
    error="Sweep feature not implemented in basic pywin32 adapter",
)

Sweep and loft are common SolidWorks features used in mechanical parts (helical springs, airfoils, bottles, transition fittings). Without them, the MCP server cannot execute many reconstruction or design workflows. They are tracked in SWChecklist.md backlog and referenced in the feature-tree reconstruction skill.

Proposed solution

Files to change

  • src/solidworks_mcp/adapters/pywin32_adapter.py — replace the stub bodies with real COM calls
  • nearest test file in tests/ — add branch-coverage tests for both operations
  • src/solidworks_mcp/adapters/mock_adapter.py — return a sensible stub SolidWorksFeature

Parameters already defined in base.py

class SweepParameters(BaseModel):
    path: str                    # named sketch / edge for the sweep path
    twist_along_path: bool = False
    twist_angle: float = 0.0
    merge_result: bool = True

class LoftParameters(BaseModel):
    profiles: list[str]          # ordered list of section sketch names
    guide_curves: list[str] | None = None
    start_tangent: str | None = None
    end_tangent: str | None = None
    merge_result: bool = True

COM API references

  • Sweep: IFeatureManager::InsertProtrusionSweep2 — requires active profile sketch + named path
  • Loft: IFeatureManager::InsertProtrusionBlend2 — accepts an array of profile sketch names; guide curves passed via direct param array

Reference implementation pattern

Follow create_revolve (L964 in pywin32_adapter.py) which:

  1. Guards on self.currentModel
  2. Defines an inner _operation() closure
  3. Calls featureManager = self.currentModel.FeatureManager
  4. Wraps in self._handle_com_operation(name, closure)
  5. Returns a SolidWorksFeature dataclass on success

Acceptance criteria

  • create_sweep returns AdapterResultStatus.SUCCESS and a SolidWorksFeature when a valid profile sketch + path are active
  • create_loft returns AdapterResultStatus.SUCCESS with >= 2 profiles
  • Both return ERROR with a descriptive message when currentModel is None
  • Mock adapter returns a stub SolidWorksFeature (not an error) for both
  • Unit tests cover: no-model guard, success path, and parameter edge cases
  • dev-test (non-solidworks_only) passes

Out of scope

  • Thin-wall sweep/loft variants
  • Swept/lofted cut operations (separate issue)
  • Sheet metal sweep

References

  • src/solidworks_mcp/adapters/pywin32_adapter.py L964 (create_revolve reference)
  • src/solidworks_mcp/adapters/base.py L250–L284 (parameter schemas)
  • docs/planning/ROADMAP_2026_2027.md Q2 2026 Foundation phase
  • SolidWorks API: IFeatureManager::InsertProtrusionSweep2, InsertProtrusionBlend2

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions