Find distance along polyline of each vertex

Find distance along polyline of each vertex

Anonymous
Not applicable
3,580 Views
6 Replies
Message 1 of 7

Find distance along polyline of each vertex

Anonymous
Not applicable

Hi

 

I have written a lisp to extract the vertices of a polyline, but I now need to give the distance along the polyline that each vertex is.

 

i.e. the first vertex will have a zero distance along the polyline, the second vertex would have a distance along the polyline equal to the distance between the first and the second vertex, the third will be the sum of the distance between the first, second and third vertex.

 

To make things a little easier, the only kind of polyline being analysed will be one that starts with a line, goes into an arc, then a line, then an arc (repeating between lines and arcs for however long the polyline may be), and ends in a line - Just by the way this is for a road...that is why alternating between lines and arcs, and I am needing stake values along the polyline for each vertex.

 

Please can somebody help?

 

Thanks

 

Derryck

0 Likes
Accepted solutions (1)
3,581 Views
6 Replies
Replies (6)
Message 2 of 7

Kent1Cooper
Consultant
Consultant

(vlax-curve-getDistAtParam YourEntityName 0) will give you the 0 distance at the first vertex [Parameter value 0], if in fact you need to "find" that.

(vlax-curve-getDistAtParam YourEntityName 1) will give you the distance along the Polyline at the second vertex.

(vlax-curve-getDistAtParam YourEntityName 2) will give you the overall distance along the Polyline at the third vertex.

... etc. ...

 

You can use the VLA object conversion of the Polyline instead of its entity name, if you have other reasons to need the Polyline converted to one.

 

[There are very rare circumstances under which the Parameter values can get screwed up, and not fall at integer values at the vertices, so it is remotely possible to sometimes get the wrong results from that function.  Search for "quirky Polyline" for some discussions about it.  That can be avoided, if necessary, by getting a list of vertices as points, and using (vlax-curve-getDistAtPoint) functions instead.  Since it seems you already have those points collected, you can just use them anyway and avoid the issue.]

 

Run (vl-load-com) to make the (vlax-curve-...) functions available first, if necessary [i.e. if you get a no-function-defined kind of error message].

 

[EDIT -- if you caught this really quickly, before I fixed it, I had originally omitted the "curve-" word from the function names at the beginning -- use the corrected version as edited.]

 

 

Kent Cooper, AIA
Message 3 of 7

ВeekeeCZ
Consultant
Consultant

There is a bunch of vlax-curve-* commands... all very handy.

List of them you can find here

http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-4684C76F-02F7-4989-AA53-C886E528350A

0 Likes
Message 4 of 7

Anonymous
Not applicable
Hi Kent

Thanks. But when I do this it says:

error: unable to get ObjectID?

Cheers

Derryck
0 Likes
Message 5 of 7

Anonymous
Not applicable
I assume when you say 'YourEntityName' you mean my polyline?
0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:
I assume when you say 'YourEntityName' you mean my polyline?

Yes, the Polyline's entity name.  If you are selecting it with (entsel), the entity name is the first thing in the list of two things that (entsel) returns [the second is the point where you picked it], so you need to extract it.

 

(setq esel "\nSelect Polyline: "); returns list of entity-name and selection point,

then

(setq ent (car esel)); returns Polyline's entity name,

then

(vlax-curve-getPointAtParam ent 1); etc.

Kent Cooper, AIA
0 Likes
Message 7 of 7

hmsilva
Mentor
Mentor

@Anonymous wrote:

Hi

 

I have written a lisp to extract the vertices of a polyline, but I now need to give the distance along the polyline that each vertex is.

 

i.e. the first vertex will have a zero distance along the polyline, the second vertex would have a distance along the polyline equal to the distance between the first and the second vertex, the third will be the sum of the distance between the first, second and third vertex.

...


Hi Derryck,

 

in addition to other advices, if you have a code 'to extract the vertices of a polyline', probably, you have no need to step thru the polyline parameters to get the distances, you can use those points to get the distance from the polyline start to each point.

 

(vlax-curve-getdistatpoint obj pt)

 

Hope this helps,
Henrique

EESignature

0 Likes