AnsweredAssumed Answered

How do I exclude char for renaming sections and details with a macro?

Question asked by Nicholas Haner on Dec 18, 2017
Latest reply on Dec 19, 2017 by Nicholas Haner

I found the script below on another question about renaming sections and detail. What I am trying to do, without success, is to modify it to exclude different characters I,O,Q,S,X & Z. Thought it would be as simple as an

If curChar = 73 Then

     curChar + 2


End Is

but no such luck. Any help would be appreciated. Is there a way to add an exclusion list of some kind?


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


Sub main()


    Set swApp = Application.SldWorks


    Set swDraw = swApp.ActiveDoc


    If swDraw Is Nothing Then

        MsgBox "Please open drawing document"


    End If


    Dim vSheetNames As Variant

    vSheetNames = swDraw.GetSheetNames


    Dim sheetInd As Integer

    curChar = 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


        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








End Sub


Function GetNextName() As String

    If curChar > Z_CHAR Then

        MsgBox ("Overflow")


    End If

    GetNextName = Chr(curChar) & curText

    curChar = curChar + 1

End Function