I’m not as skeptical of AI as many here 
Writing code completely mindlessly doesn’t work right now. But I use this method for simple macros, either entirely or for modules:
I write a very detailed prompt. It’s not like, “I need a macro that will establish an equation relationship between two selected sizes.”
I describe in detail which functions need to be used to obtain the “size path” and write the equation.
And once all this is done, the code works, even on the first try.
*I made the
form myself, placed the Controls myself, and immediately described their names, what they do, and how they react to events in the AI prompt.
Here’s a specific example of how I wrote a promt for this macro:
Solidworks VBA macro. I have a form called FormDim with ShowModel = False. After running the macro, it immediately displays and remains open until it’s closed. The user continues working in the Solidworks shell, occasionally accessing the form to perform the macro’s functionality. The form has four control groups, with the description of one group being:
Button CB_ADD1, Button CB_GET1, Textbox TB_WAY1, and Textbox TB_VAL1.
The other groups have indices 2, 3, and 4.
When the CB_GET1 button is clicked, if a dimension is selected in one of the Solidworks programs, the path to that dimension (e.g., “D1@EJEKTOR”) is copied to TB_WAY1, and the value of that dimension in mm is displayed in TB_VAL1.
When you press the CB_ADD1 button, if TB_WAY1 is not empty (e.g., “D1@EJEKTOR”) and a dimension is selected in one of SolidWorks, an equation is created for the selected dimension’s value, which is set to the value in TB_WAY1 (example: =“D1@EJEKTOR”).
If you click TB_VAL1, TB_WAY1 is cleared.
Here’s part of my code from another macro for finding the name of a selected dimension:
Set swSelMgr = swModel.SelectionManager
selCount = swSelMgr.GetSelectedObjectCount
' Check if an object is selected
If selCount < 1 Then
swApp.SendMsgToUser2 "Nothing selected", 1, 2
Exit Sub
End If
found = False
' Iterate through all selected objects
For i = 1 To selCount
selType = swSelMgr.GetSelectedObjectType3(i, -1)
' Check if the object is a dimension (swSelDIMENSIONS = 14)
If selType = 14 Then 'swSelDIMENSIONS
Set obj = swSelMgr.GetSelectedObject6(i, -1)
Set swDispDim = obj
Set swDim = swDispDim.GetDimension
' Check if we got the Dimension
If Not swDim Is Nothing Then
dimName = swDim.FullName
If InStr(dimName, "@") > 0 Then
' Find the position of the last "@"
atPos = InStrRev(dimName, "@")
' Trim string to the last "@"
If atPos > 0 Then
dimName = Left(dimName, atPos - 1)
If dimName <> "" Then
dimName = """" & dimName & """"
found = True
Exit For ' Exit, as we found the first dimension
End If
End If
End If
End If
ElseIf selType = 20 Then 'swSelCOMPONENTS
Set obj = swSelMgr.GetSelectedObject6(1, -1)
Set swComp = obj
rawName = swComp.Name2
' Extract only the name of the last component in the hierarchy
rawName = Mid(rawName, InStrRev(rawName, "/") + 1)
' Search for the position of the last hyphen and trim the name to it
dashPos = InStrRev(rawName, "-")
If dashPos > 0 Then
dimName = Left(rawName, dashPos - 1)
Else
dimName = rawName ' If there is no hyphen, take as is
End If
found = True
Exit For ' Exit, as we found the first dimension
End If
Next i
' If dimension is found add it to TB_WAY[1-4]
When you press CB_ADD1, use .GetEquationMgr to get the equation manager and create a new equation.