CADLisp Tools

Data Extraction

Pipeline Length by Layer AutoLISP routine

Summarize selected polyline length totals grouped by layer. Download the .LSP source below and run the PIPELEN command after loading it.

⌘ PIPELENv1.0.0IntermediateUpdated Sep 18, 2026

What it does

Pipeline Length by Layer with the PIPELEN AutoLISP command

Measures selected pipe-route polylines, groups the values by exact layer name, and prints a layer-by-layer length summary.

AutoLISP command
PIPELEN
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 pipeline-length-by-layer.lsp AutoLISP code

pipeline-length-by-layer.lspAUTOLISP
;; CADLisp Tools - Pipeline Length by Layer
(vl-load-com)

(defun ct-pl:add (key amount items / hit)
  (if (setq hit (assoc key items))
    (subst (cons key (+ amount (cdr hit))) hit items)
    (cons (cons key amount) items)))

(defun ct-pl: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:PIPELEN (/ data ent i layer length pair skipped ss totals)
  (prompt "\nSelect pipeline polylines: ")
  (if (setq ss (ssget '((0 . "LWPOLYLINE,POLYLINE"))))
    (progn
      (setq i 0 totals nil skipped 0)
      (repeat (sslength ss)
        (setq ent (ssname ss i) data (and ent (entget ent))
              layer (and data (cdr (assoc 8 data))) length (ct-pl:length ent))
        (if (and layer length)
          (setq totals (ct-pl:add layer length totals))
          (setq skipped (1+ skipped)))
        (setq i (1+ i)))
      (prompt "\n--- Pipeline length by layer ---")
      (foreach pair (vl-sort totals '(lambda (a b) (< (strcase (car a)) (strcase (car b)))))
        (prompt (strcat "\n" (car pair) ": " (rtos (cdr pair) 2 3))))
      (prompt (strcat "\nUnsupported or invalid polylines skipped: " (itoa skipped))))
    (prompt "\nNo pipeline polylines selected."))
  (princ))

Setup

How to install the pipeline-length-by-layer.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 PIPELEN command

  1. 1Run PIPELEN.
  2. 2Select pipeline polylines.
  3. 3Read the layer totals in command history.

Worked example

Example: Total process lines by service layer.

  1. Run PIPELEN.
  2. Select route polylines.
  3. Review each layer total.
Expected result

One raw drawing-unit length is printed per layer.

Read before use

Notes and limitations

  • Layer naming must encode the grouping you need.
  • Does not include fittings or convert units.
  • Not manually CAD-tested.

Version history

Changelog

v1.0.0Sep 18, 2026Initial layer-grouped route summary.

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 & Polylines4 disciplines

Station/Chainage Along Polyline

Report distance along a selected polyline to a picked location.

⌘ CHAINAGEIntermediateCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →
Geometry & Polylines6 disciplines

Total Polyline Length

Calculate the combined length of selected 2D and legacy polylines.

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