Hi everyone,
I am faced with quite the challenge here. Basically I want to be able to select 2 or 3 (depending on if I can figure another part out) points on a polyline. Get all of the coordinates in between those points and then draw another polyline over top of it with those coordinates only (From starting point to ending point). If i can figure out direction that is where I believe the 3rd point will come in, so I can pick a middle point so I will know which way the user wants the line (possibly?!?!). Right now I am just having a difficult time trying to get this to work. I realize there are some errors in the code, but here is what I have so far. Also I know I will have to handle arcs too, which will come after I figure this out. Thank you all very much
~Chris
Public Function PolyFollow(PolEnt As AcadEntity, Startpoint As Variant, Midpoint As Variant, Endpoint As Variant) As Double
Dim LVAllPoints As Variant
LVAllPoints = PolEnt.Coordinates
Dim i As Integer
Dim flag As Boolean
Dim newCount As Integer
Dim newCoordset As Double
newCount = 0
flag = False
For i = 0 To UBound(LVAllPoints)
If LVAllPoints(i) = Startpoint(0) Then
If LVAllPoints(i + 1) = Startpoint(1) Then
flag = True
newCoordset(0) = Startpoint(0)
'newCoordSet(1) = Startpoint(1)
newCount = 2
End If
End If
If flag = True Then
If LVAllPoints(i) = Endpoint(0) Then
If LVAllPoints(i + 1) = Endpoint(1) Then
'newCoordSet(newCount) = LVAllPoints(i)
'newCoordSet(newCount + 1) = LVAllPoints(i + 1)
flag = False
Exit For
End If
End If
'newCoordSet(newCount) = LVAllPoints(i)
newCount = newCount + 1
End If
Next
'ThisDrawing.ModelSpace.AddLightWeightPolyline newCoordSet
EDIT: Well I have it mostly working now. This is what I did instead. Kind of long winded but it seems to work.
LVAllPoints = PolEnt.Coordinates
'Variables that will be used for the loop and getting all of the used
'variables.
Dim i As Integer
Dim flag As Boolean
Dim newCount As Integer
'Dim newCoordset() As Double
'newCoordset = PolEnt.Coordinates
newCount = 0
flag = False
'Loop to get all of the points that were selected.
For i = 0 To UBound(LVAllPoints)
If flag = True Then
If LVAllPoints(i) = Endpoint(0) Then
If LVAllPoints(i + 1) = Endpoint(1) Then
newCount = newCount + 1
flag = False
Exit For
End If
End If
newCount = newCount + 1
End If
If LVAllPoints(i) = Startpoint(0) Then
If LVAllPoints(i + 1) = Startpoint(1) Then
flag = True
newCount = 2
i = i + 1
End If
End If
Next
ReDim newCoordset(0 To newCount) As Double
newCount = 0
For i = 0 To UBound(LVAllPoints)
If flag = True Then
If LVAllPoints(i) = Endpoint(0) Then
If LVAllPoints(i + 1) = Endpoint(1) Then
newCoordset(newCount) = LVAllPoints(i)
newCoordset(newCount + 1) = LVAllPoints(i + 1)
flag = False
Exit For
End If
End If
newCoordset(newCount) = LVAllPoints(i)
newCount = newCount + 1
End If
If LVAllPoints(i) = Startpoint(0) Then
If LVAllPoints(i + 1) = Startpoint(1) Then
flag = True
newCoordset(0) = Startpoint(0)
newCoordset(1) = Startpoint(1)
newCount = 2
i = i + 1
End If
End If
Next
ThisDrawing.ModelSpace.AddLightWeightPolyline newCoordset
I now have another question. Does anyone know how i might be able to make sure this works with arcs as well. I actually just discovered another problem if anyone thinks they might be able to help. If i were to pick points and the starting point happens to be after the endpoint in the list it is breaking. How do I continue this loop to get back around. A counter possibly, when I have found all of them exit the loop?!?!