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
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
;; 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
- 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 TOTPLEN command
- 1Run TOTPLEN.
- 2Select LWPOLYLINE or POLYLINE objects.
- 3Read the total in the command line.
Worked example
Example: Measure the total length of several route segments.
- Run TOTPLEN.
- Select the route polylines.
- Press Enter.
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