Rename All Section and Detail Views with API

I have a situation that comes up from time to time where a number of sheets are added to a drawing with additional section and detail views.  This creates a situation where the view names and not in alphabetical order thru the sheets.  I have routines where I traverse the drawing sheets to perform some operation.  What I'm looking for is the command sequence for renaming the section and detail views.

For instance: Starting on "Sheet1", rename all the section views from A to X1.  Then update all the detail views labels from X2 - X3.  Next sheet...

What are the commands to rename the a section and/or detail views?

Dave

SolidworksApi macros
Answers 20
AT
AT 2016-05-03 Best Answer

Try this macro: #CODE|Relable Views

DP
DP 2016-05-04

Excellent.  Thank you.  Worked perfectly.

CC
CC 2016-05-04

Artem,

Nice code - it'd be nice if the macro is also included renaming all proj. views

AT
AT 2016-05-05

Hi Christian,

Yes, this is possible but projected views do not have labels rather names. How would you like to name them, just alphabetically or you have any other naming convention?

Thanks,
Artem

CC
CC 2016-05-05

Hi Artem,

The number of the projected view (Drawing ViewXX) sometimes is jumped from 1 to 3 or 8 to 10 - would it be possible to rearrange for number in order?

NG
NG 2017-03-24

artem

unfortunaly this does not seem to work for sw 2014

i do get it to run if i update the library and delete 2016 ref and add 2014

and then the macro runs without problems

the downside is that it does not seem to do anything

a long while back u made this

Conversion of Tree from Chineese to English - DASSAULT: SOLIDWORKS 3D Design - Eng-Tips

i need something simular to that only for  drawing files

i tried changing this

Dim swApp As SldWorks.SldWorks

Dim swPart As SldWorks.PartDoc

to this

Dim swApp As SldWorks.SldWorks

Dim swPart As SldWorks.DrawingDoc

and that stops the macro from throwwing errors on drawwings

but it does not  work propper

as it only changes the first 2 instances

i understand it does not change the view sections

is there a way to combine these 2 macro`s into 1 ?

CV
CV 2017-04-21

Artem...this macro is magical. i desperately want to use it. Is it possible to exclude I,O,Q,S,X & Z? we don't use these alphabet as its against our standard.

DG
DG 2017-04-21

You can set IF conditions to check the current cur and if that matches with I,O,Q,S,X & Z, then jump to next.

CV
CV 2017-05-12

thanks deepak.. but i couldn't edit it. i am not good it that. will ask some expert to edit for me.

GB
GB 2017-08-04

​  and ​

sorry everyone to reopen this conversation, but with the idea, I'd like to know how to change just the details labels to number instead of letters.

<p><span class="pln"> </span><span class="kwd" style="color: #000088;">Select</span><span class="pln"> </span><span class="kwd" style="color: #000088;">Case</span><span class="pln"> swView</span><span class="pun" style="color: #666600;">.</span><span class="pln">Type</span></p><p><span class="pln">        </span><span class="kwd" style="color: #000088;">Case</span><span class="pln"> swDrawingViewTypes_e</span><span class="pun" style="color: #666600;">.</span><span class="pln">swDrawingSectionView</span></p><p><span class="pln">                  </span><span class="kwd" style="color: #000088;">Dim</span><span class="pln"> swSectionView </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> SldWorks</span><span class="pun" style="color: #666600;">.</span><span class="pln">DrSection</span></p><p><span class="pln">                  </span><span class="kwd" style="color: #000088;">Set</span><span class="pln"> swSectionView </span><span class="pun" style="color: #666600;">=</span><span class="pln"> swView</span><span class="pun" style="color: #666600;">.</span><span class="pln">GetSection</span></p><p><span class="pln">                 Debug</span><span class="pun" style="color: #666600;">.</span><span class="pln">Print swSectionView</span><span class="pun" style="color: #666600;">.</span><span class="pln">GetLabel</span></p><p><span class="pln">                 swSectionView</span><span class="pun" style="color: #666600;">.</span><span class="pln">SetLabel2 GetNextName</span></p><p><span class="pln">       </span><span class="kwd" style="color: #000088;">Case</span><span class="pln"> swDrawingViewTypes_e</span><span class="pun" style="color: #666600;">.</span><span class="pln">swDrawingDetailView</span></p><p><span class="kwd" style="color: #000088;">               Dim</span><span class="pln"> swDetailedView </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> SldWorks</span><span class="pun" style="color: #666600;">.</span><span class="pln">DetailCircle</span></p><p><span class="kwd" style="color: #000088;">               Set</span><span class="pln"> swDetailedView </span><span class="pun" style="color: #666600;">=</span><span class="pln"> swView</span><span class="pun" style="color: #666600;">.</span><span class="pln">GetDetail</span></p><p><span class="pln">               Debug</span><span class="pun" style="color: #666600;">.</span><span class="pln">Print swDetailedView</span><span class="pun" style="color: #666600;">.</span><span class="pln">GetLabel</span></p><p><span class="pln">               swDetailedView</span><span class="pun" style="color: #666600;">.</span><span class="pln">SetLabel <strong><span style="text-decoration: line-through;">GetNextName</span>  - </strong><em>"I guess that I have to change this part with a rule to choose a number that was not used yet"</em></span></p><p></p>

my idea is to change this last line, but I need still something else to verify the numbers, check if the number was used or not and use the next one, or just add a last number used +1.

<p><span class="kwd" style="color: #000088;">Const</span><span class="pln"> A_CHAR </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> </span><span class="kwd" style="color: #000088;">Integer</span><span class="pln"> </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="lit" style="color: #006666;">65</span></p><p><span class="kwd" style="color: #000088;">Const</span><span class="pln"> Z_CHAR </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> </span><span class="kwd" style="color: #000088;">Integer</span><span class="pln"> </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="lit" style="color: #006666;">90</span></p><p><span class="pln"> </span></p><p><span class="kwd" style="color: #000088;">Dim</span><span class="pln"> swApp </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> SldWorks</span><span class="pun" style="color: #666600;">.</span><span class="pln">SldWorks</span></p><p><span class="kwd" style="color: #000088;">Dim</span><span class="pln"> swDraw </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> SldWorks</span><span class="pun" style="color: #666600;">.</span><span class="pln">DrawingDoc</span></p><p><span class="kwd" style="color: #000088;">Dim</span><span class="pln"> swSheet </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> SldWorks</span><span class="pun" style="color: #666600;">.</span><span class="pln">Sheet</span><span class="pln"> </span></p><p><span class="pln"></span></p><p><span class="kwd" style="color: #000088;">Dim</span><span class="pln"> curChar </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> </span><span class="kwd" style="color: #000088;">Integer</span><span class="pln"> </span></p><p><span class="pln"></span></p><p><span class="kwd" style="color: #000088;">Sub</span><span class="pln"> main</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span></p><p><span class="pln"></span></p><p><span class="pln">   </span><span class="kwd" style="color: #000088;">Set</span><span class="pln"> swApp </span><span class="pun" style="color: #666600;">=</span><span class="pln"> Application</span><span class="pun" style="color: #666600;">.</span><span class="pln">SldWorks</span><span class="pln"> </span></p><p><span class="pln"></span></p><p><span class="pln">   </span><span class="kwd" style="color: #000088;">Set</span><span class="pln"> swDraw </span><span class="pun" style="color: #666600;">=</span><span class="pln"> swApp</span><span class="pun" style="color: #666600;">.</span><span class="pln">ActiveDoc</span><span class="pln">   </span></p><p><span class="pln"></span></p><p><span class="pln">   </span><span class="kwd" style="color: #000088;">If</span><span class="pln"> swDraw </span><span class="kwd" style="color: #000088;">Is</span><span class="pln"> </span><span class="lit" style="color: #006666;">Nothing</span><span class="pln"> </span><span class="kwd" style="color: #000088;">Then</span></p><p><span class="pln">            MsgBox </span><span class="str" style="color: #008800;">"Please open drawing document"</span></p><p><span class="pln">            </span><span class="kwd" style="color: #000088;">End</span></p><p><span class="pln">   </span><span class="kwd" style="color: #000088;">End</span><span class="pln"> </span><span class="kwd" style="color: #000088;">If</span><span class="pln"> </span></p><p><span class="pln"></span></p><p><span class="pln">  </span><span class="kwd" style="color: #000088;">Dim</span><span class="pln"> vSheetNames </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> </span><span class="kwd" style="color: #000088;">Variant</span></p><p><span class="pln">  vSheetNames </span><span class="pun" style="color: #666600;">=</span><span class="pln"> swDraw</span><span class="pun" style="color: #666600;">.</span><span class="pln">GetSheetNames</span></p><p><span class="pln">   </span></p><p><span class="pln">  </span><span class="kwd" style="color: #000088;">Dim</span><span class="pln"> sheetInd </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> </span><span class="kwd" style="color: #000088;">Integer</span></p><p><span class="pln">  curChar </span><span class="pun" style="color: #666600;">=</span><span class="pln"> A_CHAR</span><span class="pln">  </span></p><p><span class="pln"></span></p><p><span class="pln">   </span><span class="kwd" style="color: #000088;">For</span><span class="pln"> sheetInd </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="lit" style="color: #006666;">0</span><span class="pln"> </span><span class="kwd" style="color: #000088;">To</span><span class="pln"> UBound</span><span class="pun" style="color: #666600;">(</span><span class="pln">vSheetNames</span><span class="pun" style="color: #666600;">)</span></p><p><span class="pln">   </span></p><p><span class="pln">   swDraw</span><span class="pun" style="color: #666600;">.</span><span class="pln">ActivateSheet vSheetNames</span><span class="pun" style="color: #666600;">(</span><span class="pln">sheetInd</span><span class="pun" style="color: #666600;">)</span></p><p><span class="pln">   </span><span class="kwd" style="color: #000088;">Set</span><span class="pln"> swSheet </span><span class="pun" style="color: #666600;">=</span><span class="pln"> swDraw</span><span class="pun" style="color: #666600;">.</span><span class="pln">Sheet</span><span class="pun" style="color: #666600;">(</span><span class="pln">vSheetNames</span><span class="pun" style="color: #666600;">(</span><span class="pln">sheetInd</span><span class="pun" style="color: #666600;">))</span></p><p><span class="pln"> </span></p><p><span class="pln">   </span><span class="kwd" style="color: #000088;">Dim</span><span class="pln"> vViews </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> </span><span class="kwd" style="color: #000088;">Variant</span></p><p><span class="pln">   vViews </span><span class="pun" style="color: #666600;">=</span><span class="pln"> swSheet</span><span class="pun" style="color: #666600;">.</span><span class="pln">GetViews</span></p><p><span class="pln">   </span></p><p><span class="pln">   </span><span class="kwd" style="color: #000088;">Dim</span><span class="pln"> i </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> </span><span class="kwd" style="color: #000088;">Integer</span><span class="pln">   </span></p><p><span class="pln"></span></p><p><span class="pln">   </span><span class="kwd" style="color: #000088;">For</span><span class="pln"> i </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="lit" style="color: #006666;">0</span><span class="pln"> </span><span class="kwd" style="color: #000088;">To</span><span class="pln"> UBound</span><span class="pun" style="color: #666600;">(</span><span class="pln">vViews</span><span class="pun" style="color: #666600;">)</span><span class="pln">   </span></p><p><span class="pln"></span></p><p><span class="pln">        </span><span class="kwd" style="color: #000088;">Dim</span><span class="pln"> swView </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> SldWorks</span><span class="pun" style="color: #666600;">.</span><span class="pln">View</span><span class="pln">  </span></p><p><span class="pln"> </span></p><p><span class="pln">        </span><span class="kwd" style="color: #000088;">Set</span><span class="pln"> swView </span><span class="pun" style="color: #666600;">=</span><span class="pln"> vViews</span><span class="pun" style="color: #666600;">(</span><span class="pln">i</span><span class="pun" style="color: #666600;">)</span><span class="pln">   </span></p><p><strong><span class="pln">        </span><span class="kwd" style="color: #000088;">Select</span><span class="pln"> </span><span class="kwd" style="color: #000088;">Case</span><span class="pln"> swView</span><span class="pun" style="color: #666600;">.</span><span class="pln">Type</span></strong></p><p><strong><span class="pln">                  </span><span class="kwd" style="color: #000088;">Case</span><span class="pln"> swDrawingViewTypes_e</span><span class="pun" style="color: #666600;">.</span><span class="pln">swDrawingSectionView</span></strong></p><p><strong><span class="pln">                       </span><span class="kwd" style="color: #000088;">Dim</span><span class="pln"> swSectionView </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> SldWorks</span><span class="pun" style="color: #666600;">.</span><span class="pln">DrSection</span></strong></p><p><strong><span class="pln">                       </span><span class="kwd" style="color: #000088;">Set</span><span class="pln"> swSectionView </span><span class="pun" style="color: #666600;">=</span><span class="pln"> swView</span><span class="pun" style="color: #666600;">.</span><span class="pln">GetSection</span></strong></p><p><strong><span class="pln">                      Debug</span><span class="pun" style="color: #666600;">.</span><span class="pln">Print swSectionView</span><span class="pun" style="color: #666600;">.</span><span class="pln">GetLabel</span></strong></p><p><strong><span class="pln">                      swSectionView</span><span class="pun" style="color: #666600;">.</span><span class="pln">SetLabel2 GetNextName</span></strong></p><p><strong><span class="pln">                  </span><span class="kwd" style="color: #000088;">Case</span><span class="pln"> swDrawingViewTypes_e</span><span class="pun" style="color: #666600;">.</span><span class="pln">swDrawingDetailView</span></strong></p><p><strong><span class="pln">                       </span><span class="kwd" style="color: #000088;">Dim</span><span class="pln"> swDetailedView </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> SldWorks</span><span class="pun" style="color: #666600;">.</span><span class="pln">DetailCircle</span></strong></p><p><strong><span class="pln">                       </span><span class="kwd" style="color: #000088;">Set</span><span class="pln"> swDetailedView </span><span class="pun" style="color: #666600;">=</span><span class="pln"> swView</span><span class="pun" style="color: #666600;">.</span><span class="pln">GetDetail</span></strong></p><p><strong><span class="pln">                      Debug</span><span class="pun" style="color: #666600;">.</span><span class="pln">Print swDetailedView</span><span class="pun" style="color: #666600;">.</span><span class="pln">GetLabel</span></strong></p><p><strong><span class="pln">                      swDetailedView</span><span class="pun" style="color: #666600;">.</span><span class="pln">SetLabel GetNextName</span></strong></p><p><strong><span class="pln">             </span><span class="kwd" style="color: #000088;">End</span><span class="pln"> </span><span class="kwd" style="color: #000088;">Select</span></strong></p><p><span class="kwd" style="color: #000088;"></span></p><p><span class="pln">        </span><span class="kwd" style="color: #000088;">Next</span></p><p><span class="kwd" style="color: #000088;"></span></p><p><span class="pln">   </span><span class="kwd" style="color: #000088;">Next</span></p><p><span class="kwd" style="color: #000088;"></span></p><p><span class="pln">   swDraw</span><span class="pun" style="color: #666600;">.</span><span class="pln">ForceRebuild</span><span class="pln"> </span></p><p><span class="pln"></span></p><p><span class="kwd" style="color: #000088;">End</span><span class="pln"> </span><span class="kwd" style="color: #000088;">Sub</span></p><p><span class="kwd" style="color: #000088;"></span></p><p><span class="kwd" style="color: #000088;">Function</span><span class="pln"> GetNextName</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span><span class="kwd" style="color: #000088;">As</span><span class="pln"> </span><span class="kwd" style="color: #000088;">String</span></p><p><span class="kwd" style="color: #000088;"></span></p><p><span class="pln">   </span><span class="kwd" style="color: #000088;">If</span><span class="pln"> curChar </span><span class="pun" style="color: #666600;">></span><span class="pln"> Z_CHAR </span><span class="kwd" style="color: #000088;">Then</span></p><p><span class="pln">            MsgBox </span><span class="pun" style="color: #666600;">(</span><span class="str" style="color: #008800;">"Overflow"</span><span class="pun" style="color: #666600;">)</span></p><p><span class="pln">            </span><span class="kwd" style="color: #000088;">End</span></p><p><span class="pln">   </span><span class="kwd" style="color: #000088;">End</span><span class="pln"> </span><span class="kwd" style="color: #000088;">If</span></p><p><span class="kwd" style="color: #000088;"></span></p><p><span class="pln">   GetNextName </span><span class="pun" style="color: #666600;">=</span><span class="pln"> Chr</span><span class="pun" style="color: #666600;">(</span><span class="pln">curChar</span><span class="pun" style="color: #666600;">)</span><span class="pln"> </span><span class="pun" style="color: #666600;">&</span><span class="pln"> curText</span></p><p><span class="pln"></span></p><p><span class="pln">   curChar </span><span class="pun" style="color: #666600;">=</span><span class="pln"> curChar </span><span class="pun" style="color: #666600;">+</span><span class="pln"> </span><span class="lit" style="color: #006666;">1</span></p><p><span class="lit" style="color: #006666;"></span></p><p><span class="kwd" style="color: #000088;">End</span><span class="pln"> </span><span class="kwd" style="color: #000088;">Function</span></p>
DG
DG 2017-08-04

You can add a variable

<p>Dim nNumView As Long</p><p>nNumView = 1</p>

and then use

<p>swDetailedView.SetLabel ("DetailView" & nNumView)</p>

And can check if nNumView is used or not. If used, then bump by +1, check and repeat. If not then use the nNumView value and next view.

GB
GB 2017-08-04

Thanks! I did what you said changed the code and works fine now!

Here is the code changed with everything I've done to work.

I don't know if there is any way to make the code see all sheets at once, but I already can work with this!

maybe there is a easy way to do this!

I found out what was the problem, It works perfect now!

THANKS!!

<p><em style="font-size: 8pt;">Const A_CHAR As Integer = 65</em></p><p><em style="font-size: 8pt;">Const Z_CHAR As Integer = 90</em></p><p><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;">Dim swApp As SldWorks.SldWorks</em></p><p><em style="font-size: 8pt;">Dim swDraw As SldWorks.DrawingDoc</em></p><p><em style="font-size: 8pt;">Dim swSheet As SldWorks.Sheet</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;">Dim curChar As Integer</em></p><p><em style="font-size: 8pt;">Dim nNumView As Long</em></p><p><span style="color: #e23d39;"><strong><em style="font-size: 8pt;">Dim curNum As Long</em></strong></span></p><p><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;">Sub main()</em><em style="font-size: 8pt;">    </em></p><p><em style="font-size: 8pt;">    Set swApp = Application.SldWorks</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;">    Set swDraw = swApp.ActiveDoc</em><em style="font-size: 8pt;">    </em></p><p><em style="font-size: 8pt;">    If swDraw Is Nothing Then</em></p><p><em style="font-size: 8pt;">        MsgBox "Please open drawing document"</em></p><p><em style="font-size: 8pt;">        End</em></p><p><em style="font-size: 8pt;">    End If</em><em style="font-size: 8pt;">        </em></p><p><em style="font-size: 8pt;">    Dim vSheetNames As Variant</em></p><p><em style="font-size: 8pt;">    vSheetNames = swDraw.GetSheetNames</em><em style="font-size: 8pt;">    </em></p><p><em style="font-size: 8pt;">    Dim sheetInd As Integer</em></p><p><em style="font-size: 8pt;">    curChar = A_CHAR</em></p><p><em style="font-size: 8pt;">    <span style="color: #e23d39;"><strong>curNum = 1</strong></span></em><em style="font-size: 8pt;">            </em></p><p><em style="font-size: 8pt;">    For sheetInd = 0 To UBound(vSheetNames)</em><em style="font-size: 8pt;">        </em></p><p><em style="font-size: 8pt;">        swDraw.ActivateSheet vSheetNames(sheetInd)</em></p><p><em style="font-size: 8pt;">        Set swSheet = swDraw.Sheet(vSheetNames(sheetInd))</em></p><p><em style="font-size: 8pt;">        Dim vViews As Variant</em></p><p><em style="font-size: 8pt;">        vViews = swSheet.GetViews</em><em style="font-size: 8pt;">        </em></p><p><em style="font-size: 8pt;">        Dim i As Integer</em><em style="font-size: 8pt;">    </em></p><p><em style="font-size: 8pt;">        For i = 0 To UBound(vViews)</em><em style="font-size: 8pt;">            </em></p><p><em style="font-size: 8pt;">            Dim swView As SldWorks.View</em><em style="font-size: 8pt;">            </em></p><p><em style="font-size: 8pt;">            Set swView = vViews(i)</em><em style="font-size: 8pt;">            </em></p><p><em style="font-size: 8pt;">            Select Case swView.Type</em></p><p><em style="font-size: 8pt;">                Case swDrawingViewTypes_e.swDrawingSectionView</em></p><p><em style="font-size: 8pt;">                    Dim swSectionView As SldWorks.DrSection</em></p><p><em style="font-size: 8pt;">                    Set swSectionView = swView.GetSection</em></p><p><em style="font-size: 8pt;">                    Debug.Print swSectionView.GetLabel</em></p><p><em style="font-size: 8pt;">                    swSectionView.SetLabel2 (GetNextName)</em></p><p><em style="font-size: 8pt;">                Case swDrawingViewTypes_e.swDrawingDetailView</em></p><p><em style="font-size: 8pt;">                    Dim swDetailedView As SldWorks.DetailCircle</em></p><p><em style="font-size: 8pt;">                    Set swDetailedView = swView.GetDetail</em></p><p><em style="font-size: 8pt;">                    Debug.Print swDetailedView.GetLabel</em></p><p><em style="font-size: 8pt;">                    <span style="color: #e23d39;"><strong>swDetailedView.SetLabel ("DETALHE " & GetNextNumber) 'swDetailedView.SetLabel GetNextName</strong></span></em></p><p><em style="font-size: 8pt;">            End Select</em><em style="font-size: 8pt;">            </em></p><p><em style="font-size: 8pt;">        Next</em><em style="font-size: 8pt;">    </em></p><p><em style="font-size: 8pt;">    Next</em><em style="font-size: 8pt;">    </em></p><p><em style="font-size: 8pt;">    swDraw.ForceRebuild</em></p><p><em style="font-size: 8pt;">End Sub</em></p><p><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;">Function GetNextName() As String</em></p><p><em style="font-size: 8pt;">    If curChar > Z_CHAR Then</em></p><p><em style="font-size: 8pt;">        MsgBox ("Overflow")</em></p><p><em style="font-size: 8pt;">        End</em></p><p><em style="font-size: 8pt;">    End If</em></p><p><em style="font-size: 8pt;">    GetNextName = Chr(curChar) & curText</em></p><p><em style="font-size: 8pt;">    curChar = curChar + 1</em></p><p><em style="font-size: 8pt;">End Function</em></p><p></p><p><strong style="color: #e23d39;"><em style="font-size: 8pt;">Function GetNextNumber() As String</em></strong></p><p><strong style="color: #e23d39;"><em style="font-size: 8pt;">    GetNextNumber = curNum</em></strong></p><p><strong style="color: #e23d39;"><em style="font-size: 8pt;">    curNum = curNum + 1</em></strong></p><p><strong style="color: #e23d39;"><em style="font-size: 8pt;">End Function</em></strong></p>
DH
DH 2018-09-12

The link no longer works, can you put up the code?

DG
DG 2018-09-12

You can use the codes post by ​ in this post : https://forum.solidworks.com/message/769040#comment-769040

WM
WM 2018-12-26

Long after the fact with this one, but here is my addition. This code, based on the code I found here, will add on a "A" prefix after the alphabet is used up then continue on. Removed unnecessary code and pulled the dims out to the start so you're not re-declaring on every loop to speed things up.

Dim swApp           As SldWorks.SldWorks

Dim swDraw          As SldWorks.DrawingDoc

Dim swSheet         As SldWorks.Sheet

Dim swView          As SldWorks.View

Dim swSectionView   As SldWorks.DrSection

Dim swDetailedView  As SldWorks.DetailCircle

Dim curChar         As Integer

Dim sheetInd        As Integer

Dim i               As Integer

Const A_CHAR        As Integer = 65

Const Z_CHAR        As Integer = 90

Dim prefix          As String

Dim vViews          As Variant

Dim vSheetNames     As Variant

Sub main()

    Set swApp = Application.SldWorks

    Set swDraw = swApp.ActiveDoc

  

    'this is a prefix for sections and details

    prefix = ""

    If swDraw Is Nothing Then

        MsgBox "Please open drawing document"

        End

    End If

    vSheetNames = swDraw.GetSheetNames

    curChar = A_CHAR

    For sheetInd = 0 To UBound(vSheetNames)

  

        swDraw.ActivateSheet vSheetNames(sheetInd)

        Set swSheet = swDraw.Sheet(vSheetNames(sheetInd))

        vViews = swSheet.GetViews

              

        For i = 0 To UBound(vViews)

          

            Set swView = vViews(i)

          

            'This if statement will add an A prefix to any existing prefixes when the count goes past Z

            If curChar > 90 Then

                        prefix = prefix & "A"

                        curChar = A_CHAR

                    End If

                  

            Select Case swView.Type

                Case swDrawingViewTypes_e.swDrawingSectionView

                    Set swSectionView = swView.GetSection

                    swSectionView.SetLabel2 (prefix & GetNextName)

                Case swDrawingViewTypes_e.swDrawingDetailView

                    Set swDetailedView = swView.GetDetail

                    swDetailedView.SetLabel (prefix & GetNextName)

                  

            End Select

        Next

    Next

    swDraw.ForceRebuild

End Sub

Function GetNextName() As String

    GetNextName = Chr(curChar) & curText

    curChar = curChar + 1

End Function

MM
MM 2018-12-27

The link does not work. I am also after it

AT
AT 2018-12-27

Here is a code

<p>Const A_CHAR As Integer = 65</p><p>Const Z_CHAR As Integer = 90</p><p></p><p></p><p>Dim swApp As SldWorks.SldWorks</p><p>Dim swDraw As SldWorks.DrawingDoc</p><p>Dim swSheet As SldWorks.Sheet</p><p></p><p></p><p>Dim curChar As Integer</p><p></p><p></p><p>Sub main()</p><p>    </p><p>    Set swApp = Application.SldWorks</p><p></p><p></p><p>    Set swDraw = swApp.ActiveDoc</p><p>    </p><p>    Set swSheet = swDraw.GetCurrentSheet</p><p>    </p><p>    Dim vViews As Variant</p><p>    vViews = swSheet.GetViews</p><p>    </p><p>    Dim i As Integer</p><p>    </p><p>    curChar = A_CHAR</p><p></p><p></p><p>    For i = 0 To UBound(vViews)</p><p>        </p><p>        Dim swView As SldWorks.View</p><p>        </p><p>        Set swView = vViews(i)</p><p>        </p><p>        Select Case swView.Type</p><p>            Case swDrawingViewTypes_e.swDrawingSectionView</p><p>                Dim swSectionView As SldWorks.DrSection</p><p>                Set swSectionView = swView.GetSection</p><p>                Debug.Print swSectionView.GetLabel</p><p>                swSectionView.SetLabel2 GetNextName</p><p>            Case swDrawingViewTypes_e.swDrawingDetailView</p><p>                Dim swDetailedView As SldWorks.DetailCircle</p><p>                Set swDetailedView = swView.GetDetail</p><p>                Debug.Print swDetailedView.GetLabel</p><p>                swDetailedView.SetLabel GetNextName</p><p>        End Select</p><p>        </p><p>    Next</p><p>    </p><p>    swDraw.ForceRebuild</p><p>    </p><p>End Sub</p><p></p><p></p><p>Function GetNextName() As String</p><p></p><p></p><p>    If curChar > Z_CHAR Then</p><p>        MsgBox ("Overflow")</p><p>        End</p><p>    End If</p><p>        </p><p>    GetNextName = Chr(curChar) & curText</p><p></p><p></p><p>    curChar = curChar + 1</p><p></p><p></p><p>End Function</p>

-----

Thanks,
Artem

Development of advanced SOLIDWORKS add-in - YouTube

DK
DK 2020-02-12

Hi, I know this is a very old thread but how would I modify this to rename auxiliary views rather than section/detail views?

Thanks in advance

MS
MS 2024-12-05

I was hoping to try out this code, but the variable "curText", which is used in several blocks of code here is never defined.

WS
WS 2026-05-29

I know that's an old thread and the links are expired. Could someone help me with this macro?