Showing results for 
Search instead for 
Did you mean: 

NXOpen How to select a curve in a sketch

Siemens Creator Siemens Creator
Siemens Creator



I would like to select a curve (an arc to find the diameter). This curve for this part, is in a sketch.

I do not find how to do.


I miss understanding something between UF and cpp function: 

  • If I use 'UF_OBJ_ask_type_and_subtype' I find type 5 (= UF_circle_type).

OK, fine.


  • If I use FeatureType() I find "SKETCH".

I can cast my feature in sketch and do many things (list curves...) but not to have The curve I select.


Thank in advanced for your help.



Enclosed a simple part and simplified code (it compile and is usable as dll)


Re: NXOpen How to select a curve in a sketch

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

My code is in VB as opposed to C++, but I think it conveys the idea.


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Sub Main()

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

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow

        Dim theArc As Arc
        If SelectArc(theArc) = Selection.Response.Cancel Then
        End If

        lw.WriteLine("Diameter: " & theArc.Radius * 2)


    End Sub

    Function SelectArc(ByRef selArc As Arc) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select an Arc"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple
        Dim prompt As String = "Select Arc"
        Dim selObj As TaggedObject

        With selectionMask_array(0)
            .Type = UFConstants.UF_circle_type
            .Subtype = 0
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
         title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selObj, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            selArc = Utilities.NXObjectManager.Get(selObj.Tag)
            Return Selection.Response.Ok
            Return Selection.Response.Cancel
        End If

    End Function

    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: NXOpen How to select a curve in a sketch

Valued Contributor
Valued Contributor

@cowski1 with this code only one line can be selected. How would it be if I wanted to make it continous until cancel button clicked?


Re: NXOpen How to select a curve in a sketch

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

If you want to select multiple objects, use the .SelectTaggedObjects method rather than .SelectTaggedObject. An article here explains their use. The article actually references the older .SelectObject and .SelectObjects methods, but the newer .SelectTaggedObject and .SelectTaggedObjects methods are pretty much direct replacements.