AnsweredAssumed Answered

Macro: Create configs of range of sizes - loop problems

Question asked by Ben Richardson on Mar 5, 2020
Latest reply on Mar 5, 2020 by Ben Richardson

I am trying to create a macro that will generate configurations of different sizes from 15mm up to 90mm in steps of 5mm, which also changes the scaling dimension (D1@SKetch1) to the same value as the config name. I have gotten this to work creating a single configuration but now that I have introduced a loop to create them all its appears to be in an endless loop. Im also not sure if integer is the right variable type, decimal is giving errors.


Here is the code:

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim scaleDimension As Object
Dim size As Integer

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

size = 0.015 'set lowest size for D1@Sketch1 - 15mm

While size <> 0.09 'until size = 90mm

    boolstatus = Part.AddConfiguration2(size & "mm", "", "", True, False, False, True, 256) 'create configuration
    boolstatus = Part.Extension.SelectByID2("Boss-Extrude1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0) 'select boss extrude 1
    Part.FeatEdit 'edit sketch
    Set scaleDimension = Part.Parameter("D1@Sketch1") 'Change scaling dimension to config name value
    scaleDimension.SystemValue = size 'input value
    Part.SketchManager.InsertSketch True 'close sketch
    size = size + 0.005

End Sub

Any help appreciated!