4 Replies Latest reply on Jun 8, 2018 4:31 PM by Daniel Muller

    Macro to rename configurations by the filename

    Daniel Muller



      I work in a medical company using Solidworks 2018. I would like to save a lot of time for me and my team using a macro. I found this thread : rename configs and derived configs using find replace macro but it's not exactly that I would like.


      The aim of the macro will be to rename the configurations of a part with a function like "find and replace". Usually, we create prototype parts with this type of configurations : AB18_1234_0X and after the first series of prototype, we convert all the parts manually (several hundred) with a customer designation like 5678_9123_0X .

      Old partNew part


      - Sometimes we have only 2 operations of machining, so 2 configurations, and sometimes we have 3, 4 or 5 configurations.


      - The end of the configurations (the 3 last characters) must be always the same between old part and new part ("_00 ; _01 ; _02 ; _03...")


      - Only the 9 first characters must change (XXXX_XXXX) and must be extract from the 9 first characters of the part name (we rename manually the part name in windows explorer) which is always composed of "XXXX_XXXX_00". Also the end of the part name (3 last characters) is always the same ("_00").


      - If we can also update the "description of the configuration" with the same string than the configuration it will be nice :



      Me and my team thank you in advance,



        • Re: Macro to rename configurations by the filename
          Deepak Gupta

          Try these codes


          Option Explicit

              Dim swApp As SldWorks.SldWorks

              Dim swModel As SldWorks.ModelDoc2

              Dim vConfNameArr As Variant

              Dim i As Long

              Dim swConfig As SldWorks.Configuration


          Sub main()


              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc


              vConfNameArr = swModel.GetConfigurationNames

              For i = 0 To UBound(vConfNameArr)

                Set swConfig = swModel.GetConfigurationByName(vConfNameArr(i))

                  swConfig.Name = Left(swModel.GetTitle, 9) & Right(swConfig.Name, 3)

              Next i


          End Sub