Skip to content
Back to skills

Solidworks Macro Fallback

ASecurity

Use when a SolidWorks API call through the MCP bridge needs a ref/out parameter or a COM object argument (limit mates, gear mates, AddMate5, ModifyDefinition), and only after the user has agreed to macros being used.

  • 5 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 7, 2026
ai-agentsbashapi

Works with

  • api
  • mcp

Security analysis

A100/100

Scanned November 7, 2026

npx -y skills add Cloud-Cad-Ai/solidworks-mcp --skill solidworks-macro-fallback --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Solidworks Macro Fallback?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Solidworks Macro Fallback
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/cloud-cad-ai-solidworks-macro-fallback/badge)](https://www.skillsdirectory.com/skills/cloud-cad-ai-solidworks-macro-fallback)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: "solidworks-macro-fallback"
description: "Use when a SolidWorks API call through the MCP bridge needs a ref/out parameter or a COM object argument (limit mates, gear mates, AddMate5, ModifyDefinition), and only after the user has agreed to macros being used."
---

# Macro fallback for calls the bridge cannot make

The list of calls the bridge cannot make is in `solidworks-bridge-tool-selection`. This skill is the workaround: a text macro run through the legacy RunMacro.

## Ask first
Macros run code inside the user's SolidWorks, are hard to verify through the bridge, and have failed with type-mismatch errors in real runs. Before writing one:
- Tell the user which call needs a macro and what the alternative is (design around it, or leave it as an open item).
- Use a macro only if the user agrees. If the user has said not to use macros, don't; record the item as open. A user constraint applies to every remaining step, not just the current one.

## Workaround: text macro + legacy RunMacro
1. Write a SolidWorks Basic macro as plain text with extension `.swb` into the project (e.g. `05_CAD/Macros/NAME.swb`, using device_bash) so the user can re-run it. Use **CRLF line endings** for the macro and any data file it reads; LF files were read as one line and silently did nothing.
2. Template:
```
Dim swApp As Object
Dim Part As Object
Sub main()
    Set swApp = Application.SldWorks
    Set Part = swApp.ActiveDoc
    Dim ok As Boolean
    Dim errStat As Long
    Dim m As Object
    Part.ClearSelection2 True
    ok = Part.Extension.SelectByID2("Front Plane@Comp-1@AsmName", "PLANE", 0, 0, 0, False, 1, Nothing, 0)
    ok = Part.Extension.SelectByID2("Right Plane", "PLANE", 0, 0, 0, True, 1, Nothing, 0)
    Set m = Part.AddMate5(5, 0, False, nominal, maxAbs, minAbs, 1, 1, 0, 0, 0, False, False, 0, errStat)
    Part.ClearSelection2 True
    Part.EditRebuild3
End Sub
```
   AddMate5 with type 5 (distance) and different upper/lower limits creates a LimitDistance mate. Values in metres. Do one mate (or one small, closely related group) per macro, so a failure has one cause.
3. Make sure the target document is active (app ActivateDoc(title)), then run: app invoke RunMacro("full\\path\\NAME.swb", "", "main"). It returns true when the macro ran.
4. **Verify, never assume.** A RunMacro call that reported an error or "RPC server unavailable" may still have run: re-read the mate list before running it again, or you create duplicates. Then read the result: doc FeatureByName("LimitDistance1") → GetSpecificFeature2 → get_property MinimumVariation / MaximumVariation (offsets from nominal, metres), and check the mate's error code.

## Use the macro route for (with the user's agreement)
- Limit, gear and other advanced mates; any AddMate5 / AddDistanceMate need.
- Anything needing out parameters or object arguments.

Not for routine work the bridge can already do: a macro saves round trips but hides failures, and its values are not linked to the design state.

Equations that need deleting cannot be fixed by macro either in practice; rebuild the document instead (see the bridge skill).

## Note in the deliverable
Values hard-coded in a macro are not linked to the design state or the global-variables file. Tell the user which macro to edit and re-run when a driving parameter changes.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.