Forums:
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>