MACRO LIBRARY

Get the names of all sheets and drawing views

Free public access. No account or subscription required.

Files

Get the names of all sheets and drawing views

Code

'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
'Preconditions: Drawing is open
'Postconditions: Sheet names and drawing view names in that sheet are displayed _
    in immediate window
    
Option Explicit
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim vSheetNames As Variant
Dim i As Integer
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swDraw = swModel
    
    vSheetNames = swDraw.GetSheetNames
    For i = 0 To UBound(vSheetNames)
        swDraw.ActivateSheet vSheetNames(i)
        Debug.Print vSheetNames(i)
        Set swView = swDraw.GetFirstView
        While Not swView Is Nothing
            Debug.Print "Drawing view: " & swView.GetName2 & " [" & swView.Type & "]"
            Set swView = swView.GetNextView
        Wend
    Next i
End Sub
    
'Notes: first view in any sheet is the sheet itself
    
'To get sheet names you could also use (where swSheet is sldworks.sheet):
'Set swSheet = swDraw.GetCurrentSheet
'debug.print = swSheet.GetName