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

1. Have you considered using a design table for this function? Excel can do random numbers, and generating new configs is one of the main functions of design tables.

2. Sounds like you're just having issues getting a random number in a certain range? Rand returs a random number in the range 0 to 1. To make this number between 0 and 10, simply multiply by 10. To make it between 10 and 20, simply add 10 to the previous step. If it needs to be an integer (or any other precision), just Round the result.