Recording macro values to global variables

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
Answers 7
DG
DG 2009-08-26 Best 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
SF 2009-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.
DG
DG 2009-08-26
Look at this macro. Not exact what you need but somehow close Rectangular Block (In Inches)
JB
JB 2009-08-26
I believe you can get to the global variables through the EquationManager interface.
SF
SF 2009-08-27

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

SF
SF 2009-08-27
Thanks for all the help. Artem this code works great.
KL
KL 2009-08-27
Kevin ... For future reference, please read the linked post for info on marking the correct answer.

https://forum.solidworks.com/thread/26552