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