Finding sketchpoint in a large array of sketchpoints

Finding sketchpoint in a large array of sketchpoints

BromanSillito
Advocate Advocate
467 Views
1 Reply
Message 1 of 2

Finding sketchpoint in a large array of sketchpoints

BromanSillito
Advocate
Advocate

I'm having some slow-down issues with some code I've written in VB that looks thru and identifies certain sketch points in an array of sketch points. The array can vary in size from a few points to a couple of thousand points. Obviously the slowdowns increase with the size of the array.

What I'd like to know is if there is a way of finding points without having to loop through every point in the array every time. I'd like to be able to just look at one row in the array. Is it possible to just look at a small geometric area of points, like a row, using the API? The code below illustrates one of the loops that I am currently using. Any help would be greatly appreciated!

For count = 1 To oSketch.SketchPoints.Count
            Dim sPoint = oSketch.SketchPoints.Item(count)
            Dim sPointX As Double = sPoint.Geometry.X
            Dim sPointY As Double = sPoint.Geometry.Y
            Dim sPointSpot As Point2d = oTG.CreatePoint2d(sPointX, sPointY)
            If Math.Abs(sPointSpot.DistanceTo(oSketchPointSpot) - pitch) < 0.001 Then
                If UCase(checkSide) = "UPLEFT" Then
                    'MsgBox("Distance to sPoint is: " & sPointSpot.DistanceTo(oSketchPointSpot) - pitch & vbNewLine & vbNewLine & "Angle between vectors is: " & (sPointSpot.VectorTo(oSketchPointSpot).AngleTo(vectorY)) * 180 / Math.PI)
                    If Math.Abs(sPointSpot.VectorTo(oSketchPointSpot).AngleTo(vectorY) - Math.PI * 120 / 180) < 0.1 Then
                        If sPointSpot.X > oSketchPointSpot.X And sPointSpot.Y > oSketchPointSpot.Y Then
                            Return True
                        End If
                    End If
                ElseIf UCase(checkSide) = "UPRIGHT" Then
                    'MsgBox("Distance to sPoint is: " & sPointSpot.DistanceTo(oSketchPointSpot) - pitch & vbNewLine & vbNewLine & "Angle between vectors is: " & (sPointSpot.VectorTo(oSketchPointSpot).AngleTo(vectorY)) * 180 / Math.PI)
                    If Math.Abs(sPointSpot.VectorTo(oSketchPointSpot).AngleTo(vectorY) - Math.PI * 60 / 180) < 0.1 Then
                        If sPointSpot.X > oSketchPointSpot.X And sPointSpot.Y < oSketchPointSpot.Y Then
                            Return True
                        End If
                    End If
                ElseIf UCase(checkSide) = "LEFT" Then
                    'MsgBox("Distance to sPoint is: " & sPointSpot.DistanceTo(oSketchPointSpot) - pitch & vbNewLine & vbNewLine & "Angle between vectors is: " & (sPointSpot.VectorTo(oSketchPointSpot).AngleTo(vectorY)) * 180 / Math.PI)
                    If Math.Abs(sPointSpot.VectorTo(oSketchPointSpot).AngleTo(vectorY) - Math.PI * 180 / 180) < 0.1 Then
                        Return True
                    End If
                ElseIf UCase(checkSide) = "RIGHT" Then
                    'MsgBox("Distance to sPoint is: " & sPointSpot.DistanceTo(oSketchPointSpot) - pitch & vbNewLine & vbNewLine & "Angle between vectors is: " & (sPointSpot.VectorTo(oSketchPointSpot).AngleTo(vectorY)) * 180 / Math.PI)
                    If Math.Abs(sPointSpot.VectorTo(oSketchPointSpot).AngleTo(vectorY) - Math.PI * 0 / 180) < 0.1 Then
                        Return True
                    End If
                ElseIf UCase(checkSide) = "DOWNLEFT" Then
                    'MsgBox("Distance to sPoint is: " & sPointSpot.DistanceTo(oSketchPointSpot) - pitch & vbNewLine & vbNewLine & "Angle between vectors is: " & (sPointSpot.VectorTo(oSketchPointSpot).AngleTo(vectorY)) * 180 / Math.PI)
                    If Math.Abs(sPointSpot.VectorTo(oSketchPointSpot).AngleTo(vectorY) - Math.PI * 240 / 180) < 0.1 Then
                        If sPointSpot.X < oSketchPointSpot.X And sPointSpot.Y > oSketchPointSpot.Y Then
                            Return True
                        End If
                    End If
                ElseIf UCase(checkSide) = "DOWNRIGHT" Then
                    'MsgBox("Distance to sPoint is: " & sPointSpot.DistanceTo(oSketchPointSpot) - pitch & vbNewLine & vbNewLine & "Angle between vectors is: " & (sPointSpot.VectorTo(oSketchPointSpot).AngleTo(vectorY)) * 180 / Math.PI)
                    If Math.Abs(sPointSpot.VectorTo(oSketchPointSpot).AngleTo(vectorY) - Math.PI * 300 / 180) < 0.1 Then
                        If sPointSpot.X < oSketchPointSpot.X And sPointSpot.Y < oSketchPointSpot.Y Then
                            Return True
                        End If
                    End If
                Else
                    Return False
                End If
            End If
        Next
0 Likes
Accepted solutions (1)
468 Views
1 Reply
Reply (1)
Message 2 of 2

BromanSillito
Advocate
Advocate
Accepted solution

I was able to bypass this issue by using an array of Point2d objects to locate and manipulate instead of sketch points. The Sketch points were then placed at the resultant Point2d locations. The Point2d object is much faster to work with because it is a mathematical entity rather than an actual sketch entity.

0 Likes