Select all views in drawing sheet

Hi guys,

I just starting with NXOpen and trying to run some basic scripts. In this one I would like to select all views of current drawing sheet and set color of visible lines. Actual (not working) code is below. It looks like there is problem with selection of all views.

' NX 8.5.3.3
' Journal created by hm1535 on Fri Aug 18 10:18:40 2017 Central Europe Daylight Time
'
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "View Style")

Dim startSheet As Drawings.DrawingSheet = theSession.Parts.Work.DrawingSheets.CurrentDrawingSheet

Dim viewsToSelect() As Drawings.DraftingView = startSheet.GetDraftingViews

For Each viewsToSelect in startSheet
Style.VisibleLines.VisibleColor = 2

workPart.DraftingViews.SuppressViewBreaks(viewsToSelect)

viewsToSelect.Commit()

workPart.DraftingViews.RestoreViewBreaks(viewsToSelect)

next

End Sub
End Module

In the "for" loop, we need to create a variable to hold the individual object from the collection (in this case, an array) that we are iterating over. The overall syntax is:
For each {individualVariableName} as Type in {Collection}

In the code below, we've declared the tempView variable in the For loop definition; the scope of the tempView variable is limited to the For loop. When the For loop ends, the tempView variable will go out of scope and cannot be referenced in the rest of the code.

' NX 8.5.3.3
' Journal created by hm1535 on Fri Aug 18 10:18:40 2017 Central Europe Daylight Time
'
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "View Style")

Dim startSheet As Drawings.DrawingSheet = theSession.Parts.Work.DrawingSheets.CurrentDrawingSheet

Dim viewsToSelect() As Drawings.DraftingView = startSheet.GetDraftingViews

For Each tempView as Drawings.DraftingView in viewsToSelect
tempView.Style.VisibleLines.VisibleColor = 2

tempView.Commit()

next

End Sub
End Module

Note that I removed the .SuppressViewBreaks and .RestoreViewBreaks method calls as I did not need them for my testing. Depending on what you need the code to do, you may need to add them back in.

Thanks, that helps me a lot!