Script fail if I click on Stop in Work In Progress dialog

I have a script which pause while it shows a message box.
MsgBox("Continue?")
But after a second it also shows the "Work in Progress" dialog with a Stop button.
Everything works well if I don't touch the Stop button.
But if I hit Stop the script fails.
How can I avoid this?

BR Gunnar

What version of NX are you using? Can you post your code, or at least the portion with the message box?

I'm on NX 9 and I'm not able to reproduce your issue (I tested with the message box code found here: http://nxjournaling.com/content/using-message-boxes).

Here is my code.
You will need to have the attribute "DB_PART_REV" set to a character i.e. "C" and it will Highlight all revision triangles that not has the character "C" AND/OR is pointing downwards.

After clicking OK in the MessageBox it should UnHighlight them again.

'********************************************************************************
'NX Journal file
'
'********************************************************************************

Imports System
Imports System.Collections
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.Drawings
Imports NXOpen.UF
Imports NXOpenUI
Imports System.Windows.Forms

Public Module NXRobot
Dim theSession As Session
Dim theUI As UI
Dim theUfSession As UFSession
Dim lw As ListingWindow

Sub Main()
SelectTriangles()
'stop and show a continue box here
MessageBox.Show("Press OK to continue!")
DeselectTriangles()
End Sub

Public Function SelectTriangles()
theSession = Session.GetSession()
theUI = UI.GetUI()
theUfSession = UFSession.GetUFSession()
lw = theSession.ListingWindow

Try
Dim idCol As IdSymbolCollection = theSession.Parts.Work.Annotations.IdSymbols
Dim ids As IdSymbol
Dim iEnum1 As IEnumerator = idCol.GetEnumerator()
Dim dwgs As Drawings.DrawingSheetCollection = theSession.Parts.Work.DrawingSheets
Dim workpart As Part = theSession.Parts.Work

Dim idFind As String
idFind = workpart.GetStringattribute("DB_PART_REV")

Dim idMatrix_Tag = New String(0) {0}
Dim idMatrix_Sht = New String(0) {0}

iEnum1.Reset()
While iEnum1.MoveNext()
ids = DirectCast(iEnum1.Current, IdSymbol)
ids.UnHighlight()
ids.RedisplayObject()

Dim idsb As IdSymbolBuilder = idCol.CreateIdSymbolBuilder(ids)

If idsb.Type = 2 Or (idsb.Type = 3 And idsb.UpperText <> idFind) Then
ReDim Preserve idMatrix_Tag(idMatrix_Tag.GetUpperBound(0) + 1)
ReDim Preserve idMatrix_Sht(idMatrix_Sht.GetUpperBound(0) + 1)
idMatrix_Tag(idMatrix_Tag.GetUpperBound(0)) = ids.Tag.ToString()
idMatrix_Sht(idMatrix_Sht.GetUpperBound(0)) = "N/A"
ids.Unblank()
ids.Highlight()
End If

idsb.Destroy()
End While

'read out current view on next line
Dim currDrawSheet As Drawings.DrawingSheet = theSession.Parts.Work.DrawingSheets.CurrentDrawingSheet

For Each sheet As Drawings.DrawingSheet In dwgs
sheet.Open()
Dim objs() As DisplayableObject = sheet.View.AskVisibleObjects()
For Each obj As DisplayableObject In objs
For i As Integer = 0 To idMatrix_Tag.GetUpperBound(0)
If obj.Tag.ToString() = idMatrix_Tag(i) Then idMatrix_Sht(i) = sheet.Name()
Next
Next
Next

'set back to current view on next line
currDrawSheet.Open

'lw.Open()

If idMatrix_Tag.GetUpperBound(0) = 0 Then
'lw.WriteLine(vbLf & vbTab & "No wron revision triangles found")
Else

Dim resMatrix_Sht = New String(0) {0}
Dim resMatrix_Qty = New String(0) {0}

Do While idMatrix_Sht.GetUpperBound(0) > 0
Dim tmpMatrix_Sht = New String(0) {0}

ReDim Preserve resMatrix_Sht(resMatrix_Sht.GetUpperBound(0) + 1)
ReDim Preserve resMatrix_Qty(resMatrix_Qty.GetUpperBound(0) + 1)
resMatrix_Sht(resMatrix_Sht.GetUpperBound(0)) = idMatrix_Sht(1)
resMatrix_Qty(resMatrix_Qty.GetUpperBound(0)) = 0
For i As Integer = 1 To idMatrix_Sht.GetUpperBound(0)
If idMatrix_Sht(i) = resMatrix_Sht(resMatrix_Sht.GetUpperBound(0)) Then
resMatrix_Qty(resMatrix_Qty.GetUpperBound(0)) = resMatrix_Qty(resMatrix_Qty.GetUpperBound(0)) + 1
Else
ReDim Preserve tmpMatrix_Sht(tmpMatrix_Sht.GetUpperBound(0) + 1)
tmpMatrix_Sht(tmpMatrix_Sht.GetUpperBound(0)) = idMatrix_Sht(i)
End If
Next
ReDim idMatrix_Sht(tmpMatrix_Sht.GetUpperBound(0))
For i As Integer = 1 To idMatrix_Sht.GetUpperBound(0)
idMatrix_Sht(i) = tmpMatrix_Sht(i)
Next
ReDim tmpMatrix_Sht(0)
Loop
'lw.WriteLine("It exist rev. triangles with wrong letter or is upside down")
'lw.WriteLine(vbLf & vbTab & vbTab & vbTab & "SHEET" & vbTab & vbTab & "QTY")
For i As Integer = 1 To resMatrix_Sht.GetUpperBound(0)
'lw.WriteLine(vbTab & "[" & i & "]" & vbTab & "..." & vbTab & resMatrix_Sht(i) & vbTab & resMatrix_Qty(i))
Next
End If

'lw.WriteLine(vbLf & "End of report.")
Catch ex As NXOpen.NXException
UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.[Error], ex.Message)
End Try

End Function

Public Function DeselectTriangles()
theSession = Session.GetSession()
theUI = UI.GetUI()

Try
Dim idCol As IdSymbolCollection = theSession.Parts.Work.Annotations.IdSymbols
Dim ids As IdSymbol
Dim iEnum1 As IEnumerator = idCol.GetEnumerator()

iEnum1.Reset()
While iEnum1.MoveNext()
ids = DirectCast(iEnum1.Current, IdSymbol)
ids.UnHighlight()
ids.RedisplayObject()
End While
Catch ex As NXOpen.NXException
UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.[Error], ex.Message)
End Try

End Function
End Module

Best Regards
Gunnar

I am running NX 8.5

Best Regards
Gunnar

I changed the windows message box out for the NX message box and it seems to work - the "busy" dialog does not show up while the message box is onscreen.

'********************************************************************************
'NX Journal file
'
'********************************************************************************

Option Strict Off
Imports System
Imports System.Collections
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.UF
Imports NXOpenUI

Module Module95
Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

lw.Open()

SelectTriangles()

'stop and show a continue box here
Dim response As Integer
response = theUI.NXMessageBox.Show("Title", NXMessageBox.DialogType.Information, "Press OK to continue")

DeselectTriangles()

End Sub

Public Function SelectTriangles()

Dim idCol As IdSymbolCollection = theSession.Parts.Work.Annotations.IdSymbols
Dim dwgs As Drawings.DrawingSheetCollection = theSession.Parts.Work.DrawingSheets
Dim workpart As Part = theSession.Parts.Work

Dim idFind As String
idFind = workpart.GetStringAttribute("DB_PART_REV")
lw.WriteLine("idFind: " & idFind)

Dim idMatrix_Tag = New String(0) {0}
Dim idMatrix_Sht = New String(0) {0}

For Each ids As IdSymbol In theSession.Parts.Work.Annotations.IdSymbols

ids.Unhighlight()
ids.RedisplayObject()

Dim idsb As IdSymbolBuilder = idCol.CreateIdSymbolBuilder(ids)

If idsb.Type = IdSymbolBuilder.SymbolTypes.Triangle Or (idsb.Type = IdSymbolBuilder.SymbolTypes.TriangleUp And idsb.UpperText <> idFind) Then
ReDim Preserve idMatrix_Tag(idMatrix_Tag.GetUpperBound(0) + 1)
ReDim Preserve idMatrix_Sht(idMatrix_Sht.GetUpperBound(0) + 1)
idMatrix_Tag(idMatrix_Tag.GetUpperBound(0)) = ids.Tag.ToString()
idMatrix_Sht(idMatrix_Sht.GetUpperBound(0)) = "N/A"
ids.Unblank()
ids.Highlight()
End If

idsb.Destroy()
Next

'read out current view on next line
Dim currDrawSheet As Drawings.DrawingSheet = theSession.Parts.Work.DrawingSheets.CurrentDrawingSheet

For Each sheet As Drawings.DrawingSheet In dwgs
sheet.Open()
Dim objs() As DisplayableObject = sheet.View.AskVisibleObjects()
For Each obj As DisplayableObject In objs
For i As Integer = 0 To idMatrix_Tag.GetUpperBound(0)
If obj.Tag.ToString() = idMatrix_Tag(i) Then idMatrix_Sht(i) = sheet.Name()
Next
Next
Next

'set back to current view on next line
currDrawSheet.Open()

If idMatrix_Tag.GetUpperBound(0) = 0 Then
lw.WriteLine(vbLf & vbTab & "No wrong revision triangles found")
Else

Dim resMatrix_Sht = New String(0) {0}
Dim resMatrix_Qty = New String(0) {0}

Do While idMatrix_Sht.GetUpperBound(0) > 0
Dim tmpMatrix_Sht = New String(0) {0}

ReDim Preserve resMatrix_Sht(resMatrix_Sht.GetUpperBound(0) + 1)
ReDim Preserve resMatrix_Qty(resMatrix_Qty.GetUpperBound(0) + 1)
resMatrix_Sht(resMatrix_Sht.GetUpperBound(0)) = idMatrix_Sht(1)
resMatrix_Qty(resMatrix_Qty.GetUpperBound(0)) = 0
For i As Integer = 1 To idMatrix_Sht.GetUpperBound(0)
If idMatrix_Sht(i) = resMatrix_Sht(resMatrix_Sht.GetUpperBound(0)) Then
resMatrix_Qty(resMatrix_Qty.GetUpperBound(0)) = resMatrix_Qty(resMatrix_Qty.GetUpperBound(0)) + 1
Else
ReDim Preserve tmpMatrix_Sht(tmpMatrix_Sht.GetUpperBound(0) + 1)
tmpMatrix_Sht(tmpMatrix_Sht.GetUpperBound(0)) = idMatrix_Sht(i)
End If
Next
ReDim idMatrix_Sht(tmpMatrix_Sht.GetUpperBound(0))
For i As Integer = 1 To idMatrix_Sht.GetUpperBound(0)
idMatrix_Sht(i) = tmpMatrix_Sht(i)
Next
ReDim tmpMatrix_Sht(0)
Loop
lw.WriteLine("It exist rev. triangles with wrong letter or is upside down")
lw.WriteLine(vbLf & vbTab & vbTab & vbTab & "SHEET" & vbTab & vbTab & "QTY")
For i As Integer = 1 To resMatrix_Sht.GetUpperBound(0)
lw.WriteLine(vbTab & "[" & i & "]" & vbTab & "..." & vbTab & resMatrix_Sht(i) & vbTab & resMatrix_Qty(i))
Next
End If

lw.WriteLine(vbLf & "End of report.")

End Function

Public Sub DeselectTriangles()

For Each ids As IdSymbol In theSession.Parts.Work.Annotations.IdSymbols
ids.Unhighlight()
ids.RedisplayObject()
Next

End Sub

End Module

Now it works fine. Thank you very much for your help.
Just some fine tuning now and I am ready to go live.

Best Regards
Gunnar