Lisp to tell me how far along a polyline I am (chainage)

Lisp to tell me how far along a polyline I am (chainage)

barry2104
Collaborator Collaborator
908 Views
3 Replies
Message 1 of 4

Lisp to tell me how far along a polyline I am (chainage)

barry2104
Collaborator
Collaborator

I have a polyline representing the middle/axis of a road, containing straights and arcs. The road/axis starts at chainage 0 and Ends at chainage 6543.21 (which equates to the length of the axis/polyline).

I want to be able to load a Lisp that lets me pick any Point along the polyline ("nearest to" snap, not just at nodes) and have the command line tell me how far along I am / what the "chainage" is at that Point.

 

Has anyone got (or can write) such a Lisp that would do this?

Running AutoCAD Architecture 2020, in German
0 Likes
Accepted solutions (1)
909 Views
3 Replies
Replies (3)
Message 2 of 4

DannyNL
Advisor
Advisor

Can you post an example drawing?

Always easier to see what needs to be done and test.

0 Likes
Message 3 of 4

marko_ribar
Advisor
Advisor
Accepted solution

Untested...

 

(defun c:foo ( / c p l )
  (vl-load-com)
  (while
    (or
      (not (setq c (car (entsel "\nPick curve..."))))
      (if c
        (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getstartpoint (list c)))
      )
    )
    (prompt "\nMissed or picked wrong entity type...")
  )
  (initget 1)
  (setq p (getpoint "\nPick point on curve : "))
  (setq l (vlax-curve-getdistatpoint c (vlax-curve-getclosestpointto c p)))
  (prompt "\nYou picked point at distance : ") (princ (rtos l 2 50)) (prompt " from its start point of curve...")
  (princ)
)
Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 4 of 4

Kent1Cooper
Consultant
Consultant

In simplest terms, without verifying appropriate selection, etc., and reporting using whatever your distance Units mode and precision settings are:

 

(vl-load-com); [if needed]

(defun C:RCD (/ esel); = Report Chainage Distance

  (setq esel (entsel "\nSelect Polyline at desired location: "))

  (prompt

    (strcat

      "\nChainage distance at that point is "

      (rtos (vlax-curve-getDistAtPoint (car esel) (osnap (cadr esel) "_nea")))

    )

  )

)

Kent Cooper, AIA