2 Replies Latest reply on Jan 11, 2019 2:36 PM by Paul Flores

    Macro to renumber BOM in numerical order

    Paul Flores

      We typically re-use projects when possible as a starting point for similar projects.  I typically open a multi-sheet drawing and use Pack and Go to copy and rename parts/assemblies/drawings to a new folder.  Whenever I do this, the BOMs stay linked to their correct assemblies, however the numbers following "Bill of Materials" in the feature tree have numbers that aren't in numerical order because I'll delete unnecessary pages (see the attached image).


      Is there a macro to renumber these from

      Bill of Materials17

      Bill of Materials19

      Bill of Materials23




      Bill of Materials1

      Bill of Materials2

      Bill of Materials3


        • Re: Macro to renumber BOM in numerical order
          Deepak Gupta

          You can try the following codes which I had written few weeks back for a friend. I've not added any error handling though.


          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim swDrawing As SldWorks.DrawingDoc

          Dim swFeat As SldWorks.Feature

          Dim swBOM As SldWorks.Feature

          Dim i  As Integer


          Sub Main()


              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swDrawing = swModel

              Set swFeat = swDrawing.FirstFeature

              i = 1

              Do While Not swFeat Is Nothing

                  If "BomFeat" = swFeat.GetTypeName Then

                      Set swBomFeat = swFeat.GetSpecificFeature2

                      Set swBOM = swBomFeat.GetFeature

                      swBOM.Name = "Bill of Materials" & i

                      i = i + 1

                  End If

                  Set swFeat = swFeat.GetNextFeature



               End Sub