Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations JAE on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtaining Adjacent Curves

Status
Not open for further replies.

EngProgrammer

Aerospace
Joined
Jan 14, 2015
Messages
150
Location
US
I am working on a interactive NXOpen app where the user is selecting 2D curve geometry on the workpart / displayed part. I need to determine the attached curves to the user's selection while they are hovering over the curve. (1.) Is there a way to determine the position (start and end points) of the curve while the user is mouse hovering over the geometry? (2.) Is there a way to determine what curves are attached to the start and end points of the curve without looping through all the curves in the workpart / displayed part?

Thanks
 
What version of NX are you using?

The code below (NX 9) prompts you to select a curve, then it collects the selected curve and all connected curves.

Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Sub Main()

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

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

        Const undoMarkName As String = "connected_curves"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        Dim theCurve As Curve
        If SelectCurve("select seed curve", theCurve) = Selection.Response.Cancel Then
            Return
        End If

        Dim section1 As Section
        section1 = workPart.Sections.CreateSection(0.00095, 0.001, 0.5)
        section1.SetAllowedEntityTypes(Section.AllowTypes.OnlyCurves)
        section1.AllowSelfIntersection(True)

        Dim curveChainRule1 As CurveChainRule
        curveChainRule1 = workPart.ScRuleFactory.CreateRuleCurveChain(theCurve, Nothing, True, 0.001)

        Dim rules1(0) As SelectionIntentRule
        rules1(0) = curveChainRule1

        Dim nullNXObject As NXObject = Nothing
        Dim helpPoint1 As Point3d = New Point3d(0, 0, 0)
        section1.AddToSection(rules1, theCurve, nullNXObject, nullNXObject, helpPoint1, Section.Mode.Create, False)



        Dim outputObjs() As NXObject
        section1.GetOutputCurves(outputObjs)

        Dim theData() As SectionData
        section1.GetSectionData(theData)
        Dim theSectionElementData() As SectionElementData
        theData(0).GetSectionElementsData(theSectionElementData)

        Dim sectionElements As New List(Of DisplayableObject)

        lw.WriteLine("number of curves in section: " & outputObjs.Length.ToString)
        For Each temp As SectionElementData In theSectionElementData
            Dim secElement As DisplayableObject
            Dim stConn As DisplayableObject
            Dim stPt As Point3d
            Dim endConn As DisplayableObject
            Dim endPt As Point3d
            temp.GetSectionElementData1(secElement, stConn, stPt, endConn, endPt)
            sectionElements.Add(secElement)
        Next

        For Each temp As DisplayableObject In sectionElements
            Dim secCurve As Curve = DirectCast(temp, Curve)
            lw.WriteLine("curve type: " & secCurve.GetType.ToString)
            lw.WriteLine("curve length: " & secCurve.GetLength.ToString)
            lw.WriteLine("")
        Next

        lw.Close()

    End Sub

    Function SelectCurve(ByVal prompt As String, ByRef selCurve As Curve) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a curve"
        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(3) As Selection.MaskTriple

        Dim selObj As TaggedObject

        With selectionMask_array(0)
            .Type = UFConstants.UF_circle_type
            .Subtype = 0
        End With
        With selectionMask_array(1)
            .Type = UFConstants.UF_conic_type
            .Subtype = UFConstants.UF_all_subtype
        End With
        With selectionMask_array(2)
            .Type = UFConstants.UF_line_type
            .Subtype = UFConstants.UF_all_subtype
        End With
        With selectionMask_array(3)
            .Type = UFConstants.UF_spline_type
            .Subtype = UFConstants.UF_all_subtype
        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
            selCurve = DirectCast(selObj, Curve)
            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

www.nxjournaling.com
 
Thanks Cowski, What if, I only wanted the tangent connected curves??

 
I see that. I've found CurveTangentRule within the namespace NXOpen.SelectionIntentRule but having a problem instantitate it. Have you used this function? Do you have an example?
 
I don't have any example code handy, but it appears that CurveTangentRule is a near drop-in replacement for the CurveChainRule in the code above. You'll need to modify the parameters slightly to specify an angular tolerance.

www.nxjournaling.com
 
thank you. I've got it working. thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top