Hi all!
I'm having some trouble using VBA API with SolidWorks 2015 Premium.
I have a Project and a VBA marco in which i want just to replace the value of the global variables and suddenly rebuild the project.
There are 2 global variable Diam=5 and Height=5 and i want to replace their value.
My Macro is this:
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim swModel As SldWorks.ModelDoc2
Dim swEqnMgr As SldWorks.EquationMgr
Sub main()
Dim longEquation As Long
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set swApp = Application.SldWorks
Set swEqnMgr = Part.GetEquationMgr
'Delete old variable and add a new one with the same name
swEqnMgr.Delete 2
swEqnMgr.Add2 2, ("""Diam"" = 10"), False
swEqnMgr.Delete 3
swEqnMgr.Add2 3, ("""Height"" = 15"), False
'Evaluate all equations
Dim ret As Integer
ret = swEqnMgr.EvaluateAll()
MsgBox "Diam value : " & swEqnMgr.Value(2), vbOKCancel
MsgBox "Height value : " & swEqnMgr.Value(3), vbOKCancel
'Rebuild
boolstatus = Part.EditRebuild3()
MsgBox "rebuild : " & boolstatus, vbOKCancel
End Sub
The main problem is that the EditRebuild3 doesn't work properly and i don't know why.
Suddenly the macro run, i go to "Manage equation" panel and see that the macro change correctly the value, and pressing the rebuild button seems do it work properly.
Would you please help me? (i have attached all you need to run the macro)
Thanks a lot.
Best Regards
SolidworksApi macros