1 Reply Latest reply on Feb 25, 2018 7:22 PM by Solid Air

    Rename all features in a part

    Abc Cba


      After perofrming SaveAsPart to a big assembly I got a part file with thousands of surface features.

      They all bare the names of their original model files.

      I wish to batch rename all features with incremental numerator .

      Using IFirstFeature gets me runtime error 91 :"object variable or With block varibale not set"


      Please assist.

        • Re: Rename all features in a part
          Solid Air

          Most of the time the message means the object has not been set.  Without seeing your code, it is very difficult to figure out what is wrong.  What language are you writing your code in?  I only write in VBA so I have included some code that I wrote in hope that it helps you.


          Dim swApp As SldWorks.SldWorks

          Dim swDoc As SldWorks.ModelDoc2

          Dim swFeat As SldWorks.Feature


          Sub main()


              Dim NameIndex As Long


              Set swApp = Application.SldWorks

              Set swDoc = swApp.ActiveDoc


              NameIndex = 1


              Set swFeat = swDoc.FirstFeature


              Do Until swFeat Is Nothing


                  If swFeat.GetTypeName2 = "RefSurface" Then


                      swFeat.Name = "New Name" & NameIndex


                      NameIndex = NameIndex + 1


                  End If


                  Set swFeat = swFeat.GetNextFeature




          End Sub