Finding the End Vertex of a Polyline

Finding the End Vertex of a Polyline

Civil3DReminders_com
Mentor Mentor
464 Views
4 Replies
Message 1 of 5

Finding the End Vertex of a Polyline

Civil3DReminders_com
Mentor
Mentor
How does one find the end vertex of a LWpolyline? I want to add a point at the beginning and end of a LWpolyline. The start is easy since it is 0, but can't seem to think of a way to find the end vertex easily.

Thanks,

Christopher
Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
0 Likes
465 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
' Create the selection set
Set lo_SSet = ThisDrawing.SelectionSets.Add("SSET")
Set lo_SSetDims = ThisDrawing.SelectionSets.Add("SSETDIMS")

' Add entities to a selection set by prompting user to select on the
screen
ThisDrawing.Utility.Prompt vbCrLf & "Select Profile to process ..."
lo_SSet.SelectOnScreen

' Return Insertion point using a prompt
lo_Pnt = ThisDrawing.Utility.GetPoint(, "Pick Insertion point : ")

' Extract Vertices
Set lo_LWPline = lo_SSet.Item(0)
lv_Coords = lo_LWPline.Coordinates

dim LI_I as Integer

LI_I = ubound(lv_Coords )

Something like this.

Dale

"ChristopherF" wrote in message news:5789951@discussion.autodesk.com...
How does one find the end vertex of a LWpolyline? I want to add a point at
the beginning and end of a LWpolyline. The start is easy since it is 0, but
can't seem to think of a way to find the end vertex easily.

Thanks,

Christopher
0 Likes
Message 3 of 5

Anonymous
Not applicable
Hi Chris,

An LWPolyline object has a property of Coordinates.

If you define a variant variable you can do this:

Sub AddToPolyline
Dim v as Variant
Dim i as Integer
Dim dCoords() as double
Dim oPoly as AcadLWPolyline
... Select the polyline in any suitable way
v = oPoly.Coordinates
redim dCoords(0 to Ubound(v) + 4) ' You need 4 more items - 2 at each
end to store the new points
' Add the new start
dCoords(0) = Xvalue of new start point
dCoords(1) = Yvalue of new start point
' Add the new end
dCoords(Ubound(dCoords) - 1) = Xvalue of new endpoint
dCoords(Ubound(dCoords)) = Yvalue of new end point
' Transfer the existing coordinates to the middle section of the polyline
for i = 0 to Ubound(v)
dCoords(i + 2) = v(i)
next i
oPoly.Coordinates = dCoords
oPoly.Update
End Sub

--

Laurie Comerford


wrote in message news:5789951@discussion.autodesk.com...
How does one find the end vertex of a LWpolyline? I want to add a point at
the beginning and end of a LWpolyline. The start is easy since it is 0, but
can't seem to think of a way to find the end vertex easily.

Thanks,

Christopher
0 Likes
Message 4 of 5

Civil3DReminders_com
Mentor
Mentor
Thanks Laurie, didn't know about the UBound.

Here is the code I ended up with for anyone interested:

oAcadLWpolyline has already been found:
Dim dEndPoint As Variant
Dim v As Variant
Dim l As Long
v = oAcadLWpolyline.Coordinates
l = ((UBound(v) + 1) / 2) - 1
dEndPoint = oAcadLWpolyline.Coordinate(l)
Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
0 Likes
Message 5 of 5

jbooth
Advocate
Advocate
dim result as Variant
result = polyline.Coordinate (ubound(polyline.Coordinates) \ 2 - 1)

The \ operator is an integer based operator, and will automatically discard the remainder of the division for you.

ie: 7 / 5 = 1.4 (double) but 7 \ 5 = 1 (integer)

To add a vertex to the end of a polyline, call the AddVertex() method using the index you calculated (obviously).
0 Likes