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
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
;; 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
- 1Download and review the source code.
- 2Load the .lsp file with APPLOAD in a copy of a drawing.
- 3Keep the routine session-only until it has been tested for your CAD version and standards.
Command workflow
How to run the CHAINAGE command
- 1Run CHAINAGE.
- 2Pick a supported polyline.
- 3Pick a nearby point and read the distance along.
Worked example
Example: Check chainage at a utility crossing.
- Run CHAINAGE.
- Pick the route.
- Pick the crossing.
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