Drawing Labels

m2shell
Posts: 134
Joined: Mon Jun 28, 2021 2:07 pm
Answers: 0
Location: Brooklyn NY
x 121
x 56

Drawing Labels

Unread post by m2shell »

Is there a way to set the automatic Section & Detail labeling so that if I have a multi-sheet drawing, it will have labels start at "A" for each sheet in the drawing file?
User avatar
Glenn Schroeder
Posts: 1516
Joined: Mon Mar 08, 2021 11:43 am
Answers: 23
Location: southeast Texas
x 1751
x 2124

Re: Drawing Labels

Unread post by Glenn Schroeder »

m2shell wrote: Tue May 16, 2023 3:16 pm Is there a way to set the automatic Section & Detail labeling so that if I have a multi-sheet drawing, it will have labels start at "A" for each sheet in the drawing file?
I'm pretty sure the answer is no. Why would you want to?
"On the days when I keep my gratitude higher than my expectations, well, I have really good days."

Ray Wylie Hubbard in his song "Mother Blues"
m2shell
Posts: 134
Joined: Mon Jun 28, 2021 2:07 pm
Answers: 0
Location: Brooklyn NY
x 121
x 56

Re: Drawing Labels

Unread post by m2shell »

Drawing starts out single sheet, becomes multiple sheets, then later gets split into separate drawings. For instance Part detail sheets get worked on a separate sheet than the installation context drawings. Then file gets too big and slow, so it has to get split into separate files.
User avatar
mattpeneguy
Posts: 1386
Joined: Tue Mar 09, 2021 11:14 am
Answers: 4
x 2489
x 1899

Re: Drawing Labels

Unread post by mattpeneguy »

You can try the following macro when you separate the sheets out. It'll rename the views starting with A.

Code: Select all

    Const A_CHAR As Integer = 65
    Const Z_CHAR As Integer = 90
     
    Dim swApp As SldWorks.SldWorks
    Dim swDraw As SldWorks.DrawingDoc
    Dim swSheet As SldWorks.Sheet
     
    Dim curChar As Integer
    Dim curChar2 As Integer
    Dim curChar3 As Integer
'
    Sub main()
        
        Set swApp = Application.SldWorks
     
        Set swDraw = swApp.ActiveDoc
        
        If swDraw Is Nothing Then
            MsgBox "Please open drawing document"
            End
        End If
        Dim vSheetNames() As String
        vSheetNames = swDraw.GetSheetNames
        
        Dim sheetInd As Integer
        curChar = A_CHAR
        curChar2 = A_CHAR
        curChar3 = A_CHAR
        For sheetInd = 0 To UBound(vSheetNames)
            
            
            swDraw.ActivateSheet vSheetNames(sheetInd)
            Set swSheet = swDraw.Sheet(vSheetNames(sheetInd))
     
            Dim vViews As Variant
            vViews = swSheet.GetViews
            
            Dim i As Integer
        'Debug.Print UBound(vViews)
            'If UBound(vViews) Is Nothing Then
            ' if sheet has no views skip
            
            'Else
            For i = 0 To UBound(vViews)
                
                Dim swView As SldWorks.View
                
                Set swView = vViews(i)
                
                Select Case swView.Type
                    Case swDrawingViewTypes_e.swDrawingSectionView
                        Dim swSectionView As SldWorks.DrSection
                        Set swSectionView = swView.GetSection
                        Debug.Print swSectionView.GetLabel
                        swSectionView.SetLabel2 GetNextName
                    Case swDrawingViewTypes_e.swDrawingDetailView
                        Dim swDetailedView As SldWorks.DetailCircle
                        Set swDetailedView = swView.GetDetail
                        Debug.Print swDetailedView.GetLabel
                        swDetailedView.SetLabel GetNextName
                End Select
                
            Next
            'End If
        
            
        
        Next
        
        swDraw.ForceRebuild
    End Sub
     
    Function GetNextName() As String
        If curChar > Z_CHAR Then
            If curChar2 > Z_CHAR Then
                MsgBox ("Overflow")
                End
            Else
                If curChar3 > Z_CHAR Then
                    curChar3 = A_CHAR
                    curChar2 = curChar2 + 1
                End If
'                FirstLet = curChar2
'                SecondLet = curChar3
                GetNextName = Chr(curChar2) & Chr(curChar3)
                curChar3 = curChar3 + 1
            End If
        Else
            GetNextName = Chr(curChar)
            curChar = curChar + 1
        End If
    End Function

    
User avatar
mattpeneguy
Posts: 1386
Joined: Tue Mar 09, 2021 11:14 am
Answers: 4
x 2489
x 1899

Re: Drawing Labels

Unread post by mattpeneguy »

Fair warning though, it was made for a drawing file with multiple sheets. I suppose you could modify it to iterate through each sheet in the drawing and rename starting with A for each sheet. But, because the file already has an "A" view when you get to sheet 2, it will probably give you an error.
m2shell
Posts: 134
Joined: Mon Jun 28, 2021 2:07 pm
Answers: 0
Location: Brooklyn NY
x 121
x 56

Re: Drawing Labels

Unread post by m2shell »

mattpeneguy wrote: Tue May 16, 2023 4:03 pm You can try the following macro when you separate the sheets out. It'll rename the views starting with A.
Great Thanks! I'll definitely try it out!
User avatar
mattpeneguy
Posts: 1386
Joined: Tue Mar 09, 2021 11:14 am
Answers: 4
x 2489
x 1899

Re: Drawing Labels

Unread post by mattpeneguy »

Good luck and let us know how it works. If you modify it to work on a multisheet drawing with each sheet starting at "A", post it back here for others who may get use out of it.

Credit to where credit is due, Deepak Gupta helped me with that macro several years ago on the old forum.
I'm not really a coder, but I can kludge things together with some help from people who know what they're doing.
Post Reply