Renumber Sheet Names and Relabel View Labels

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, ​ 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 ​ 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 I copied the code written by ​ 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.

SolidworksApi macros
Answers 16
DG
DG 2018-01-11 Best Answer

Thanks for putting it up here ​. 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).

JS
JS 2018-01-11

Interesting ​ - 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 ​

3.  Then I run a macro to Rebuild the Reference File written by ​ - 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 ​ - Edited by ​)

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

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

comment imagecomment image
MP
MP 2018-01-11

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?

DG
DG 2018-01-11
<p>Matt Peneguy wrote:</p><p></p><p>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?</p>

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

<p>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.</p>

Check macros here and   by

MP
MP 2018-01-11

​,

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.

MP
MP 2018-01-11

Thanks Deepak,

I'm going to get onto fixing the macro and then I'll see about renaming those views.

JS
JS 2018-01-11

Yeah - I don't see my workflow fitting with your workflow at all, totally different process.

MP
MP 2018-01-11

But, I'm sure that view renaming macro Deepak mentioned would be useful to everyone.  So, useful that I think it should be part of the SWX program.  Though, I'm not going to suggest it at this point.  One and Two comes first!

CB
CB 2019-04-17

This worked perfect for renaming the drawing views, but does not incluse the case for Auxiliary Views. I added the following code, and it worked perfect:

<p>Case swDrawingViewTypes_e.swDrawingAuxiliaryView</p><p>    Dim swProjView As SldWorks.ProjectionArrow</p><p>    Set swProjView = swView.GetProjectionArrow</p><p>    Debug.Print swProjView.GetLabel</p><p>    swProjView.SetLabel GetNextName</p><p></p>

Thanks again for your help.

SF
SF 2020-08-12

Question guys.... If I renumber the sheets does this make the new sheet 1 be 1 of X# sheet?  Or does this just change the name of the sheet?

MP
MP 2020-08-12

Hi ,

Unfortunately all this does is change custom property that controls the name in the "Tab" right here:

I have a reference to that custom property in my title block.

So what I use this to do is to number my sheets from something like 201-215 for a drawing file.  We make our drawing files based on assembly and they slip into a set of drawing sheets that can be many hundreds of sheets.  So this macro makes it easy to if someone in the 100's sheet numbers adds a sheet for me to just shift my sheets accordingly. I open the drawing file and run the macro and type 202, and voila, my sheets are now 202-216.


I'm curious what you need.  Can you give me a little more information?

comment imagecomment image
SF
SF 2020-08-12

I did some detail prints of a frame we are building for a awning.  Right now there are 5 sheets of details, sheet 1 has rafter 1 one it, sheet 2 has rafter 2 on it, sheet 3 has some of the poles on it, ect.  I now need to add a sheet that shows the frame in an isometric view and I want it to be sheet 1, and the others to be sheet 2, 3, 4, 5, & 6.  My tile block uses the $PRP:"SW-Current Sheet(Current Sheet) OF $PRP:"SW-Total Sheet (Total Sheet) to show the sheet number of total sheets, so right now when I add the new sheet it so as 6 of 6, not 1 of 6 like I want it to.  I know I can do it manually, but I was hoping this actually changed the sheet number as opposed to just renaming them.

MP
MP 2020-08-12

Tim Taby wrote:

I did some detail prints of a frame we are building for a awning.  Right now there are 5 sheets of details, sheet 1 has rafter 1 one it, sheet 2 has rafter 2 on it, sheet 3 has some of the poles on it, ect.  I now need to add a sheet that shows the frame in an isometric view and I want it to be sheet 1, and the others to be sheet 2, 3, 4, 5, & 6.  My tile block uses the $PRP:"SW-Current Sheet(Current Sheet) OF $PRP:"SW-Total Sheet (Total Sheet) to show the sheet number of total sheets, so right now when I add the new sheet it so as 6 of 6, not 1 of 6 like I want it to.  I know I can do it manually, but I was hoping this actually changed the sheet number as opposed to just renaming them.

If I'm interpreting what you need correctly, wouldn't just dragging sheet 6 to position 1 solve your problem?

comment imagecomment image
SF
SF 2020-08-12

Yes, that did it.  When I first moved it the broader showed sheet 6 of 6, but once I reloaded the drawing it updated.  Thanks!

MP
MP 2020-08-12

Glad I could help.  Any time in drawings you make an update that affects custom properties you have to rebuild to get the changes to show.

AJ
AJ 2023-12-06

Hi All, which one is the working macro? Can someone resend it?