## Does SolidWorks have APIs that can modify the values of global variables in SolidWorks equations?

Does solidworks have APIs that can modify global variables in solidworks equations?Please somebody answer this question...

Does solidworks have APIs that can modify global variables in solidworks equations?Please somebody answer this question...

This macro sets the Global Variable "A" equals to 100. Just create this variable in your Equation Manager and run the macro:

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Dim swEqMgr As SldWorks.EquationMgr

Set swEqMgr = swModel.GetEquationMgr

Dim i As Integer

For i = 0 To swEqMgr.GetCount - 1

If Trim(Split(swEqMgr.Equation(i), "=")(0)) = """A""" Then

swEqMgr.Equation(i) = """A""=100"

End If

Next

End Sub

______________________

Regards,

**Artem Taturevych***Application Engineer at Intercad*Tel: +61 2 9454 4444

Hi Artem,

Thank you for the quick response..

I had already tried your way using Replace property,but the problem is:

*"If we have too many equations,accessing equations using index seemed to be an inappropriate way.Is there any other option for selecting equations using equation name?*Are you worrying about the performance? I do not think it will be a problem because you are just iterating through the list but not actually evaluates the values. However if this is the case and you are not happy with this the only way I can suggest is use cached equations. So you have a Dictionary where key is index and value is name or vice-versa. You should fill this when your add-in/macro runs and update this every time you get the EquationEditorPostNotifyEventHandler notification cause it means that user may changed something. I do not aware of any other solutions for that.

______________________

Regards,

**Artem Taturevych***Application Engineer at Intercad*Tel: +61 2 9454 4444

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Dim swEqMgr As SldWorks.EquationMgr

Set swEqMgr = swModel.GetEquationMgr

Dim i As Integer

'swEqMgr.Equation(0) = Chr(34) & "D1@Sketch1" & Chr(34) & "=30"

swEqMgr.Equation(0) = Replace(swEqMgr.Equation(0), "bbbb", "aaaa")

For i = 0 To swEqMgr.GetCount - 1

Debug.Print swEqMgr.Equation(i)

If Trim(Split(swEqMgr.Equation(i), "=")(0)) = """A""" Then

'swEqMgr.Equation(i) = """A""=100"

End If

Next

End Sub

In your example you are using 100 to update the value of A how can I set 100 to equal Cost in my example which will update the Cost per lb equation.

Thanks

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Dim swEqMgr As SldWorks.EquationMgr

Dim Cost As Integer

Set swEqMgr = swModel.GetEquationMgr

Cost = 20

Dim i As Integer

For i = 0 To swEqMgr.GetCount - 1

If Trim(Split(swEqMgr.Equation(i), "=")(0)) = """Cost per lb""" Then

swEqMgr.Equation(i) = """Cost per lb"" = Cost"

Debug.Print swEqMgr.Equation(i)

End If

Next

End Sub

This macro sets the Global Variable "A" equals to 100. Just create this variable in your Equation Manager and run the macro:

______________________

Regards,

Artem TaturevychApplication Engineer at Intercadhttp://intercad.com.au/

Tel: +61 2 9454 4444