2 Replies Latest reply on Aug 15, 2016 8:47 PM by Alin Vargatu

    Macro: Find and Replace text in order to rename Features in Bulk

    Alin Vargatu

      Do you know if there is already a macro that can run a Find and Replace operation on a whole feature tree?


      I would like to be able to rename features in bulk, by replacing strings of characters.


      Also with the new option in SW2016 to rename components in the assembly, I would like to be able to do the same thing in an assembly for renaming components.

        • Re: Macro: Find and Replace text in order to rename Features in Bulk
          Viktor Bovzdarenko

          Hi Alin

          This macro is renaming feature tree for parts. If the macro is launched for assemblies then the components would be renamed only in assembly and not propagated to model name


          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Const STR_FIND_WHAT As String = "Sheet"

          Const STR_REPLACE_WITH As String = "SHEET"

          Sub main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Dim swFeatures As Variant: swFeatures = swModel.FeatureManager.GetFeatures(False)

              Dim i As Integer

              Dim s As String: s = ""

              For i = 0 To UBound(swFeatures)

                  Dim swFeature As Feature: Set swFeature = swFeatures(i)

                  If InStrRev(swFeature.name, STR_FIND_WHAT) > 0 Then

                      s = s & "feature : '" & swFeature.name

                      swFeature.name = Replace(swFeature.name, STR_FIND_WHAT, STR_REPLACE_WITH)

                      s = s & "' is renamed to : '" & swFeature.name & "'." & vbNewLine

                      Debug.Print s

                  End If

              Next i

              If (s <> "") Then

                  MsgBox s

              End If

          End Sub