NX 6 Journal How to obtain the object name tag from a selected object
NX 6 Journal How to obtain the object name tag from a selected object
(OP)
I'm using the code below to select and change the color of a face that I created using the "Ruled" feature. I was wondering if it's possible to obtain the "RULED(545)" name from using a function such as object.tag, but 'tag' only returns the tag number not the RULED number.
This is the coded that I'm using, which I just copied and pasted from another forum:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module changeColorOfPreSelectedFaces_v2
Dim theSession As Session = Session.GetSession()
Dim sel As Selection = NXOpen.UI.GetUI.SelectionManager
Sub Main()
'' Integer variable to store color code in.
Dim newColorCode As Integer = 114
'' While loop to ensure that color code is Integer value
While 1
newColorCode = Convert.ToInt32(NXInputBox.GetInputNumber("Color code:", "Enter New Face Color Code", 1))
If newColorCode > 0 And newColorCode < 217 Then
Exit While
End If
MsgBox("Code must be Integer between 1 and 216")
End While
'' The selectFaces method takes an NXobject array by reference
Dim selectedObjectsArray() As NXObject
SelectFaces(selectedObjectsArray)
'' Need to recast the face NXObjects to Displayable objects
Dim faceArray(selectedObjectsArray.Length - 1) As DisplayableObject
For i As Integer = 0 To selectedObjectsArray.Length - 1
faceArray(i) = CType(selectedObjectsArray(i), DisplayableObject)
Next
'' A display modification object is used to change to color of the faces.
Dim changeFaceColor As DisplayModification = theSession.DisplayManager.NewDisplayModification()
With changeFaceColor
.ApplyToAllFaces = False
.NewColor = newColorCode
.Apply(faceArray)
.Dispose()
End With
End Sub
'' The following routine is from GTAC
' ----------------------------------------------
' sub to select faces
' ----------------------------------------------
Sub SelectFaces(ByRef selectedObjects As NXObject())
Dim ui As UI = NXOpen.UI.GetUI
Dim message As String = "Select Faces"
Dim title As String = "Selection"
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim keepHighlighted As Boolean = False
Dim includeFeatures As Boolean = False
Dim response As Selection.Response
Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim selectionMask_array(1) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
End With
response = ui.SelectionManager.SelectObjects(message, title, scope, _
selectionAction, includeFeatures, _
keepHighlighted, selectionMask_array, _
selectedObjects)
If response = Selection.Response.Cancel Or response = Selection.Response.Back Then
Return
End If
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.UF.UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module
This is the coded that I'm using, which I just copied and pasted from another forum:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module changeColorOfPreSelectedFaces_v2
Dim theSession As Session = Session.GetSession()
Dim sel As Selection = NXOpen.UI.GetUI.SelectionManager
Sub Main()
'' Integer variable to store color code in.
Dim newColorCode As Integer = 114
'' While loop to ensure that color code is Integer value
While 1
newColorCode = Convert.ToInt32(NXInputBox.GetInputNumber("Color code:", "Enter New Face Color Code", 1))
If newColorCode > 0 And newColorCode < 217 Then
Exit While
End If
MsgBox("Code must be Integer between 1 and 216")
End While
'' The selectFaces method takes an NXobject array by reference
Dim selectedObjectsArray() As NXObject
SelectFaces(selectedObjectsArray)
'' Need to recast the face NXObjects to Displayable objects
Dim faceArray(selectedObjectsArray.Length - 1) As DisplayableObject
For i As Integer = 0 To selectedObjectsArray.Length - 1
faceArray(i) = CType(selectedObjectsArray(i), DisplayableObject)
Next
'' A display modification object is used to change to color of the faces.
Dim changeFaceColor As DisplayModification = theSession.DisplayManager.NewDisplayModification()
With changeFaceColor
.ApplyToAllFaces = False
.NewColor = newColorCode
.Apply(faceArray)
.Dispose()
End With
End Sub
'' The following routine is from GTAC
' ----------------------------------------------
' sub to select faces
' ----------------------------------------------
Sub SelectFaces(ByRef selectedObjects As NXObject())
Dim ui As UI = NXOpen.UI.GetUI
Dim message As String = "Select Faces"
Dim title As String = "Selection"
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim keepHighlighted As Boolean = False
Dim includeFeatures As Boolean = False
Dim response As Selection.Response
Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim selectionMask_array(1) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
End With
response = ui.SelectionManager.SelectObjects(message, title, scope, _
selectionAction, includeFeatures, _
keepHighlighted, selectionMask_array, _
selectedObjects)
If response = Selection.Response.Cancel Or response = Selection.Response.Back Then
Return
End If
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.UF.UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module





RE: NX 6 Journal How to obtain the object name tag from a selected object
If I understand you correctly, do you want to extract 545 from the feature's name ("RULED(545)")? If I recall correctly, you can access the feature's name with <feat_obj>.GetFeatureName(). You can then extract whatever you need from the result.
HTH!
Marc
NX Software Developer
RE: NX 6 Journal How to obtain the object name tag from a selected object
Thanks,
Nathan
RE: NX 6 Journal How to obtain the object name tag from a selected object
What's your goal with this journal? Perhaps there is an easier way to get what you want.
RE: NX 6 Journal How to obtain the object name tag from a selected object
CODE
NXOpen.UI.GetUI.UFModl.AskFeatName(faceTag, featName)
Where faceTag is the tag of the face feature whose name you need to determine.
Marc
NX Software Developer
RE: NX 6 Journal How to obtain the object name tag from a selected object
'UFModl' is not a member of 'NXOpen.UI'.
RE: NX 6 Journal How to obtain the object name tag from a selected object
You will need:
CODE
NXOpen.UF.UFSession.GetUFSession.UFModl.AskFeatName(faceTag, featName)
Marc
NX Software Developer
RE: NX 6 Journal How to obtain the object name tag from a selected object
This time I keep getting the following error:
'UFModl' is not a member of 'NXOpen.UF.UFSession'
RE: NX 6 Journal How to obtain the object name tag from a selected object
My goal is that after running this portion of the code:
'' The selectFaces method takes an NXobject array by reference
Dim selectedObjectsArray() As NXObject
SelectFaces(selectedObjectsArray)
'' Need to recast the face NXObjects to Displayable objects
Dim faceArray(selectedObjectsArray.Length - 1) As DisplayableObject
For i As Integer = 0 To selectedObjectsArray.Length - 1
faceArray(i) = CType(selectedObjectsArray(i), DisplayableObject)
Next
I'm trying to use Marc's code to use the faceArray(i).tag to obtain the feature name of the face selected.
RE: NX 6 Journal How to obtain the object name tag from a selected object
CODE
Dim theUFSession as NXOpen.UF.UFSession = NXOpen.UF.UFSession.GetUFSession()
theUFSession.Modl.AskFeatName(faceTag, featName)
Marc
NX Software Developer
RE: NX 6 Journal How to obtain the object name tag from a selected object
First for a Ruled feature we actually also have a body of the ruled. We also have a face of the ruled.
Second each of these have a tag associated with them.
Now if for example you use the face tag or the body tag then you cannot get a feature name since these tags do not identify the feature. That is in the previous discussion
theUFSession.Modl.AskFeatName(faceTag, featName)
will not get the feature name because it uses the face tag. Also the body tag will also not get the feature name.
The end result is that to get the feature name in the above line of code you need to know the feature tag.
I think we all need to know more accurately what you are trying to achieve. For example it is simple to select the feature and get the feature name from it.
Frank Swinkels
RE: NX 6 Journal How to obtain the object name tag from a selected object
Sorry, yes I understand the problem now.
How about Splines and Lines is it possible to output the ID number using a Journal. My goal is to put either Lines or Splines automatically created from a Journal in ascending ID order when selected, so that I can know which line/spline I'm calling in my code.
RE: NX 6 Journal How to obtain the object name tag from a selected object
Like the way you showed me for the Points feature name, but is It possible for Line/Spline IDs?
-Nathan
RE: NX 6 Journal How to obtain the object name tag from a selected object
Yes we have both a LineCollection Class and a SplineCollection Class. The code would be very similar to the PointCollection Class. Now before I write the code to get the time line order (the feature name number) I should point out that provided we dont have parent/child limitations it is possible to re-order features in the feature browser. This would change the time line numbers hence the order code can give different results.
I understand you have a good reason for wanting the lines/splines in a specific order. I just think that time line numbers is probably a poor method for controlling the order. I think we have other methods for getting the curves in a correct order (depending on the application for the required order).
Frank Swinkels
RE: NX 6 Journal How to obtain the object name tag from a selected object
When I click and drag to select the sets of splines within my journal. The resulting selected lines objects in the array seem to be in random order, I tried arranging by tag, but the tag number is sometimes lower for splines created after. Line ID seems more in line with the order lines/splines are created. i.e. lines created after a line ID 1801 will not be 1654, it's always a higher ID number.
-Nathan
RE: NX 6 Journal How to obtain the object name tag from a selected object
Marc
NX Software Developer
RE: NX 6 Journal How to obtain the object name tag from a selected object
I have the Associative check box off for lines and splines for this particular journal.
Nathan
RE: NX 6 Journal How to obtain the object name tag from a selected object
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports System.Collections
Module LineOrder
' Explicit Activation
' This entry point is used to activate the application explicitly
Sub Main()
Dim s As Session = Session.GetSession()
Dim lw As ListingWindow = s.ListingWindow
Dim workPart As Part = s.Parts.Work
Dim lcol As LineCollection = workPart.Lines
Dim fcol As Features.FeatureCollection = workPart.Features
Dim feat1 As Features.Feature
Dim featname1 As String = Nothing
Dim linenames As ArrayList = New ArrayList
' Make sure we have lines
If lcol.ToArray().Length = 0 Then
lw.Open()
lw.WriteLine("No Lines found. Exit.")
Return
End If
' Collect all line features
Dim count As Integer = 0
For Each ln As Line In lcol
feat1 = fcol.GetAssociatedFeature(ln)
featname1 = feat1.GetFeatureName.ToString
linenames.Add(featname1)
Next
' Now sort the lineArray
lw.Open()
' Before reordering
lw.WriteLine("Before sorting")
For i As Integer = 0 To linenames.Count - 1
lw.WriteLine(linenames(i))
Next
linenames.Sort()
lw.WriteLine("After sorting")
' After sorting
For i As Integer = 0 To linenames.Count - 1
lw.WriteLine(linenames(i))
Next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'----Other unload options-------
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
Frank Swinkels
RE: NX 6 Journal How to obtain the object name tag from a selected object