Back to Blog

CAD / BIM

5 AutoLISP Routines Every Small Engineering Firm Should Have

Copy-paste AutoLISP routines for quick quantities, block counts, standard layers and drawing cleanup: the small automations that save hours every week.

March 12, 2026

AutoLISP has been inside AutoCAD since the 1980s, and it's still one of the most underused tools in small engineering firms. Most firms either never touch it, or they have one ancient .lsp file someone wrote in 2009 that nobody dares open.

You don't need to become a programmer. You need a handful of short routines that remove the repetitive clicks your team does dozens of times a week.

Here are five we use and recommend. Each one is short enough to read and understand, and each one solves a real, daily problem.

How to load these routines

  1. Copy the code into a plain text editor (Notepad works) and save it with a .lsp extension, for example kronos-tools.lsp.
  2. In AutoCAD, type APPLOAD, browse to the file and click Load.
  3. To load it automatically every time, add it to the Startup Suite in the same APPLOAD dialog.
  4. Type the command name (for example TLEN) to run it.

You can paste all five routines into one file.

1. TLEN: Total length of selected objects

The problem: you need the total linear footage of a pipe run, a curb line or a fence. So you click each polyline, read the length in Properties, write it down, and add it up by hand.

The routine:

(defun c:TLEN (/ ss i e total)
  (vl-load-com)
  (setq total 0.0)
  (if (setq ss (ssget '((0 . "LINE,LWPOLYLINE,POLYLINE,ARC,CIRCLE,SPLINE,ELLIPSE"))))
    (progn
      (setq i 0)
      (repeat (sslength ss)
        (setq e (ssname ss i))
        (setq total (+ total (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e))))
        (setq i (1+ i))
      )
      (princ (strcat "\nTotal length: " (rtos total 2 2)
                     " drawing units in " (itoa (sslength ss)) " objects."))
    )
  )
  (princ)
)

Select everything you want measured, press Enter, and the total appears on the command line. Units are drawing units: if your drawing is in feet, the answer is in feet.

Why it matters: this is the backbone of a fast linear takeoff. Put each item on its own layer, use QSELECT or LAYISO to grab only that layer, run TLEN, done.

2. TAREA: Total area of closed shapes

The problem: you need total pavement, sod or slab area across 30 separate polylines and hatches.

(defun c:TAREA (/ ss i obj a total n)
  (vl-load-com)
  (setq total 0.0 n 0)
  (if (setq ss (ssget '((0 . "LWPOLYLINE,POLYLINE,HATCH,CIRCLE,REGION"))))
    (progn
      (setq i 0)
      (repeat (sslength ss)
        (setq obj (vlax-ename->vla-object (ssname ss i)))
        (setq a (vl-catch-all-apply 'vla-get-area (list obj)))
        (if (not (vl-catch-all-error-p a))
          (setq total (+ total a) n (1+ n))
        )
        (setq i (1+ i))
      )
      (princ (strcat "\nTotal area: " (rtos total 2 2)
                     " sq. drawing units from " (itoa n) " objects."))
      (princ "\nTip: if the drawing is in inches, divide by 144 for square feet.")
    )
  )
  (princ)
)

The vl-catch-all-apply wrapper skips any object whose area AutoCAD can't calculate (some complex hatches) instead of crashing the whole routine, and it tells you how many objects it actually counted, so you can spot what was skipped.

Watch out for: open polylines. AutoCAD calculates their area as if they were closed, which can quietly give you wrong numbers. Close your boundaries.

3. BCOUNT: Count blocks by name

The problem: how many light poles, inlets, trees or borings are on this sheet? Counting by eye is slow and error-prone.

(defun c:BCOUNT (/ ss i obj nm lst pair)
  (vl-load-com)
  (if (setq ss (ssget '((0 . "INSERT"))))
    (progn
      (setq i 0)
      (repeat (sslength ss)
        (setq obj (vlax-ename->vla-object (ssname ss i)))
        (setq nm (if (vlax-property-available-p obj 'EffectiveName)
                   (vla-get-EffectiveName obj)
                   (vla-get-Name obj)))
        (if (setq pair (assoc nm lst))
          (setq lst (subst (cons nm (1+ (cdr pair))) pair lst))
          (setq lst (cons (cons nm 1) lst))
        )
        (setq i (1+ i))
      )
      (princ "\n--- Block count ---")
      (foreach p (vl-sort lst '(lambda (a b) (< (car a) (car b))))
        (princ (strcat "\n" (car p) ": " (itoa (cdr p))))
      )
    )
  )
  (princ)
)

Using EffectiveName matters: dynamic blocks get renamed internally to anonymous names like *U12, and without it your count would split one symbol into a dozen meaningless rows.

4. STDLAYERS: Create your standard layers in one shot

The problem: a drawing came from a client, a surveyor or an old project, and it doesn't have your layers. Someone spends 20 minutes creating them by hand, and gets the colors slightly wrong.

(defun c:STDLAYERS (/ doc lays lay)
  (vl-load-com)
  (setq doc  (vla-get-ActiveDocument (vlax-get-acad-object))
        lays (vla-get-Layers doc))
  (foreach spec '(("C-ROAD" 1) ("C-STRM" 5) ("C-TOPO" 8)
                  ("C-BORE" 3) ("C-ANNO-TEXT" 7) ("G-NPLT" 9))
    (setq lay (vla-Add lays (car spec)))
    (vla-put-Color lay (cadr spec))
  )
  (princ "\nStandard layers created or updated.")
  (princ)
)

Edit the list to match your firm's layer table (name and color index). If a layer already exists, the routine simply resets its color to your standard, so it's safe to run on any drawing.

This is your CAD standards document turned into a button.

5. CLEANUP: Purge, audit and zoom before you send

The problem: drawings go out bloated with unused blocks, styles and registered applications, sometimes with minor database errors. The fix is always the same three commands. And people forget them.

(defun c:CLEANUP (/ oldecho)
  (setq oldecho (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (repeat 3 (command "_.-PURGE" "_All" "*" "_N"))
  (command "_.-PURGE" "_Regapps" "*" "_N")
  (command "_.AUDIT" "_Y")
  (command "_.ZOOM" "_E")
  (setvar "CMDECHO" oldecho)
  (princ "\nDrawing purged, audited and zoomed to extents.")
  (princ)
)

Purge runs three times because removing one unused item (a block) can make another one unused (a layer only that block was using). Make CLEANUP the last step of your QC checklist, and every file you send will be smaller and cleaner.

How much time does this actually save?

Do the honest math for your own firm. If one person on your team spends 15 minutes a day adding up lengths, counting symbols and cleaning drawings by hand, that's about 60 hours a year (a week and a half of work) from one person, on tasks these routines reduce to seconds.

Small automations don't feel important because each one only saves a few minutes. Their value is in how often they run.

The bigger lesson

These five routines do something more important than saving clicks: they put your standards into the tools. Nobody has to remember your layer colors when STDLAYERS sets them. Nobody forgets to purge when CLEANUP is part of the checklist.

That's the difference between a firm that depends on careful people and a firm with a system that works no matter who's drafting.

At Kronos GMT we build this kind of automation for our clients' workflows, from small LISP routines to Python tools that process hundreds of drawings at once. Next in this series: batch-fixing 50 drawings with Python.