Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Determine end of Polyline

3 REPLIES 3
Reply
Message 1 of 4
125minden
943 Views, 3 Replies

Determine end of Polyline

If I have an open polyline with more than 2 vertices, and I select (using entsel) the pline near one end, how could I determine the point (x,y)of the end I picked nearest to and not the other end?

I can only generate a points list of the pline and go no further.

thanks for any help ...I'm stumped

 

3 REPLIES 3
Message 2 of 4
Kent1Cooper
in reply to: 125minden


@125minden wrote:

If I have an open polyline with more than 2 vertices, and I select (using entsel) the pline near one end, how could I determine the point (x,y)of the end I picked nearest to and not the other end?

I can only generate a points list of the pline and go no further.

thanks for any help ...I'm stumped

 


I assume you mean the nearest extreme end of the Polyline, not necessarily the nearest segment endpoint [which you could get with (osnap)].  For that, the Polyline's (vlax-curve-...) values are probably the best source.  One way to do it [untested]:

 

(setq

  plsel (entsel "\nSelect Polyline: ")

  plent (car plsel)

  plCloserEnd    (if

      (<

        (vlax-curve-getDistAtPoint

          plent

          (osnap (cadr plsel) "_nea")

        )

        (/

          (vlax-curve-getDistAtParam

            plent

            (vlax-curve-getEndParam plent)

          )

          2

        ); end /

      ); end <

      (vlax-curve-getStartPoint plent)

      (vlax-curve-getEndPoint plent)

    ); end if & plCloserEnd

); end setq

 

A little curiosity I've discovered:  If you use

 

(vlax-curve-getDistAtPoint plent (vlax-curve-getEndPoint plent))

 

instead of the Param versions to get an object's overall length, it will return 0 for closed things, whereas the Param version returns the length correctly whether the object is open or closed.  In your particular case of open Polylines, either would work [after all, for a closed Polyline, the same point would be returned no matter where you pick on it, anyway].

Kent Cooper, AIA
Message 3 of 4
125minden
in reply to: Kent1Cooper

Hey thanks Kent that work very nicely. Smiley Happy

 

I must admit I have never used those valx-curve-xxx functions before. So I have learnt something interesting from you! Beats me why that family of functions are called vlax-CURVE when 95% of the time the user is dealing with striaght plines, lines etc.

Message 4 of 4
Kent1Cooper
in reply to: 125minden


@125minden wrote:

Hey thanks Kent that work very nicely. .... 

.... Beats me why that family of functions are called vlax-CURVE when 95% of the time the user is dealing with striaght plines, lines etc.


You're welcome, and yes, that "curve" thing is a surprise to a lot of people -- I used to wonder about it, too, but I've gotten used to it. 

I just noticed a bit of wacky formatting in the code I posted:

 

  plCloserEnd    (if

      (<

 

ought to be

 

  plCloserEnd

    (if

      (<

 

[it wouldn't affect the working of it, just the readability].

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost