Does anyone know if it is possible to change global properties in a part or assembly with a macro? I am trying to have users input a few values and use those to build the model. SolidworksApi macros
Answers7
DG
DG2009-08-26Best Answer
Yes I did something similar long back. The macro will ask for some values from user and then change those values and rebuild the part.
SF
SF2009-08-26
Do you know what the syntax is for changing the values in solidworks? I've searched for the syntax and i can't find it.
Kevin,
Josh is correct. The IEquationMgr interface can do this.
Please refer the following macro which increases twice the value of first global variable:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swEqnMgr As SldWorks.EquationMgr
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swEqnMgr = swModel.GetEquationMgr
Dim eqn As String
Dim val As Double
Dim newVal As Double
Dim sVal As String
eqn = swEqnMgr.equation(0)
val = swEqnMgr.Value(0)
newVal = val * 2
sVal = val
eqn = Left(eqn, Len(eqn) - Len(sVal))
eqn = eqn & newVal
swEqnMgr.equation(0) = eqn
swModel.ForceRebuild3 False
End Sub
https://forum.solidworks.com/thread/26552