Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations JAE on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

NX Journal: Turning Expressions into Labels

GiantIsopod

Mechanical
Joined
Jun 24, 2025
Messages
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
 
What is the LOCATION of an expression? They are not graphically displayed objects. It is table like data.
 
"...but as far as I can tell there isn't an easy way to get an expression's location..."

An expression itself is not a displayable object, thus it has no location. There are point expressions that can hold coordinate data that represents a location in the part, but again, the expression itself is not displayable and has no location of its own.

Can you explain more of what you are trying to accomplish?
 
An expression itself is not a displayable object, thus it has no location. There are point expressions that can hold coordinate data that represents a location in the part, but again, the expression itself is not displayable and has no location of its own.

Can you explain more of what you are trying to accomplish?
Basically what I'm trying to do is help move towards Model Based Definition. I need to get all my expressions labeled on my model via balloons or labels with at least some automation (maybe a program feeds the user an expression and the user inputs it?) Again I am new so any and all ideas are super helpful.
 

Part and Inventory Search

Sponsor

Back
Top