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
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
;; 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
- 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 PIPELEN command
- 1Run PIPELEN.
- 2Select pipeline polylines.
- 3Read the layer totals in command history.
Worked example
Example: Total process lines by service layer.
- Run PIPELEN.
- Select route polylines.
- Review each layer total.
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