CADLisp Tools

Text & Numbering

Incremental Text Numbering AutoLISP routine

Renumber TEXT and MTEXT objects in the exact order you select them. Download the .LSP source below and run the NUMTEXT command after loading it.

⌘ NUMTEXTv1.1.0BeginnerUpdated Sep 18, 2026

What it does

Incremental Text Numbering with the NUMTEXT AutoLISP command

A focused numbering helper for equipment labels, notes, room numbers, and other drawing text. You choose each object individually, so the resulting sequence is predictable.

AutoLISP command
NUMTEXT
Difficulty
Beginner

Applicable disciplines

CAD workflows that use this routine

Requirements and compatibility

What it needs

AutoLISP

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 incremental-numbering.lsp AutoLISP code

incremental-numbering.lspAUTOLISP
;; CADLisp Tools - Incremental Text Numbering
(defun ct-nt:editable-p (data / flags row)
  (and data
       (setq row (tblsearch "LAYER" (cdr (assoc 8 data))))
       (setq flags (cdr (assoc 70 row)))
       (= 0 (logand flags 20))))

(defun ct-nt:text-pairs (value / pairs)
  (setq pairs nil)
  (while (> (strlen value) 250)
    (setq pairs (cons (cons 3 (substr value 1 250)) pairs)
          value (substr value 251)))
  (reverse (cons (cons 1 value) pairs)))

(defun ct-nt:set-value (data value / inserted item new out pair)
  (setq inserted nil new (ct-nt:text-pairs value) out nil)
  (foreach pair data
    (if (member (car pair) '(1 3))
      (if (not inserted)
        (progn
          (foreach item new (setq out (cons item out)))
          (setq inserted T)))
      (setq out (cons pair out))))
  (reverse out))

(defun c:NUMTEXT (/ *error* count current data entity kind picked skipped start step undo-started)
  (defun *error* (message)
    (if undo-started (command-s "_.UNDO" "_End"))
    (if (and message (not (wcmatch (strcase message) "*CANCEL*,*QUIT*,*EXIT*")))
      (prompt (strcat "\nNUMTEXT error: " message)))
    (princ))
  (setq start (getint "\nStarting number <1>: "))
  (if (null start) (setq start 1))
  (initget 2)
  (setq step (getint "\nIncrement (non-zero) <1>: "))
  (if (null step) (setq step 1))
  (setq current start count 0 skipped 0)
  (prompt "\nSelect TEXT or MTEXT in sequence. Press Enter to finish.")
  (if (= 0 (logand 8 (getvar "UNDOCTL")))
    (progn (command "_.UNDO" "_Begin") (setq undo-started T)))
  (while (setq picked (entsel (strcat "\nSelect text for number " (itoa current) ": ")))
    (setq entity (car picked) data (and entity (entget entity))
          kind (and data (cdr (assoc 0 data))))
    (if (and (member kind '("TEXT" "MTEXT"))
             (ct-nt:editable-p data)
             (entmod (ct-nt:set-value data (itoa current))))
      (progn
        (entupd entity)
        (setq current (+ current step) count (1+ count)))
      (progn
        (setq skipped (1+ skipped))
        (prompt "\nSkipped: select editable TEXT or MTEXT on an unlocked, non-xref layer."))))
  (if undo-started (progn (command "_.UNDO" "_End") (setq undo-started nil)))
  (prompt (strcat "\nNumbered " (itoa count) " object(s); skipped " (itoa skipped) "."))
  (princ))

Setup

How to install the incremental-numbering.lsp file

  1. 1Download the .lsp file.
  2. 2Run APPLOAD and select the file.
  3. 3Keep it session-only until tested.

Command workflow

How to run the NUMTEXT command

  1. 1Run NUMTEXT.
  2. 2Enter the starting number and a non-zero increment.
  3. 3Select each TEXT or MTEXT object in sequence.
  4. 4Press Enter to finish.

Worked example

Example: Change five placeholders into numbers 101 through 105.

  1. Enter 101 as the start.
  2. Accept 1 as the increment.
  3. Select five labels in drawing order.
Expected result

The labels contain 101 through 105 in selection order.

Read before use

Notes and limitations

  • Works only with TEXT and MTEXT.
  • Replaces the complete text value.
  • A zero increment is rejected.

Version history

Changelog

v1.1.0Sep 18, 2026Reject zero increments and track changed-object count directly.
v1.0.0Sep 17, 2026Initial starter implementation.

Keep automating

Related tools

Text & Numbering6 disciplines

Add Prefix to Selected Text

Add a fixed prefix to selected TEXT and MTEXT objects.

⌘ ADDPREFIXBeginnerCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →
Blocks & Attributes4 disciplines

Equipment Tag Numbering

Write a prefix and sequential number into a chosen block attribute.

⌘ EQTAGNOAdvancedCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →
Text & Numbering6 disciplines

Find & Replace Selected Text

Replace matching text inside a deliberate selection of TEXT and MTEXT objects.

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