×
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

Obtaining Adjacent Curves

Obtaining Adjacent Curves

Obtaining Adjacent Curves

(OP)
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

RE: Obtaining Adjacent Curves

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

RE: Obtaining Adjacent Curves

(OP)
Thanks Cowski, What if, I only wanted the tangent connected curves??

RE: Obtaining Adjacent Curves

There is also a .CreateRuleCurveTangent(...) method that might be useful.

www.nxjournaling.com

RE: Obtaining Adjacent Curves

(OP)
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?

RE: Obtaining Adjacent Curves

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

RE: Obtaining Adjacent Curves

(OP)
thank you. I've got it working. thanks 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