Marc Kane

Random global variable value

Discussion created by Marc Kane on Feb 14, 2020
Latest reply on Feb 16, 2020 by Rob Edwards

Hi guys, I am quite new to SW macros, and I would like to make a macro that will open an existing part with two global variables (A and B) already set, and then randomly generate their values in range from lets say 10 to 20, to make a new configuration and then write those values in an excell sheet.

I believe something like this would be ok for getting a known value, but im having troubles with generating a random value from a specific range.

Any help would be much appreciated.

 

    Dim SwApp           As SldWorks.SldWorks

    Dim Part            As SldWorks.ModelDoc2

    Dim swEquationMgr   As SldWorks.EquationMgr

 

    Set SwApp = Application.SldWorks

    Set Part = SwApp.ActiveDoc

    Set swEquationMgr = Part.GetEquationMgr

    swEquationMgr.SetEquationAndConfigurationOption 0, """A"" = 5", swAllConfiguration, Empty

End Sub

Outcomes