What is a good way to go about finding out whether the endpoints of a line are coincident with a particular point?
I am not sure whether the context is important but will describe it and then get to the point:
Broadly, I have a layout with two different types of nodes. Call them LV nodes and Houses. The idea is to draw lines between them which would be electrical service connections. A node can connect to multiple houses but a house can only connect to a single node. Each node can have X number of service connections and the length of each connection should be as short as possible(within reason).
The current philosophy is to use ElementScanCriteria to find all of the nodes and houses and then to loop through all of the nodes one at a time and find the closest X Houses. Then it would, one at a time check through each house to see if it has been connected or not(*** This is where the difficulty is ***). Once it has found out whether the house is connected or not, it checks to see whether the existing connection (if there is one) is longer than the possible new one and if it is, the existing connection is deleted and a new one is made.
The current function I am working on is "Existing Connection" and is to return a True or False based on whether a house is connected or not. The function takes in a point and then checks whether there is an endpoint of a particular line style at the target point. I am not sure whether I am using the ElementScanCriteria properly or if there is just flat out a better way of doing it.
Function ExistingConnection(TargetPoint As Point3d) As Boolean
Dim oScanCriteria As ElementScanCriteria
Dim oScanEnumerator As ElementEnumerator
Dim oElement As Element
ExistingConnection = False
Set oScanCriteria = New ElementScanCriteria
oScanCriteria.ExcludeNonGraphical
oScanCriteria.ExcludeAllTypes
oScanCriteria.IncludeType (msdElementTypeLine)
oScanCriteria.IncludeLineStyle ActiveDesignFile.LineStyles("CustomLineStyle")
Set oScanEnumerator = ActiveModelReference.Scan(oScanCriteria)
Do While oScanEnumerator.MoveNext
Set oElement = oScanEnumerator.Current
If oElement.AsLineElement.EndPoint.X - TargetPoint.X = 0 Then
If oElement.AsLineElement.EndPoint.Y - TargetPoint.Y = 0 Then
If oElement.AsLineElement.EndPoint.Z - TargetPoint.Z = 0 Then
ExistingConnection = True
End If
End If
End If
Loop
End Function
Sometimes the function appears to work and other times, not. It is consistent about the results if I use a particular house as target point, it will either always give true when connected or always give false if connected which leads me to think that it might be the scan criteria that need to be better defined.