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!

nxopen line arc crawler

Status
Not open for further replies.

EngProgrammer

Aerospace
Joined
Jan 14, 2015
Messages
150
Location
US
Dear Forum.

I am looking for some help in creating nxopen code for crawling along a set of lines and arcs connected to each other. First the user selects the start point and end point of the line/arc connected geometry. From a coding point of view is there a way to programmatically select all the lines encompassing a box by these points? If I can get all the lines and arcs via a box around the points. Then I can possibility sort all the lines and connect the dots.

Looking for advice and suggestions on various approaches.

Thank you.
 
Dear Forum,

Here's a cool recursive function to walk through tangent / connected lines and arcs of geometry within a part and get all the lines and arc that are tangent to each other. Finally, got something working, so I decided to post it in the hope of getting some feedback. Had to use AskCurveProps to get the start and end points of the ug arcs. Any commnets are welcome:

Code:
    Function TopologyWalker(ByRef currentObj As NXObject, _
                            ByRef currentPoint As Point3d, _
                            ByRef frmGeometry As ArrayList, _
                            ByRef toGeometry As ArrayList, _
                            ByRef index As Integer) As ArrayList

        If currentObj Is Nothing Then
            Return toGeometry
        End If

        index = index + 1

        Dim currentArc As Arc
        Dim currentLine As Line
        Dim currentStartPoint As Point3d
        Dim currentEndPoint As Point3d

        Dim nextObj As NXObject = Nothing
        Dim nextPoint As Point3d = Nothing

        Try
            currentArc = CType(currentObj, Arc)
            currentStartPoint = ArcStartPt(currentArc)
            currentEndPoint = ArcEndPt(currentArc)
        Catch ex As Exception
            currentLine = CType(currentObj, Line)
            currentStartPoint = currentLine.StartPoint
            currentEndPoint = currentLine.EndPoint
        End Try

        Dim tryArc As Arc = Nothing
        Dim tryLine As Line = Nothing

        Dim tryStartPoint As Point3d
        Dim tryEndPoint As Point3d

        Dim rtnGeometry As New ArrayList

        For Each obj As NXObject In frmGeometry
            rtnGeometry.Add(obj)
        Next

        Dim i As Integer = 0

        Dim nxPoint As Point

        For Each obj As NXObject In frmGeometry

            Try
                tryArc = CType(obj, Arc)
                tryStartPoint = ArcStartPt(tryArc)
                tryEndPoint = ArcEndPt(tryArc)
            Catch ex As Exception
                tryLine = CType(obj, Line)
                tryStartPoint = tryLine.StartPoint
                tryEndPoint = tryLine.EndPoint
            End Try

            nxPoint = workpart.Points.CreatePoint(tryStartPoint)
            nxPoint.SetVisibility(SmartObject.VisibilityOption.Visible)
            nxPoint.RedisplayObject()

            nxPoint = workpart.Points.CreatePoint(tryEndPoint)
            nxPoint.SetVisibility(SmartObject.VisibilityOption.Visible)
            nxPoint.RedisplayObject()

            If distance(tryStartPoint, currentStartPoint) < 0.0001 And distance(tryEndPoint, currentEndPoint) < 0.0001 Then
                Continue For
            End If

            If distance(tryStartPoint, currentPoint) < 0.0001 Or distance(tryEndPoint, currentPoint) < 0.0001 Then
                If distance(tryStartPoint, currentPoint) < 0.0001 Then
                    nextObj = obj
                    toGeometry.Add(nextObj)
                    nextPoint = tryEndPoint
                    rtnGeometry.RemoveAt(i)
                    Exit For
                End If

                If distance(tryEndPoint, currentPoint) < 0.0001 Then
                    nextObj = obj
                    toGeometry.Add(nextObj)
                    nextPoint = tryStartPoint
                    pmi.Note(theSession, workpart, "node" & index.ToString(), nextPoint)
                    rtnGeometry.RemoveAt(i)
                    Exit For
                End If
            End If

            i = i + 1

        Next

        TopologyWalker(nextObj, nextPoint, rtnGeometry, toGeometry, index)

        Return Nothing

    End Function

    Function distance(ByVal PtA As Point3d, ByVal PtB As Point3d) As Double
        Return Math.Sqrt((PtA.X - PtB.X) ^ 2 + (PtA.Y - PtB.Y) ^ 2 + (PtA.Z - PtB.Z) ^ 2)
    End Function

    Function ArcEndPt(ByVal iArc As Arc) As Point3d
        Dim stPt(2) As Double
        Dim edPt(2) As Double
        Dim junk3(2) As Double
        Dim junk1 As Double
        ufs.Modl.AskCurveProps(iArc.Tag, 1, stPt, junk3, junk3, junk3, junk1, junk1)

        Dim pt As Point3d = New Point3d(stPt(0), stPt(1), stPt(2))

        Return pt
    End Function
    Function ArcStartPt(ByVal iArc As Arc) As Point3d
        Dim stPt(2) As Double
        Dim edPt(2) As Double
        Dim junk3(2) As Double
        Dim junk1 As Double
        ufs.Modl.AskCurveProps(iArc.Tag, 0, stPt, junk3, junk3, junk3, junk1, junk1)

        Dim pt As Point3d = New Point3d(stPt(0), stPt(1), stPt(2))

        Return pt
    End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top