2 Replies Latest reply on Jan 24, 2017 11:53 AM by Kevin Collins

    API - Reset to original Configuration After Cycling

    Kevin Collins

      Hi All,


      I am working on a macro to cycle through all configurations of a given document and force rebuild each one.  I found the code (below) for the basics on the SW API help site.  It works great except for one minor issue. 


      I need the macro to reset the active configuration to the original configuration (whichever was active when the macro was started) after it has rebuilt the last one. 


      Currently it will cycle through all configurations and, once the last one has been rebuilt it remains the active configuration.


      Please help!


      Here is the code I am working with:


      Sub main()

          Dim swApp As SldWorks.SldWorks
          Dim swModel As SldWorks.ModelDoc2
          Dim vConfNameArr As Variant
          Dim sConfigName As String
          Dim start As Single
          Dim i As Long
          Dim bShowConfig As Boolean
          Dim bRebuild As Boolean
          Dim bRet As Boolean
          Set swApp = CreateObject("SldWorks.Application")
          Set swModel = swApp.ActiveDoc
          Debug.Print "File = " + swModel.GetPathName
          vConfNameArr = swModel.GetConfigurationNames
          For i = 0 To UBound(vConfNameArr)
              sConfigName = vConfNameArr(i)
              bShowConfig = swModel.ShowConfiguration2(sConfigName)
              start = Timer
              bRebuild = swModel.ForceRebuild3(False)
              Debug.Print "  Configuration = " & sConfigName
              Debug.Print "    ShowConfig  = " & bShowConfig
              Debug.Print "    Rebuild     = " & bRebuild
              Debug.Print "    Time        = " & Timer - start & " seconds"
          Next i
      End Sub


      Thanks in advance!!