AnsweredAssumed Answered

How to batch rename configurations?

Question asked by Grant Kirkland on Jan 24, 2018
Latest reply on Jan 26, 2018 by Grant Kirkland

I'm trying to write a VBA macro to iterate through all configurations and rename (remove characters from existing string).

 

For example, I want

 

0.2500-20x0.375

0.2500-20x0.500

0.2500-20x0.750

 

to be

 

0.375

0.500

0.750

 

I found and modified the following macro to iterate through the configurations on the SW VBA help page BUT it will not actual rename the configuration?

What am I missing?

 

'--------------------------------------

' Preconditions:

' 1. Open a part or assembly.

' 2. Open the Immediate window.

'

' Postconditions:

' 1. Iterates through all configurations.

' 2. Examine the Immediate window.

'---------------------------------------------------------

Option Explicit

Sub main()

    Dim swApp As SldWorks.SldWorks

    Dim swModel As SldWorks.ModelDoc2

    Dim vConfNameArr As Variant

    Dim sConfigName As String

    Dim nStart As Single

    Dim i As Long

    Dim bShowConfig As Boolean

    Dim bRebuild As Boolean

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Debug.Print "File = " + swModel.GetPathName

    vConfNameArr = swModel.GetConfigurationNames

    For i = 0 To UBound(vConfNameArr)

        sConfigName = vConfNameArr(i)

        Debug.Print "  Old Configuration Name = " & sConfigName

        sConfigName = Right(sConfigName, Len(sConfigName) - 10)

        bShowConfig = swModel.ShowConfiguration2(sConfigName)

        Debug.Print "  New Configuration Name= " & sConfigName

        bRebuild = swModel.ForceRebuild3(False)

    Next i

End Sub

Outcomes