• 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

ADDLENGTH LISP: Total the Length of Lines in AutoCAD

August 1, 2006

Last updated July 28, 2026

ADDLENGTH totals the length of everything you select and prints the result at the command line. Select a run of lines and arcs, and it tells you how many metres of them there are. The obvious use, and the one the listing gives, is a bill of materials take-off: pipe runs, cable trays, handrail, kerb lengths, fencing — anything where the drawing already holds the geometry and you need the number.

It is a short routine and it does its job, but there is one limitation that will bite anyone using a current release of AutoCAD, so it is worth covering before anything else.

It ignores modern polylines

The routine tests the type of each object you select and handles three of them: lines, arcs and polylines. The catch is which kind of polyline. AutoCAD has drawn lightweight polylines by default since Release 14, and the internal name for those is LWPOLYLINE. The routine checks for POLYLINE, the older heavyweight type, and nothing else.

A lightweight polyline therefore fails all three tests, falls through to the catch-all branch, and is quietly removed from the selection without being measured. Nothing is reported. You get a total that silently excludes every polyline you drew with the PLINE command — and if your selection was mostly polylines, you can get a total of zero on a screen full of geometry.

There are two ways around it. Convert the polylines to the old format before measuring, or add LWPOLYLINE to the routine’s list of accepted types. It is a two-line change and the same handler already in the file will measure them correctly, because it works by calling AutoCAD’s own AREA command rather than reading the vertices. Circles, ellipses and splines are not handled either, and are dropped the same silent way.

What it does in practice

Everything you select goes into a pile, and the routine works through it one object at a time, removing each from the pile as it is dealt with. Lines are measured from end to end. Arcs get proper arc-length treatment: the routine takes the centre, radius, start angle and end angle from the object, works out the included angle — correctly handling arcs that cross the zero-degree mark — and takes that fraction of the full circumference. Heavyweight polylines are handed to AutoCAD’s AREA command and their perimeter is read back.

The running total is printed at the end to two decimal places in your current drawing units. There is no output to file and nothing is written into the drawing, so it is safe to run on live work.

One thing to be aware of if you fold this into anything larger: the routine declares no local variables, so the total and its working values are left behind as globals after it finishes. Run it twice without thinking and you are still fine — the total is reset at the start of each run — but the variables persist in the drawing session.

Command reference

The file defines one command, ADDLENGTH, plus three internal helpers for the three object types it understands.

How to load it

This download is a bare .lsp file rather than a zip, so there is nothing to extract — save it somewhere on AutoCAD’s support file search path and load it with APPLOAD, or add it to the Startup Suite. Our AutoLISP guide covers the options.

Step-by-step usage

  1. Type ADDLENGTH.
  2. At “Select all objects to count:” select the geometry. Any selection method works.
  3. Press Enter to close the selection. The routine reports “Total length is:” followed by the figure.

Sanity-check the first result. Measure one known line with the DIST command and confirm the total moves by that amount when you include it. That will tell you straight away whether the objects you care about are the ones being counted.

Compatibility notes

The listing records it as working on AutoCAD 2006. It is plain AutoLISP with no dialog boxes and no Express Tools calls, so nothing in it requires the full product; LT users on LT 2024 or later, the release that brought AutoLISP to LT, should be able to run it. See what runs on AutoCAD LT. It only reads the drawing, so there is no risk to your geometry — the risk is in trusting a total that may have skipped things.

Download

Name: Addlength
Description: Add individual lenghts of lines together for a grand total.
Useful for Bill Of Materials take offs.
Type: AutoCAD AutoLISP Routine
Author: Anon
File Size: 4 Kb
Cost: Free
Worked on: AutoCAD 2006
Download File: Addlength.lsp

Related routines

  • ZONE — totals length or area for every polyline on a layer, and handles both polyline types correctly.
  • DISTBEAR — label individual lines with their length and bearing.
  • Best of LISP collection — more general drafting utilities in one download.

References

  • AutoLISP: the complete guide
  • Free LISP routines library
  • 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