Quantcast
Channel: NX Journaling - Journaling / NXOpen API
Viewing all articles
Browse latest Browse all 787

Terminating a program on Error

$
0
0

Hi all,

I would like to test, if an expression exist in NX. If not, it should show a message and terminate the program without running the rest of the code. If no error, it should run all the code. But I did not find a way to exit the try-code to go directly to the end.

Option Strict Off
Imports System
Imports NXOpen
Imports System.Windows.Forms
 
Module FindExpression
 
	Sub Main ()	
 
	Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
	Dim workPart As NXOpen.Part = theSession.Parts.Work
	Dim displayPart As NXOpen.Part = theSession.Parts.Display
 
        Dim expNameToFind As String = "MassPropVolume"
        Dim myExp As Expression
 
        Try
            myExp = workPart.Expressions.FindObject(expNameToFind)
 
			Catch ex As NXException
				If ex.ErrorCode = 3520016 Then
					'Expression not exist
					MessageBox.Show("Part has no material expression" & _
					ControlChars.NewLine & "Save part first to create them!", "Error", _
					MessageBoxButtons.OK, MessageBoxIcon.Error)
				Else
					'other error
					MessageBox.Show("Error" & ex.ErrorCode)
				End If
			Finally
		End Try
 
' Code from here should run in case of no error
' code to run		
 
' in case of error we will go to the end immediatelly
ProgEnd:
 
	End Sub
End Module
<code>

Viewing all articles
Browse latest Browse all 787

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>