Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Module Module1
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UF.UFSession = UF.UFSession.GetUFSession
Sub Main()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim currentApplication As Integer
theUfSession.UF.AskApplicationModule(currentApplication)
If currentApplication <> UF.UFConstants.UF_APP_DRAFTING Then
lw.WriteLine("must be in the drafting application")
Return
End If
Const undoMarkName As String = "next drawing page"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim drawingDic As New Dictionary(Of Integer, Drawings.DrawingSheet)
For Each dwgSheet As Drawings.DrawingSheet In workPart.DrawingSheets
drawingDic.Add(SheetNumber(dwgSheet), dwgSheet)
Next
Dim totalSheets As Integer = workPart.DrawingSheets.ToArray.Length
'lw.WriteLine("number of drawing sheets: " & totalSheets.ToString)
Dim curSheetNumber As Integer = SheetNumber(workPart.DrawingSheets.CurrentDrawingSheet)
'lw.WriteLine("current sheet: " & curSheetNumber.ToString)
'For Each kvp As KeyValuePair(Of Integer, Drawings.DrawingSheet) In drawingDic
' lw.WriteLine("sheet number: " & kvp.Key.ToString & " name: " & kvp.Value.Name)
'Next
Dim newSheetNum As Integer = curSheetNumber + 1
If newSheetNum > totalSheets Then
newSheetNum = 1
End If
Dim newSheet As Drawings.DrawingSheet
If drawingDic.TryGetValue(newSheetNum, newSheet) Then
newSheet.Open()
Else
'sheet not found
lw.WriteLine("error: sheet not found")
End If
lw.Close()
End Sub
Function SheetNumber(ByVal theSheet As Drawings.DrawingSheet) As Integer
Dim sheetNum As Integer
Dim theSheetBuilder As Drawings.DrawingSheetBuilder = theSession.Parts.Work.DrawingSheets.DrawingSheetBuilder(theSheet)
sheetNum = theSheetBuilder.Number
theSheetBuilder.Destroy()
Return sheetNum
End Function
End Module