Showing results for 
Search instead for 
Do you mean 
Reply

NXOpen How to select a curve in a sketch

Hello,

 

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.

Jonathan

 

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

1 REPLY

Re: NXOpen How to select a curve in a sketch

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
            Return
        End If

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

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

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

        lw.Close()

    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
        Else
            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