CADLisp Tools

Geometry & Polylines

Station/Chainage Along Polyline AutoLISP routine

Report distance along a selected polyline to a picked location. Download the .LSP source below and run the CHAINAGE command after loading it.

⌘ CHAINAGEv1.1.0IntermediateUpdated Sep 18, 2026

What it does

Station/Chainage Along Polyline with the CHAINAGE AutoLISP command

Transforms the picked UCS point to WCS, projects it to the nearest location on one supported polyline, and reports accumulated distance from its start.

AutoLISP command
CHAINAGE
Difficulty
Intermediate

Applicable disciplines

CAD workflows that use this routine

Requirements and compatibility

What it needs

AutoLISPVisual LISP

Software rows marked “Not tested” are not compatibility claims. Test the routine in a copy of your drawing and CAD version.

Downloadable source code

Review the station-chainage-along-polyline.lsp AutoLISP code

station-chainage-along-polyline.lspAUTOLISP
;; CADLisp Tools - Station/Chainage Along Polyline
(vl-load-com)

(defun ct-ch:supported-polyline-p (data / flags)
  (and data
       (or (= (cdr (assoc 0 data)) "LWPOLYLINE")
           (and (= (cdr (assoc 0 data)) "POLYLINE")
                (setq flags (cdr (assoc 70 data)))
                (= 0 (logand flags 80))))))

(defun c:CHAINAGE (/ data distance ent nearest pick point)
  (cond
    ((null (setq pick (entsel "\nPick a polyline: ")))
      (prompt "\nNo polyline selected."))
    ((not (ct-ch:supported-polyline-p
            (setq data (entget (setq ent (car pick))))))
      (prompt "\nThe selected object is not a supported polyline."))
    ((null (setq point (getpoint "\nPick station location: ")))
      (prompt "\nNo station point supplied."))
    ((vl-catch-all-error-p
       (setq nearest
         (vl-catch-all-apply 'vlax-curve-getClosestPointTo
           (list ent (trans point 1 0)))))
      (prompt "\nThe closest point could not be calculated."))
    ((vl-catch-all-error-p
       (setq distance
         (vl-catch-all-apply 'vlax-curve-getDistAtPoint (list ent nearest))))
      (prompt "\nThe chainage could not be calculated."))
    (T
      (prompt (strcat "\nDistance along from polyline start: " (rtos distance 2 3)))))
  (princ))

Setup

How to install the station-chainage-along-polyline.lsp file

  1. 1Download and review the source code.
  2. 2Load the .lsp file with APPLOAD in a copy of a drawing.
  3. 3Keep the routine session-only until it has been tested for your CAD version and standards.

Command workflow

How to run the CHAINAGE command

  1. 1Run CHAINAGE.
  2. 2Pick a supported polyline.
  3. 3Pick a nearby point and read the distance along.

Worked example

Example: Check chainage at a utility crossing.

  1. Run CHAINAGE.
  2. Pick the route.
  3. Pick the crossing.
Expected result

Distance from the polyline start to the closest projected point is reported.

Read before use

Notes and limitations

  • Uses raw drawing units and the polyline's stored start direction.
  • Polygon and polyface meshes are rejected.
  • Does not format station notation such as 1+234.56.
  • Not manually CAD-tested.

Version history

Changelog

v1.1.0Sep 18, 2026Correct UCS-to-WCS projection and guard unsupported or invalid curves.
v1.0.0Sep 18, 2026Initial closest-point chainage routine.

Keep automating

Related tools

Geometry & Polylines3 disciplines

Bearing Between Points

Report clockwise azimuth from north between two picked points.

⌘ PTBEARINGIntermediateCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →
Data Extraction4 disciplines

Cable/Route Length

Total selected route polylines and apply an optional allowance percentage.

⌘ CABLELENIntermediateCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →
Data Extraction4 disciplines

Pipeline Length by Layer

Summarize selected polyline length totals grouped by layer.

⌘ PIPELENIntermediateCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →