CADLisp Tools

Text & Numbering

Add Suffix to Selected Text AutoLISP routine

Append a fixed suffix to selected TEXT and MTEXT objects. Download the .LSP source below and run the ADDSUFFIX command after loading it.

⌘ ADDSUFFIXv1.0.0BeginnerUpdated Sep 18, 2026

What it does

Add Suffix to Selected Text with the ADDSUFFIX AutoLISP command

Appends one user-entered suffix to every selected text object for controlled label and note updates.

AutoLISP command
ADDSUFFIX
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 add-suffix-selected-text.lsp AutoLISP code

add-suffix-selected-text.lspAUTOLISP
;; CADLisp Tools - Add Suffix to Selected Text
(defun ct-as:editable-p (data / row flags)
  (and data
       (setq row (tblsearch "LAYER" (cdr (assoc 8 data))))
       (setq flags (cdr (assoc 70 row)))
       (= 0 (logand flags 20))))

(defun ct-as:text-value (data / pair value)
  (setq value "")
  (foreach pair data
    (if (member (car pair) '(1 3)) (setq value (strcat value (cdr pair)))))
  value)

(defun ct-as: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-as:set-value (data value / inserted item new out pair)
  (setq inserted nil new (ct-as: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:ADDSUFFIX (/ *error* changed data ent i old skipped ss suffix undo-started)
  (defun *error* (message)
    (if undo-started (command-s "_.UNDO" "_End"))
    (if (and message (not (wcmatch (strcase message) "*CANCEL*,*QUIT*,*EXIT*")))
      (prompt (strcat "\nADDSUFFIX error: " message)))
    (princ))
  (setq suffix (getstring T "\nSuffix: "))
  (if (= suffix "")
    (prompt "\nBlank suffix; no objects changed.")
    (progn
      (prompt "\nSelect TEXT or MTEXT: ")
      (if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
        (progn
          (setq changed 0 skipped 0)
          (if (= 0 (logand 8 (getvar "UNDOCTL")))
            (progn (command "_.UNDO" "_Begin") (setq undo-started T)))
          (repeat (setq i (sslength ss))
            (setq ent (ssname ss (setq i (1- i))) data (and ent (entget ent)))
            (if (and (ct-as:editable-p data) (assoc 1 data))
              (progn
                (setq old (ct-as:text-value data))
                (if (entmod (ct-as:set-value data (strcat old suffix)))
                  (progn (entupd ent) (setq changed (1+ changed)))
                  (setq skipped (1+ skipped))))
              (setq skipped (1+ skipped))))
          (if undo-started (progn (command "_.UNDO" "_End") (setq undo-started nil)))
          (prompt (strcat "\nUpdated " (itoa changed) " object(s); skipped " (itoa skipped) ".")))
        (prompt "\nNo text selected."))))
  (princ))

Setup

How to install the add-suffix-selected-text.lsp file

  1. 1Download and review the source code.
  2. 2Load the .lsp file with APPLOAD in a copy of a drawing.
  3. 3Keep the routine session-only until it has been tested for your CAD version and standards.

Command workflow

How to run the ADDSUFFIX command

  1. 1Run ADDSUFFIX.
  2. 2Enter the suffix, including any separator.
  3. 3Select TEXT or MTEXT and press Enter.

Worked example

Example: Append -EX to selected room tags.

  1. Run ADDSUFFIX.
  2. Enter -EX.
  3. Select the intended tags.
Expected result

Each selected tag ends with -EX.

Read before use

Notes and limitations

  • Does not check whether the suffix is already present.
  • Works only on TEXT and MTEXT.
  • Not manually CAD-tested.

Version history

Changelog

v1.0.0Sep 18, 2026Initial deterministic selection-based routine.

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 →
Text & Numbering6 disciplines

Change Text Case

Convert selected TEXT and unformatted MTEXT to upper- or lowercase.

⌘ TEXTCASEBeginnerCAD 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 →