How can i get current sheet number API

How can i get current sheet number in a drawing document ? ?

SolidworksApi macros
Answers 5
DG
DG 2015-12-22 Best Answer

I don't think there is direct way to get the sheet number. You can get the sheet name and ID though.

<p>Option Explicit</p><p>Sub main()</p><p>    Dim swApp                   As SldWorks.SldWorks</p><p>    Dim swModel                 As SldWorks.ModelDoc2</p><p>    Dim swDraw                  As SldWorks.DrawingDoc</p><p>    Dim swSheet                 As SldWorks.Sheet</p><p></p><p>    Set swApp = Application.SldWorks</p><p>    Set swModel = swApp.ActiveDoc</p><p>    Set swDraw = swModel</p><p>    Set swSheet = swDraw.GetCurrentSheet</p><p>    Debug.Print swSheet.GetName & " " & swSheet.GetID</p><p>    </p><p>End Sub</p>
AJ
AJ 2015-12-22

Actually, there is a way to find the sheet number using the DrawingDoc.Sheetnames method

<p>Option Explicit</p><p>Sub main()</p><p>    Dim swApp                  As SldWorks.SldWorks</p><p>    Dim swModel                As SldWorks.ModelDoc2</p><p>    Dim swDraw                  As SldWorks.DrawingDoc</p><p>    Dim swSheet                As SldWorks.Sheet</p><p></p><p></p><p>    Set swApp = Application.SldWorks</p><p>    Set swModel = swApp.ActiveDoc</p><p>    Set swDraw = swModel</p><p>    Set swSheet = swDraw.GetCurrentSheet</p><p>    Dim swSheetName As String</p><p>    swSheetName = swSheet.GetName</p><p>    Dim swSheetNames As Variant</p><p>    swSheetNames = swDraw.GetSheetNames</p><p>    Dim SheetNumber As Long</p><p>    Dim I As Integer</p><p>    For I = 1 To UBound(swSheetNames) + 1</p><p>    If swSheet.GetName = swSheetNames(I - 1) Then</p><p>    SheetNumber = I</p><p>    Exit For</p><p>    End If</p><p>    Next I</p><p>    Debug.Print "Sheet name: "; swSheet.GetName & " Number: " & SheetNumber</p><p>End Sub</p><p></p>
DG
DG 2015-12-22

Great, thanks for sharing that. I was using .SheetNames but could not work out these lines

<p>If swSheet.GetName = swSheetNames(I - 1) Then  </p><p>SheetNumber = I  </p>
AJ
AJ 2015-12-22

No problem. "Sharing is caring".

SF
SF 2015-12-22

Thank you that's work great !