ChatGPT writes SolidWorks VBA macros fast, but more than half of what free ChatGPT gave us would not even compile. In the TechDraw AI test on 1 December 2026 (TechDraw AI is the AI tool that turns photos, sketches and descriptions into technical drawings and exact CAD parts), we gave free ChatGPT 12 everyday SolidWorks jobs and checked every API call in its macros against the SOLIDWORKS 2026 API. Only 4 answers were clean. 7 contained a macro that uses a method or constant that does not exist, and 1 compiled but would have exported only the first file in a folder. Pasting the error back into the chat fixed every one we sent back. Below are the 13 prompts we now use, each with what happened when we ran it.
Our articles are still written by humans!
Get human written articles in your Google feed.
What happened in our test
We wrote 12 prompts for jobs SolidWorks users automate all the time: batch STEP export, flat patterns to DXF, custom properties, a BOM to CSV, mass properties, a new drawing with views. Each prompt asked for early binding and checked return values, the way a careful engineer would ask. Then we checked every macro two ways.
- Against the API itself. A script listed every SOLIDWORKS call in each macro and looked it up in the SOLIDWORKS 2026 interop assemblies, the files Visual Studio and VBA read the API from. It flags a member that does not exist on that object, a wrong number of arguments and an enum value that does not exist. With early binding, VBA stops on each of those with
Compile error: Method or data member not foundbefore the macro does anything. - By reading it. A macro can compile and still do the wrong thing, so we read each one for logic: the loop, the file names, what it saves and what it leaves changed.
Free ChatGPT, 1 December 2026: first answer, and the answer after we pasted the error back
The pattern in the failures is consistent. ChatGPT never invented a whole fake API. It used a real member on the wrong object, or a plausible enum name one word away from the real one. That is exactly the kind of mistake you only see when the VBA editor refuses to run.

The one that worried us most is prompt 1, because it does not fail loudly. The macro calls Dir to check whether a STEP file already exists, inside a loop that walks the folder with Dir. VBA has only one Dir search at a time, so the inner call ends the outer one. The macro exports the first part, reports “1 exported, 0 failed” and stops. Nothing tells you the other files were skipped. Claude and Gemini both avoided it by collecting the file list first; Claude even wrote a comment saying Dir cannot be nested.
Every answer arrived in 18 to 56 seconds. The full prompts, the answers, the macros and our check results are in the raw data (zip) and results.csv.
The rules prompt to paste first
Every failure above maps to a rule. Paste this block at the top of a new chat, then add one of the job prompts below in the same message. Replace [YOUR VERSION] with your release, because a member added in 2025 will not compile in 2022.
You write SOLIDWORKS VBA macros for SOLIDWORKS [YOUR VERSION]. Follow these rules in every answer: 1. Early binding: declare every SOLIDWORKS object with its real type (Dim swModel As SldWorks.ModelDoc2), so the VBA editor catches a wrong member name before anything runs. 2. Use only methods, properties and enum values that exist in the SOLIDWORKS API for my version. After each API call add a comment with the interface it belongs to, for example ' IModelDocExtension.SaveAs3. If a member lives on another interface (BomTableAnnotation vs TableAnnotation, MassProperty vs MassProperty2), cast to that interface instead of guessing. 3. Never call Dir with arguments inside a loop that is driven by Dir. Collect the file list first, then process it. 4. Check every return value, and pass real Long variables for every Errors and Warnings argument. 5. Never save over or modify the source files. Write output files next to them, and never overwrite an existing output file. 6. If you change a user preference (export settings, units), store the old value and restore it, also when the macro fails halfway. 7. Give me the complete macro, then one sentence on how to run it. No explanation unless I ask.
Rule 1 matters more than it looks. With early binding, a wrong member is a compile error that appears before the macro touches a file. With As Object, the same mistake is a run-time error that can hit halfway through a batch, after some files are already written.
Export and batch jobs (1-4)
1. Batch export a folder of parts to STEP
Write a SOLIDWORKS VBA macro that asks me for a folder, collects all .SLDPRT files in it first, then opens each one silently and read-only, saves it as STEP AP214 with the same name in a subfolder called STEP, and closes it. Skip a part if its STEP file already exists. At the end show how many were exported and list the failures with the error code. Set the STEP AP214 preference only for the run and restore the old value.
In our test: gpt-6 wrote 355 lines that pass the API check, set AP214 correctly and opened parts read-only, then broke the folder loop with a nested Dir. When we said “it exported only the first part”, gpt-6-mini named the cause in one sentence and rewrote it with a collected file list. The prompt above asks for that from the start.
2. Save the open drawing as PDF and DXF
Write a SOLIDWORKS VBA macro that saves the active drawing next to the original file twice: once as one PDF with all sheets (use ExportPdfData), and once as DXF with every sheet as a separate DXF file named after the sheet. Stop with a clear message if the active document is not a drawing or has never been saved. Do not modify the drawing, and restore any DXF export setting you change.
In our test: the macro used swExportDataFileType_e.swExportDxfData, which does not exist; that enum has a single value, the PDF one. Naming ExportPdfData in the prompt points the model at the real interface.
3. Export a sheet metal flat pattern to DXF for laser cutting
Write a SOLIDWORKS VBA macro that exports the flat pattern of the active sheet metal part to a DXF next to the part, with the same name, for laser cutting. Use PartDoc.ExportToDWG2 with the sheet metal option and only the flat pattern geometry: no bend lines, no sketches, no library features, no forming tools, no bounding box. Explain the bitmask value in a comment. Stop with a clear message if the part has no sheet metal feature.
In our test: clean. gpt-6 used ExportToDWG2 with the sheet metal option and bitmask 1 (geometry only), which is what a laser cutter wants. Before you send the file, open it once and check the holes and the scale; our guide to why a DXF will not cut lists what to look for.
4. Save every configuration as an STL
Write a SOLIDWORKS VBA macro that activates each configuration of the active part in turn and saves it as a binary STL in millimetres, named <part name>_<configuration name>.stl next to the part, then returns to the configuration that was active at the start. Set the STL binary and unit preferences only for the run and restore the old values, also if the macro fails.
In our test: clean, and it stored and restored the binary and unit preferences, which most hand-written macros forget.
Properties, BOMs and mass (5-8)
5. Fill custom properties
Write a SOLIDWORKS VBA macro that fills the file-level custom properties of the active part or assembly with CustomPropertyManager: PartNo is the file name without extension, Description comes from an input box, DrawnBy is my Windows user name, and for parts Material is linked to the part's material so it updates by itself. Overwrite existing values. Check the result of every Add3 and Set2 call against the real swCustomInfoAddResult_e and swCustomInfoSetResult_e values.
In our test: gpt-6-mini compared results with swCustomInfoAddResult_Added and swCustomInfoSetResult_Updated. The real names are swCustomInfoAddResult_AddedOrChanged and swCustomInfoSetResult_OK. Claude made the same kind of slip in this job, with a third invented name. Enum values are where every model guessed.
6. Export the BOM table of a drawing to CSV
Write a SOLIDWORKS VBA macro that finds the first bill of materials table in the active drawing and writes it to a CSV next to the drawing, headers first, exactly as the table shows it, leaving out hidden rows. Get the BomTableAnnotation, then cast it to TableAnnotation for RowCount, ColumnCount, RowHidden and DisplayedText. Quote every cell for CSV. Stop with a clear message if there is no BOM.
In our test: this one failed on five lines. The macro read RowCount, ColumnCount, RowHidden and DisplayedText straight from BomTableAnnotation; in the API they belong to TableAnnotation. The cast is now in the prompt.
7. Mass properties report
Write a SOLIDWORKS VBA macro that reads the mass properties of the active part with IModelDocExtension.CreateMassProperty2 and the MassProperty2 interface: mass in kg, volume in cm³, surface area in cm² and the centre of mass in mm, converted from the SI values the API returns no matter what the document units are. Show them with 3 decimals. Stop with a message if no part is open or no material is assigned.
In our test: the unit conversions were right, but the macro declared the older MassProperty and then called Recalculate, which only MassProperty2 has.
8. List every component of an assembly with quantities
Write a SOLIDWORKS VBA macro that traverses the active assembly and all sub-assemblies, starting from the active configuration's root component (Configuration.GetRootComponent3), and writes a CSV next to the assembly with one row per unique part file and configuration: file name, configuration and total quantity. Skip suppressed components and components excluded from the BOM.
In our test: gpt-6-mini called GetRootComponent3 on the assembly document. It lives on the configuration, so the prompt now says where to start.
Drawings, equations and units (9-11)
9. Create a drawing with three views and an isometric
Write a SOLIDWORKS VBA macro that creates a new drawing of the active part on an A3 landscape sheet with the default drawing template, sets third-angle projection and scale 1:2 with Sheet.SetProperties2, inserts front, top and right views plus an isometric view top right, inserts the model dimensions marked for drawings, and saves the drawing next to the part with the same name. Give me one macro only.
In our test: ChatGPT answered with two complete macros in one reply. The first called Sheet.SetProjectionType with an enum swProjectionType_e and View.SetScale; none of the three exists. The second was clean and set third angle the real way, through SetProperties2. If you copy the first block you see, you get the broken one, hence “one macro only”. If you want the drawing without writing a macro at all, our guide to dimensioning a technical drawing covers what the views and dimensions should look like.
10. Change a global variable and rebuild
Write a SOLIDWORKS VBA macro that asks me for a new value of the global variable "Length" in the active part, changes it through the EquationMgr, rebuilds, and reports the old and new value. Find the variable by its name in quotes, ignoring spaces around the equals sign. Stop with a clear message if it does not exist.
In our test: the API calls are clean. The macro finds the variable by matching the equation text, and whether that text match holds depends on how your SolidWorks formats the equation, which we could not check without a SolidWorks seat. The prompt now asks it to ignore spaces.
11. Set document units to MMGS
Write a SOLIDWORKS VBA macro that sets the units of the active document to MMGS with swUnitSystem_MMGS, 2 decimal places for lengths and 1 for angles, and turns dual dimensions off. Use only swUserPreferenceIntegerValue_e, swUserPreferenceToggle_e and swUserPreferenceOption_e values that exist in my SOLIDWORKS version, and say in a comment which enum each one comes from.
In our test: two invented enum values, swDetailingAngularDimension and swDetailingRadialDimension. The real ones are swDetailingAngleDimension and swDetailingRadiusDimension. One word off, and the macro will not start.
Debug and fix prompts (12-13)
12. Find the bug in a macro
This SOLIDWORKS [YOUR VERSION] VBA macro should [WHAT IT SHOULD DO], but [WHAT HAPPENS INSTEAD]. Find every bug, explain each in one sentence, then give me the corrected complete macro with early binding. [PASTE THE MACRO]
In our test: we gave it a 9-line macro with three planted problems: a SaveAs call with 5 arguments instead of 6 and Nothing where the error variables go, a case-sensitive Replace on the file extension, and no check for a part that was never saved. gpt-6-mini found all three and the fix passes the API check.
13. Paste the error back (the one that fixed 7 of 7)
When I run it, VBA shows "[THE EXACT ERROR MESSAGE]" and highlights [THE HIGHLIGHTED WORD] in this line: [THE LINE]. Fix it and give me the complete corrected macro.
In our test: this is the prompt that worked. We sent it in the same chat for 6 compile errors and described the symptom for the silent Dir bug (prompt 9 already had a clean second version, so we left it). All 7 replies were clean on the API check, and each one fixed the actual cause instead of wrapping the line in On Error Resume Next. Two habits make it work: copy the error text exactly, and stay in the same chat so the model still has the macro.
Claude and Gemini on the same prompts
We sent the same 12 prompts once each to Claude Opus 5.5 and Gemini 4 Neon through their APIs and ran the same checks. Claude answered in 24 to 86 seconds. Gemini thought for 43 seconds to 5 minutes per answer, and its first answer to prompt 2 came back empty because its thinking used up the whole 32,000-token output limit; we sent that prompt again and scored the second answer.
First answers with no defect found by our API check and reading, out of 12
Read this with care. One run per prompt is a small sample, and the comparison is not equal: the two API models are paid, while free ChatGPT moved to its smaller model after three prompts. What the numbers do show is that no model was safe from guessing enum names, and that the gap closes after one round of error feedback. If you pay for one assistant for SolidWorks work, the first-try difference is real; if you use free ChatGPT, plan on prompt 13.
For connecting a model to SolidWorks itself rather than pasting code, see our guides to connecting ChatGPT to SolidWorks and connecting Claude to SolidWorks. If you also work in AutoCAD, the same approach for AutoLISP is in our ChatGPT prompts for AutoCAD.
Where ChatGPT stops
- It cannot see your model. ChatGPT in the browser does not know your feature names, configurations or templates. Put the names into the prompt.
- It cannot run what it writes. There is no SolidWorks in ChatGPT's sandbox, so every macro is untested until you run it. On the free plan it did not say so once.
- The model changes under you. The free plan answered with gpt-6 three times, then with gpt-6-mini. The chat does not show which one answered.
- Long macros are not better macros. ChatGPT's macros ran from 98 to 643 lines, with a check after nearly every call. The careful-looking ones still had the invented members.
- SolidWorks now has its own writer. LEO in SOLIDWORKS Design writes macros inside SolidWorks and opens them in the VBA editor. It needs the 3DEXPERIENCE platform connection and uses tokens. We did not test it; the video above shows it.
TechDraw AI and SolidWorks
TechDraw AI does not write SolidWorks macros, and we would rather say that plainly than pretend otherwise. TechDraw AI is our product, and it sits one step earlier, where a part only exists as a photo, a sketch or a sentence:
- A part from a description. AI CAD turns a written description with sizes into an exact CAD part with STEP, STL and 3MF downloads. The STEP opens in SolidWorks as a solid body you can dimension and change. It costs 80 credits per prompt on the Studio plan (€89 a month, 750 credits).
- A drawing from a photo or sketch. TechDraw AI turns a photo into a dimensioned technical drawing and a DXF that you can import into a SolidWorks sketch and extrude. A drawing costs 5 credits; the Starter plan is €29 for 120 credits, and the first generation is free.
- Inside Claude. The TechDraw AI MCP server works in Claude, Cursor and Codex. It does not work in the ChatGPT website.
Its limits are real too: the AI CAD output is a solid without a SolidWorks feature tree, and a drawing from a photo is only as exact as the sizes you give it.
Describe a part with its sizes and get a STEP file SolidWorks opens. Your first generation is free.
Try text to CADFAQ
Frequently asked questions
Can ChatGPT write SolidWorks macros?
Yes, but check them before you trust them. In the TechDraw AI test on 1 December 2026, free ChatGPT answered 12 SolidWorks VBA prompts. Only 4 answers were clean. 7 contained a macro that calls an API member or constant that does not exist, so the VBA editor would stop it with a compile error, and 1 compiled but would only have processed the first file in the folder. When we pasted the error message or the symptom back into the same chat 7 times, ChatGPT fixed it on the first try every time. TechDraw AI checked every macro against the SOLIDWORKS 2026 API but did not run them in SOLIDWORKS.
Is ChatGPT or Claude better for SolidWorks macros?
In the TechDraw AI test, Claude did better on the first try. The same 12 prompts gave 4 answers with no defect we could find from free ChatGPT, 11 from Claude Opus 5.5 through its API, and 11 from Gemini 4 Neon through its API. The comparison is not quite fair: the API models are paid, and free ChatGPT switched from gpt-6 to the smaller gpt-6-mini after three prompts. With one round of error feedback, ChatGPT reached the same result.
Does SolidWorks have its own AI that writes macros?
Yes. LEO, the virtual companion in SOLIDWORKS Design on the 3DEXPERIENCE platform, creates VBA macros from a prompt and opens them in the VBA editor, and you can ask it for changes in the same conversation. It arrived with the 2026 FD03 update and is part of SOLIDWORKS 2027. It needs a connection to the 3DEXPERIENCE platform, because the AI runs on Dassault's servers, and it is metered in tokens. On a classic desktop seat without that connection, ChatGPT or Claude plus the VBA editor is still the route.
How do I run a macro that ChatGPT wrote in SolidWorks?
In SolidWorks go to Tools > Macro > New, save the .swp file, and the VBA editor opens. Replace everything in the module with ChatGPT's code. Check Tools > References in the VBA editor: the SOLIDWORKS Type Library and the SOLIDWORKS Constant Type Library must be ticked, or every early-bound line fails. Then run main with F5, on a copy of your files first.
Is it safe to run a SolidWorks macro written by AI?
Mostly, if you read it first and run it on copies. A macro can save over files, delete them and change your user settings. In our test two ChatGPT macros changed system-wide export settings (STEP version, STL format and units) and both put them back, also when the macro failed, but that is easy to forget. Ask for macros that never save over the source files, restore every setting they change, and run them on a copy of the folder before the real one.
Can ChatGPT control SolidWorks directly?
Not from the website. ChatGPT in a browser writes code that you paste and run. The ChatGPT desktop app and Codex can connect to a local SolidWorks MCP server built by the community, which lets the model drive SolidWorks itself. Our guide to connecting ChatGPT to SolidWorks covers that setup.
Can TechDraw AI make SolidWorks files?
Not native SLDPRT files, and it does not write macros. TechDraw AI makes the inputs a SolidWorks user needs: an exact CAD part from a written description as STEP, which SolidWorks opens as a solid body, and a dimensioned 2D drawing or DXF from a photo or sketch, which you can import into a SolidWorks sketch. The first generation is free; a drawing costs 5 credits and an AI CAD part 80 credits on the Studio plan.
Sources
- SOLIDWORKS API Help: SOLIDWORKS Design API
- NuGet: Visiativ.SOLIDWORKS.Interop 34.0.0 (SOLIDWORKS API 2026 SP0 interop assemblies)
- Microsoft: Dir function (VBA)
- SOLIDWORKS: Generative macro creation with LEO
- 3DSwym: Eliminate tedious and repetitive tasks by automatically creating macros
- OpenAI: ChatGPT plans and pricing



