Skip to content

execute_macro runs VBA source, when the server allows it - #246

Merged
andrewbartels1 merged 11 commits into
mainfrom
feat/vba-source
Nov 18, 2026
Merged

andrewbartels1 merged 11 commits into
mainfrom
feat/vba-source

Conversation

@andrewbartels1

Copy link
Copy Markdown
Owner

Closes #96 once the live check passes. Merge #245 first; until then this PR also shows #245's commits.

execute_macro runs VBA source, when you allow it (queue item 26)

generate_vba_* writes VBA, and execute_macro could only run a macro file, so "write a macro and run it" needed a hand step in the VBA editor. Your live run of #244 showed that RunMacro2 runs a plain-text .swb like a binary .swp. So VBA source can be saved as a .swb and run, and no binary file has to be built.

  • execute_macro takes vba_source in place of macro_path. The text is written to <temp>/solidworks_mcp/macros/vba-<random>.swb and run with the dialog watchdog.
  • The reply gives source_file and repeats the vba_source that ran.
  • Off by default, as you chose. It runs only when the server is started with SOLIDWORKS_MCP_ALLOW_VBA_SOURCE=1. Otherwise the call is refused as vba_source_off, and nothing is written or run. The hint tells the agent to ask you rather than set it.
  • Only one source is accepted per call. Text that can't be saved as Windows-1252 is refused.
  • The installation guide has a new section on the setting and its risk. The catalog entry is updated.

Checks

  • Unit tests:

    • allowed: the file is written and run, and the reply repeats the source;
    • refused: nothing is written;
    • the setting is off by default and read from the environment;
    • two sources are refused;
    • a bad character is refused.
  • 4,294 unit tests pass at 100% coverage; ruff and mypy are clean; the docs build in strict mode.

  • Live: not run yet. tests/live/test_live_sw_macro_source.py runs the source with the setting on, where one sketch should be added, and then off, where it should be refused with nothing changed.

    powershell -ExecutionPolicy Bypass -File tests\scripts\live_demo.ps1 -Test tests/live/test_live_sw_macro_source.py

andrewbartels1 and others added 11 commits November 16, 2026 22:48
make typecheck runs mypy over the package (checked as on Windows), and CI
runs it before the tests. The fixes change no behaviour, apart from one
fault mypy found: dimension layout raised TypeError for a leader with no
lines when asked to place it inside its view; it now goes outside. Every
type: ignore names its error code, checked by a test. Queue item 17, #157.
…stants library

The API index now also reads swconst.tlb (983 enums on SolidWorks 2026;
index format 2.1, so a saved index is rebuilt once). get_api_enum takes an
enum's name or a member's and returns the enum's members and integer
values. Checked live: swUnitSystem_IPS is 3. Named under the tool-naming
rule (get_, reads one thing). Queue item 23, #95. 140 tools.
They were written as a literal \n, so the shell saw an unfinished if.
CI's environment has no PIL, faiss or sentence_transformers, and its
pydantic doesn't need the ignore on the annotated-union TypeAdapter.
tests/integration/test_tool_catalog.py fails when a registered tool has no
entry on its family's page, an entry's parameter table doesn't list exactly
the tool's inputs, or its sample call isn't one the tool's input model
accepts. Entries for the 20 tools that had none, about 30 stale tables and
samples fixed, a Server Admin page. The generator that overwrote the
hand-written pages is removed, with the harness tests that read its JSON
(always skipped in CI). Queue item 24, #156.
While execute_macro runs, a watchdog thread (Win32 window calls only, no
COM) looks for a dialog the SolidWorks process opened. One still open after
dialog_timeout seconds (30) is answered with Cancel, or its only button,
or closed when it has none; the run then fails as macro_waited_for_user,
naming the dialog and its answer. A Yes/No prompt is left for the user and
logged. Unit-tested; the live check is written for the user's run.
Queue item 25, #97.
A macro that waits for the user no longer hangs the server
With SOLIDWORKS_MCP_ALLOW_VBA_SOURCE=1, execute_macro takes vba_source:
the text is written to a .swb under the temp folder and run like a macro
file, with the dialog watchdog; the reply names the file and repeats the
source. Off by default (the user's choice): VBA can do anything the user
can, so the call is refused as vba_source_off and nothing is written.
Queue item 26, #96.
@andrewbartels1
andrewbartels1 merged commit 235393c into main Nov 18, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(vba): generate a runnable binary .swp from VBA source

1 participant