Generate VBA Code
generate_vba_codeWrite a VBA macro skeleton for a described SolidWorks operation, including connection, document type check and optional error handling, with the operation left as a TODO starting point.
Instructions
Write a VBA macro skeleton for an operation you describe: the SolidWorks connection, a check of the active document's type and optional error handling, with the operation itself left as a TODO.
Use it as a starting point for a custom macro. For a complete macro for a
specific feature, use a generate_vba_* tool (extrusion, revolve, mates,
drawing views, batch export). The macro reports through Debug.Print, never a
dialog, so it runs without waiting on anyone: save it as a .swb file and run it
with execute_macro (its Sub main() calls the Sub named sub_name; SolidWorks
runs a .swb macro only through main). It stops, printing why,
when the active document isn't target_document. Read-only. Nothing runs in
SolidWorks. Returns: vba_code with code, sub_name, operation,
target_document, lines_of_code and includes_error_handling.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"input_data": "<input_data>"
},
"name": "generate_vba_code"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input_data | Yes | The macro to write. Nothing is required: give `operation_description` (it also names the Sub) and `target_document` (Part, Assembly or Drawing); `include_error_handling` is on by default. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||