CADLisp Tools

Geometry & Polylines

Total Polyline Length AutoLISP routine

Calculate the combined length of selected 2D and legacy polylines. Download the .LSP source below and run the TOTPLEN command after loading it.

⌘ TOTPLENv1.0.0BeginnerUpdated Sep 18, 2026

What it does

Total Polyline Length with the TOTPLEN AutoLISP command

Sums curve distance for selected polyline entities and reports one total using current drawing units.

AutoLISP command
TOTPLEN
Difficulty
Beginner

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 total-polyline-length.lsp AutoLISP code

total-polyline-length.lspAUTOLISP
;; CADLisp Tools - Total Polyline Length
(vl-load-com)

(defun ct-tp:length (ent / data end flags result)
  (setq data (and ent (entget ent)))
  (if (and data
           (or (= (cdr (assoc 0 data)) "LWPOLYLINE")
               (and (= (cdr (assoc 0 data)) "POLYLINE")
                    (setq flags (cdr (assoc 70 data)))
                    (= 0 (logand flags 80))))
           (not (vl-catch-all-error-p
                  (setq end (vl-catch-all-apply 'vlax-curve-getEndParam (list ent)))))
           (not (vl-catch-all-error-p
                  (setq result (vl-catch-all-apply 'vlax-curve-getDistAtParam (list ent end))))))
    result))

(defun c:TOTPLEN (/ ent i length skipped ss total)
  (prompt "\nSelect polylines: ")
  (if (setq ss (ssget '((0 . "LWPOLYLINE,POLYLINE"))))
    (progn
      (setq total 0.0 skipped 0)
      (repeat (setq i (sslength ss))
        (setq ent (ssname ss (setq i (1- i))) length (ct-tp:length ent))
        (if length
          (setq total (+ total length))
          (setq skipped (1+ skipped))))
      (prompt (strcat "\nTotal polyline length: " (rtos total 2 3)
                      "; unsupported or invalid polylines skipped: " (itoa skipped))))
    (prompt "\nNo polylines selected."))
  (princ))

Setup

How to install the total-polyline-length.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 TOTPLEN command

  1. 1Run TOTPLEN.
  2. 2Select LWPOLYLINE or POLYLINE objects.
  3. 3Read the total in the command line.

Worked example

Example: Measure the total length of several route segments.

  1. Run TOTPLEN.
  2. Select the route polylines.
  3. Press Enter.
Expected result

The combined length is printed in drawing units.

Read before use

Notes and limitations

  • Does not apply unit conversion.
  • Does not include lines, arcs, or splines.
  • Not manually CAD-tested.

Version history

Changelog

v1.0.0Sep 18, 2026Initial curve-distance total routine.

Keep automating

Related tools

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 →
Geometry & Polylines6 disciplines

Closed Polyline Area

Sum the area of selected closed polylines and skip open ones.

⌘ CLOSEDARIntermediateCAD 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 →