GiantIsopod
Mechanical
- Jun 24, 2025
- 3
Hi all,
I'm trying to make an NXOpen program using VB that can loop through expressions in a part, and, if applicable, create a label at the associated location. I can both find expressions and make labels (each individually), but as far as I can tell there isn't an easy way to get an expression's location... only its "source." I am fairly new to NX so truly any kind of help would be greatly appreciated. I have been browsing the NXOpen documentation and it seems like maybe Annotations.PmiLabel could be helpful(?) but I really don't know.
Thank you!!
Here is some code I have to determine if an expression is present. I know it's not much, but it's a start.
Imports System
Imports NXOpen
Imports NXOpen.Annotations
Imports System.Windows.Forms
Module PmiNoteExample
Dim theSession As Session = Nothing
Dim workPart As Part = Nothing
Sub Main()
Try
' Initialize the NX session and work part.
theSession = Session.GetSession()
workPart = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
' Create an undo mark for the session.
Dim markId1 As Session.UndoMarkId = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Expression")
' Look up the expression
Dim expression1 As Expression = CType(workPart.Expressions.FindObject("A2"), Expression)
If expression1 IsNot Nothing Then
Dim outputMsg As String = "Found Expression: " & expression1.Name
theSession.LogFile.WriteLine(outputMsg)
MessageBox.Show(outputMsg, "Expression Found")
Else
Dim notFoundMsg As String = "Expression 'A2' not found."
theSession.LogFile.WriteLine(notFoundMsg)
MessageBox.Show(notFoundMsg, "Expression Not Found")
End If
Catch ex As Exception
Dim errMsg As String = "Error encountered: " & ex.Message
If theSession IsNot Nothing Then
theSession.LogFile.WriteLine(errMsg)
End If
MessageBox.Show(errMsg, "Error")
End Try
End Sub
End Module
I'm trying to make an NXOpen program using VB that can loop through expressions in a part, and, if applicable, create a label at the associated location. I can both find expressions and make labels (each individually), but as far as I can tell there isn't an easy way to get an expression's location... only its "source." I am fairly new to NX so truly any kind of help would be greatly appreciated. I have been browsing the NXOpen documentation and it seems like maybe Annotations.PmiLabel could be helpful(?) but I really don't know.
Thank you!!
Here is some code I have to determine if an expression is present. I know it's not much, but it's a start.
Imports System
Imports NXOpen
Imports NXOpen.Annotations
Imports System.Windows.Forms
Module PmiNoteExample
Dim theSession As Session = Nothing
Dim workPart As Part = Nothing
Sub Main()
Try
' Initialize the NX session and work part.
theSession = Session.GetSession()
workPart = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
' Create an undo mark for the session.
Dim markId1 As Session.UndoMarkId = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Expression")
' Look up the expression
Dim expression1 As Expression = CType(workPart.Expressions.FindObject("A2"), Expression)
If expression1 IsNot Nothing Then
Dim outputMsg As String = "Found Expression: " & expression1.Name
theSession.LogFile.WriteLine(outputMsg)
MessageBox.Show(outputMsg, "Expression Found")
Else
Dim notFoundMsg As String = "Expression 'A2' not found."
theSession.LogFile.WriteLine(notFoundMsg)
MessageBox.Show(notFoundMsg, "Expression Not Found")
End If
Catch ex As Exception
Dim errMsg As String = "Error encountered: " & ex.Message
If theSession IsNot Nothing Then
theSession.LogFile.WriteLine(errMsg)
End If
MessageBox.Show(errMsg, "Error")
End Try
End Sub
End Module