cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting objects by name in NX Open

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Hello everyone!

 

I can’t understand how to select an object in NX using its name. For example, I have a CSYS named ‘Ref’ (not the CSYS feature, but the CSYS itself). How can I make a selection in NX Open if I know that the CSYS I need is named ‘Ref’?

26 REPLIES

Re: Selecting objects by name in NX Open

Honored Contributor
Honored Contributor

Cycle through the coordinate systems in the part looking for the one named "REF". Save a reference to the one that you find.

 

Option Strict Off
Imports System
Imports NXOpen

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim refCsys As CoordinateSystem = Nothing

        'find coordinate system named "REF"
        For Each temp As CoordinateSystem In workPart.CoordinateSystems
            If temp.Name = "REF" Then
                refCsys = temp
            End If
        Next

        If Not IsNothing(refCsys) Then
            lw.WriteLine("REF csys found")
        Else
            lw.WriteLine("REF csys not found")
            Return
        End If

        'do something with it
        refCsys.Highlight()
        'use part cleanup -> remove extraneous highlighting to get it back to normal

        lw.Close()

    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

Re: Selecting objects by name in NX Open

Legend
Legend

You could also use the UF wrappers.  UFObj.CycleByName  or  UFObj.CycleByNameAndType.

Re: Selecting objects by name in NX Open

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Do I get it right that these UF wrappers cycle through any object? So that if I have body and datum with the same name, it will pick them both?

Re: Selecting objects by name in NX Open

Legend
Legend

Yes, UFObj.CycleByName will cycle through all objects with the given name.  It is up to you to determine the object type.

Re: Selecting objects by name in NX Open

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

So it's similar to using the Class Selection window in interactive mode and entering object name there?

Re: Selecting objects by name in NX Open

Legend
Legend

Yes that is right.

Re: Selecting objects by name in NX Open

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Do you have any C# sample with this wrapper?

Re: Selecting objects by name in NX Open

Siemens Phenom Siemens Phenom
Siemens Phenom

 

There is a related function that you can use to cycle by name, but only for a specified type: CycleByNameAndType().  You can find the types listed in ...\ugopen\uf_object_types.h

 

There is a sample on the Solution center called

 

Sample NX Open .NET C# program : find view with given name

 

 You could also search for "nx_api3561" to find it quickly.

Re: Selecting objects by name in NX Open

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Thanks! I'll have a look and get back to you if I have questions.