1Today's goals
- Write a precise prompt for a SolidWorks macro
- Recognise invented API calls and logic bugs
- Review with a checklist and test on copies
- Know what not to paste into an AI tool
2Draft fast, check slowly
AI assistants (Claude and others) are good at the shape of a macro: loops, file handling, error checks, comments. They are less reliable on exact SolidWorks API names, argument order and version differences — they may produce a plausible call that does not exist. Treat AI code like code from a new colleague: useful, reviewed before use.
Prompt template
You are helping me write a SolidWorks VBA macro (.swp) for SolidWorks [2024]. Goal: [export every .SLDPRT in a folder to STEP AP214 in the same folder]. Inputs: folder path in a constant at the top. Files: [parts only]. Rules: - Use only methods documented in the SolidWorks API Help; name the interface for each call. - Check every object for Nothing before using it; print errors and warnings codes. - Never delete or overwrite source files. Close each document after use. - Add a DRY_RUN constant: when True, only list what would be done. - Comment each block in plain English. Finish with a list of API calls used, so I can check each one in API Help.
3Do it in SolidWorks
- Write your prompt with the template; ask your approved AI assistant for the macro.
- Paste it into a new macro. Turn on
Option Explicitand Debug ▸ Compile VBAProject — compile errors catch invented names and missing variables. - Look up every API call it lists in Help ▸ API Help: interface, arguments, return value.
- Run with DRY_RUN = True on a copy folder. Read the list.
- Run for real on the copy. Open three outputs and check them.
- Ask the AI to explain any line you do not understand — then confirm in API Help.
- Save the reviewed macro with a header block and a note "reviewed by / date".
4Lab: bug hunt
An AI-drafted macro with four real problems — including one invented API method. Find them before you check.
5Pro tips and common mistakes
- Compile first: Method or data member not found usually means an invented or wrong-interface call.
- Ask for small macros and combine them yourself; long AI programs hide more mistakes.
- When the AI fixes a bug, re-run the whole test — fixes often break something else.
- Keep a library of reviewed macros; reuse beats regenerating.
6Practice
Ask an AI assistant for a macro that renames the custom property PartNo to PartNumber in every part of a folder, keeping the value. Review it with the checklist above and the lab's four bug types, test on copies, and record what you had to fix.
7Quick quiz
Five questions. Click an answer — you get the explanation straight away.