×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

RE: NX 6 Journal How to obtain the object name tag from a selected object

Quote:


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.

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

(OP)
Thanks Mark for the reply.  I'm still a beginner when it comes to NX Visual Basic Journals.  Could you give me an example on how to use <feat_obj>.GetFeatureName().

Thanks,

Nathan

RE: NX 6 Journal How to obtain the object name tag from a selected object

Didn't FrankSwinks already provide you an example in thread561-302759: Obtain Point Reference Number?

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

You will need to look at UFModl.AskFeatName, e.g.

CODE

Dim featName as String
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

(OP)
I'm getting the following message:

'UFModl' is not a member of 'NXOpen.UI'.

RE: NX 6 Journal How to obtain the object name tag from a selected object

Sorry, misread UI with UF...

You will need:

CODE

Dim featName as String
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

(OP)
Hi Marc,

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

(OP)
Hi Cowski,

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

Try this:

CODE

Dim featName as String
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

I am unclear regarding the end objective for the journal under discussion.  Let me, however,  make some observations.

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

(OP)
Hi Frank,

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

(OP)
Frank,

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

Hi Nathan,

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

(OP)
Hi Frank,

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

What about checking the children and parent features of a particular spline?

Marc
NX Software Developer
 

RE: NX 6 Journal How to obtain the object name tag from a selected object

(OP)
Marc,

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

Below is the sample code for ordering the line features based on the time stamp.  A small change of line -> spline would do the same for splines.  Please be aware of my previous comments that this may not help you depending what you want to use the reorded list for.

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

(OP)
Thanks Frank for your help!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources