8 Replies Latest reply on Jan 11, 2018 9:51 AM by Matt Peneguy

    Renumber Sheet Names and Relabel View Labels

    Matt Peneguy

      In another thread I mentioned that I manually renumbered my sheet names.  I have the name linked to a field on the sheet.  This is a good way of ordering the sheets and since I have multiple files with multiple sheets for each project. But, I have to change a lot if a sheet is inserted.  Well, Deepak Gupta mentioned that I may want to create a macro.  I did just that by copying a macro from the help and modifying it.  I thought I'd post it in a new thread to make it easier to find... And here it is (I hope it doesn't offend anyone who knows how to properly code, but I will modify it if anyone sees anything wrong):

       

      Edit to Add:

      With guidance from Deepak Gupta I have modified the macro to first change the name of the sheets to a "dummy" name to prevent an error when renumbering the sheets if a sheet name already exists (if the above macro tries to name a sheet 2 and that name already exists, it fails).  Thanks Deepak!

      Dim swApp As SldWorks.SldWorks

      Dim swModel As SldWorks.ModelDoc2

      Dim swDraw As SldWorks.DrawingDoc

      Dim vSheetName As Variant

      Dim i As Integer

      Dim bRet As Boolean

      Sub main()

      Set swApp = Application.SldWorks

      Set swModel = swApp.ActiveDoc

      Set swDraw = swModel

       

      myNum = InputBox("Enter the first sheet number")

      If IsNumeric(myNum) = False Then

          MsgBox ("Enter a numeric value and retry")

          Exit Sub

      End If

       

      ' Rename the sheets to a dummy name

      RenameSheets ("99999999")

      RenameSheets (myNum)

      End Sub

       

      Sub RenameSheets(myName)

      vSheetName = swDraw.GetSheetNames

          For i = 0 To UBound(vSheetName)

          mynewNum = myName + i

          bRet = swDraw.ActivateSheet(vSheetName(i))

          Dim swSheet As Sheet

          Set swSheet = swDraw.Sheet(vSheetName(i))

          If (swSheet.IsLoaded) Then

             swSheet.SetName mynewNum

          Else

              Debug.Print (vSheetName(i) & " is not loaded.")

              End If

          Next i

      End Sub

       

      Edit to add2: Thanks to Deepak Gupta I copied the code written by Artem Taturevych and modified it to label past 26 views (A-Z).  It should handle AA-ZZ, now (I think that works out to 702 views).  A lot of workflows don't go past 26 views, but some of our drawing files do.  Anyone interested can see the attached file.

      Sorry Artem, my code is nowhere near as neat and tidy as yours, but what I kludged together should work.

        • Re: Renumber Sheet Names
          Deepak Gupta

          Thanks for putting it up here Matt. In addition to a proper sheet numbering, I also prefer to have my views numbered correctly as it bothers me much when 1st sheet has views 1, 2, 3, etc. and then next sheet has views 56, 57, 58, etc. So may be you can further combine the macro to rename views also (there is already a macro to do that).

            • Re: Renumber Sheet Names
              Matt Peneguy

              Please point me to that macro.  I have a drawing that has gone to view AA because I have added views and deleted them.  It would be very handy to have a macro that went through and renamed them A-Z.

              I just discovered a problem with my macro.  If I run it and start with say 100, it renumbers 100, 101, 102, etc.  If I rerun it with a start of 101, it doesn't work.  Problem there is that there is already a sheet named 101.  So, it fails. A quick and dirty way of handling it is to just run it with 200 or something else and then run it again with 101.  I could put another loop in and have it rename the sheets to something like XXXXXX1, XXXXXX2, XXXXXX3, then rename them properly.  Got any better ideas?

                • Re: Renumber Sheet Names
                  Deepak Gupta

                  Matt Peneguy wrote:

                   

                  I just discovered a problem with my macro. If I run it and start with say 100, it renumbers 100, 101, 102, etc. If I rerun it with a start of 101, it doesn't work. Problem there is that there is already a sheet named 101. So, it fails. A quick and dirty way of handling it is to just run it with 200 or something else and then run it again with 101. I could put another loop in and have it rename the sheets to something like XXXXXX1, XXXXXX2, XXXXXX3, then rename them properly. Got any better ideas?

                  Yes that's the way out to have he sheet name in required order

                   

                   

                  Please point me to that macro. I have a drawing that has gone to view AA because I have added views and deleted them. It would be very handy to have a macro that went through and renamed them A-Z.

                  Check macros here Rename All Section and Detail Views with API and Renaming Drawing View Via API  by Artem Taturevych

              • Re: Renumber Sheet Names
                John Stoltzfus

                Interesting Matt Peneguy - its always great to see other possibilities..

                 

                Not to take away what you posted - but to share how I have my workflow process setup, might be a lot of steps for some, but I like the trouble free completed project...

                 

                I have a few macros that I use to rename my sheets, for me it's rather a simple process, except if you have a part with multiple configurations.

                 

                1. In the Part or Assembly file I run a Macro to change the Configuration Name from Default to the Part/Assembly File name.

                2.  In the drawing file I run a Macro to change the sheet tab name to the Configuration Name (if I have multiple configurations for a part then I would change the sheet tab manually) (Rename All Sheets written by Deepak Gupta

                3.  Then I run a macro to Rebuild the Reference File written by Deepak Gupta - This macro opens the part or assembly for every view in the drawing, and rebuilds and closes...  Takes a little time to run this macro but it guarantees that the drawing view is updated

                4.  Then I run the Reload All Sheet Formats - just to make sure I have the current format shown (Written by Deepak Gupta - Edited by Garrett Hansen)

                5.  Then I run a macro written by Leon Wurr that changes the Custom Property - Sheet 1 of ..... (Custom Sheet Number Macro)

                6.  Last I run a macro Read Sheet Names written by John Christensen - I use this to show me a summarized list of all the sheets in the drawing file, see picture below.

                 

                  • Re: Renumber Sheet Names
                    Matt Peneguy

                    John Stoltzfus,

                    Thanks for posting those here.  I am definitely going to look into the Rebuild Reference File.  That one looks like it should be useful to everyone regardless of workflows.

                    Some of the others I'll have to look at, too.  But, I have a little different workflow.  For instance, for each project I'll have up to 20 drawing files with anywhere from 2 to 8 sheets.  It would be nice to have a means of having a table with all the sheet names, but just having the section names is good enough for us.  And those section names aren't likely to change for each bridge.  I'm thinking our configurations work a little different, too.