• 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

Add or Subtract Values in AutoCAD Level Text (DP2 LISP)

September 18, 2020

Last updated July 28, 2026

DP2.LSP is a short free AutoLISP routine by Colin Browning, dated 20 May 1998, that adds or subtracts a user-entered value to the numerical part of text in an AutoCAD drawing. It works on single-line text sitting on a layer named LEVELS, which tells you who it was written for: anyone maintaining level or reduced-level annotations who needs to shift every value by the same amount, such as after a datum change.

Rather than retyping dozens of level labels one at a time, you run one command, enter the adjustment, and the routine rewrites every matching text item for you. It is the kind of two-kilobyte utility that shows why AutoLISP has stayed useful for so long.

What it does in practice

The routine only touches single-line TEXT entities on a layer called LEVELS. Both of its selection modes apply a filter for that exact combination, so text on other layers, and mtext anywhere, is left alone. The layer name is hard-coded in two filter lines that read '(8 . "LEVELS"); as the original description notes, you can change it to suit your own layer standard with a little AutoLISP experience.

For each selected string, the code scans character by character until it reaches the first digit or minus sign. Everything before that point is treated as a prefix and kept, so a label like “RL 12.350” holds onto its “RL ” while the number behind it changes. The numeric part is converted to a real number, your value is added (enter a negative value to subtract), and the result is written back with the same number of decimal places the original string had. Strings with no numeric part are left as they were. The file header notes this is Version 3, modified to convert negative number values.

Under the bonnet it pulls apart each text entity’s association list, substitutes the modified string and updates the drawing with entmod — the sort of list handling covered in Lesson 9 of our AutoLISP series, if you want to modify the routine yourself.

One trap worth knowing before you run it

The routine assumes the number sits at the end of the string. Once it finds the first digit, it takes the whole remainder of the text as the number and converts it, so anything trailing the digits is discarded. A label reading “12.5m” becomes “13.00” when you add 0.5 — the “m” is gone, and the decimal places are wrong too, because the suffix characters were counted when working out how many decimals to write back. Prefixes are safe; suffixes are not. If your level text carries units or a trailing note, test on a copy first.

Two other things a reader of the code will notice. The routine declares no local variables, so it leaves around twenty globals behind in the drawing session after it runs. And its error handler is a plain redefinition of *ERROR* that is never restored, so it stays in force for everything else you run afterwards until you reload AutoCAD or another routine replaces it. Neither will hurt a one-off level adjustment, but both are worth knowing if you fold this code into a larger toolset.

Command reference

  • DP2 — select level text globally or manually, then add or subtract a value to the numeric part of each item.

That is the only command the file defines. It also installs a minimal error handler that prints the error message — see the caveat about it above.

How to load it

Unzip Dp2.zip, then load dp2.LSP with the APPLOAD command (Manage tab, or just type APPLOAD). For one-off use, load it and run it in the current session. If level adjustment is a regular job, add the file to the APPLOAD Startup Suite so it loads in every drawing automatically. Our AutoLISP guide covers loading methods in more detail, and the free LISP routine library has plenty more utilities worth adding alongside it.

Step-by-step usage

  1. Make sure the text you want to change is single-line text on a layer named LEVELS (or edit the layer name in the code first).
  2. Type DP2 at the command line.
  3. At “Select text Globally or Manually (G/M) <Globally>:”, press Enter to accept Global, which processes every matching text item in the drawing, or type M to pick the text yourself. In Manual mode the filter still discards anything that is not text on LEVELS, so a crossing window over a busy area is safe.
  4. At “Enter value to change levels by:”, type the adjustment. A positive number adds, a negative number subtracts. The prompt will not accept empty input, so you must give it a value.
  5. The routine loops through the selection and rewrites each item. If nothing matched the filter, it reports “No valid selection. Try again!” and stops.

There is no built-in undo grouping beyond AutoCAD’s own, so if the result is not what you expected, U straight away — or better, run it on a copy of the drawing the first time.

Compatibility notes

This routine was written in 1998 for AutoCAD, and the download page lists it simply as working on AutoCAD, with no version given. It is plain AutoLISP: no DCL dialog boxes, no Express Tools functions, just standard selection, string and entity functions that have been part of AutoLISP for decades. That means there is nothing in the code that demands full AutoCAD. AutoCAD LT gained AutoLISP support in LT 2024, so LT users on 2024 or later can try it too — see what runs on AutoCAD LT for the details. As with any routine of this age, we say “written for” rather than “tested on”: try it on a copy of your drawing before trusting it on live work.

Download

Name: Add or subtract to numerical text
Description: Program to select required text (on a layer called LEVELS,
this can be changed if you have a little Autolisp experience) and
change the numerical part of each text item by adding or
subtracting a user-entered value.
Type: AutoCAD AutoLISP Routine
Author: Colin Browning
File Size: 2 Kb
Cost: Free
Worked on: AutoCAD
Download File: Dp2.zip

Related routines

  • Numbering LISP routine collection — a set of routines for working with numbered text.
  • Zero elevation LISP routine — another elevation-focused utility.
  • ImportXYZ coordinate import LISP — bring survey coordinate data into AutoCAD.

References

  • AutoLISP guide
  • Free LISP routine library
  • AutoLISP on AutoCAD LT
  • AutoLISP Lesson 9: Data Structures

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