• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
blog.draftsperson.net

blog.draftsperson.net

the art of technical drawing

blog.draftsperson.net

PDIST LISP: Label Running Distances Along a Polyline

September 19, 2020

Last updated July 28, 2026

PDIST labels a polyline with running distances. Pick one, and it writes the cumulative length above every vertex — zero at the start, then the distance travelled at each corner, all the way to the total at the end. It is chainage annotation for anything measured along its length: a road centreline, a pipe run, a fence, a boundary traverse.

It is by Art Whitton, and unusually for a routine of this size it is written as a teaching example: the header carries a full variable table, and the code is split into four named parts — a setup function, the working part, a clean exit and a replacement error handler. If you want to see how a small AutoLISP program should be structured, this is a better read than most.

Read the first line of the file before you download

The author’s own warning is unambiguous, and it is the first thing in the file: Release 13 and earlier only. The description repeats it: it does not work with lightweight polylines.

That is a hard limit, not a caution. The routine reads a polyline’s vertices as separate objects following the polyline itself, which is how the older heavyweight polylines are built. Lightweight polylines, which AutoCAD has created by default since Release 14, keep their vertices inside the single object — there is nothing for the routine to step through. It refuses them outright rather than misbehaving: the selection loop only accepts an entity whose type is POLYLINE, so clicking a modern polyline simply re-prompts.

That refusal is the good news. Several routines of this era read whatever object happens to sit next in the drawing and produce nonsense; this one checks first. If you want to use it on a current release, set PLINETYPE to 0 before drawing the polyline, or convert an existing one to the old format.

What it does in practice

Text is placed bottom-centre justified, sitting half a text height above each vertex, so the labels clear the line itself. The height comes from your current text style; if that style has no fixed height, the routine asks for one and will not accept zero or a negative number.

It starts by writing zero at the first vertex, then adds each segment length as it walks along, writing the running total at every subsequent vertex. Segment lengths are straight point-to-point distances, so an arc segment in the polyline is measured as the chord rather than along the curve — worth knowing if your centreline has curves in it.

The housekeeping is thorough. Command echo, blip mode and object snap are all saved before it starts and restored afterwards; snap is turned off while it works so the text lands exactly on the computed points; and the whole run is wrapped in an undo group so a single U removes every label. The replacement error handler restores all of it even if you cancel partway through, and it exits quietly on a deliberate cancel rather than reporting a fault.

Command reference

The file defines a single command, PDIST. It announces itself when it loads with “Loaded…type <pdist> to run.”

How to load it

Unzip Pdistr13.zip and load pdistr13.lsp with APPLOAD. There are no support files. Our AutoLISP guide covers loading, and the file itself is worth opening in a text editor whether or not you run it.

Step-by-step usage

  1. Make sure the polyline is the old heavyweight type, and set the layer and text style you want the labels on.
  2. Type PDIST.
  3. At “Pick a 2D polyline entity as your source:” click the polyline. Anything else re-prompts.
  4. If your text style has no height set, it asks for one. Type a value or pick a distance.
  5. The running distances appear above each vertex. If they are the wrong size, undo, change the text style height and run it again.

Compatibility notes

Release 13 and earlier, by the author’s own statement, and the polyline structure it depends on stopped being AutoCAD’s default at Release 14. Treat it as a routine for old drawings, for drawings where you control PLINETYPE, or as source to learn from and adapt — the vertex walk is the only part that would need rewriting to support lightweight polylines.

It is plain AutoLISP with no dialog boxes and no Express Tools calls, so nothing in it requires the full product, and LT users on LT 2024 or later face the same polyline limitation as everyone else. See what runs on AutoCAD LT. It only adds text and does not touch the polyline, so nothing of yours is at risk.

Download

Name: Polyline Distance
Description: This program will enable the user to pick on a 2D polyline and
have the cumulative distances displayed above each vertex of the polyline.
Type: AutoCAD AutoLISP Routine
Author: Art Whitton
File Size: 2 Kb
Cost: Free
Worked on: AutoCAD
Download File: Pdistr13.zip

Related routines

  • ZONE — totals length or area by layer, and handles both polyline types.
  • ADDLENGTH — a running total from a selection rather than per-vertex labels.
  • Join 2 Polylines — join the runs up before you chainage them.

References

  • AutoLISP: the complete guide
  • Free LISP routines library
  • AutoLISP Lesson 9: Data Structures
  • AutoLISP on AutoCAD LT

Filed Under: AutoLISP Routines

Primary Sidebar

Subscribe to our Youtube Channel

Post CAD drafting jobs on Freelancer.com. and get some free money to do this.

Categories

  • American Steel Industry (4)
  • AutoCAD Articles & Reference (30)
  • AutoCAD Bugs & Problems (19)
  • AutoCAD Tips (29)
  • AutoCAD Tutorials (54)
  • AutoLISP Routines (328)
  • AutoLISP Tutorials (15)
  • CAD Standards (7)
  • Civil 3D (7)
  • Civil Drafting (4)
  • Dimensions (2)
  • Drafting Funnies (71)
  • Drafting History (9)
  • Drafting Standards (84)
  • Electrical Drafting (2)
  • General IT reference (7)
  • Geometry (15)
  • GIS (2)
  • Hatch Patterns (12)
  • Office Life Hacks (3)
  • PT (1)
  • Revit Tutorials (54)
  • Steel Detailing (14)
  • Structural Drafting (26)
  • Technical Dictionary (61)
  • Useful Website Links (19)

Footer

Free downloads

  • Free AutoLISP routines
  • Free hatch patterns
  • SHX fonts & text styles
  • Numbering LISP collection
  • ISO 3098B font

Reference charts

  • AWS weld symbols chart
  • Steel detailing chart
  • Hole & slot sizes
  • Bolt edge distance
  • ANSI & ARCH paper sizes
  • How to fold an A1 drawing

Useful links

  • CAD blocks (DWG)
  • Revit families
  • structuraldrafter.com
  • cad-corner.com
  • About
  • Privacy policy

Provided for free with no warranty · Log in