Twelve labels on a drawing read "D250" and now all have to say "D300", and five dimensions need a word instead of a number. Double-clicking each one takes an afternoon and something always gets missed. This free LISP lets you edit many texts and dimensions at once: window the lot, pick one text or dimension as the sample, and everything takes on the sample's content.
STM and STMX. The full code is printed below so you can read it before running it. For the whole discipline of text and dimensioning, the Institute runs an AutoCAD course for construction.Where the idea came from, and the MT alias
The idea comes from a post on the Institute's forum: select the texts and dimensions to change, then pick an existing one as the sample. The Institute rewrote the code from scratch, tested it on AutoCAD 2027, and changed three things.
First, the command name. The forum version calls its command MT. But the 2027 alias file acad.pgp contains the line MT, *MTEXT: the mt alias already opens multiline text. Loading a LISP called MT takes that alias away. The Institute's version is called STM, checked against every built-in command, every alias and every other Institute LISP.
Second, dimension samples. When the sample is a dimension overridden as L=<>, this version keeps that rule, so each dimension shows its own measured value. There is an example below.
Third, a way back. A second command, STMX, clears the override so dimensions show their measured value again.
Dimension text override and the measured value
Before using the LISP it helps to know that a dimension has two separate parts: the measured value, which AutoCAD computes from the two definition points, and the displayed text. Normally the text is the measured value. Type something else in and that is a dimension text override.
An override changes only the text, never the measurement. Two dimensions measuring 1000 and 1500, both overridden with D300, both show D300 while still measuring 1000 and 1500 underneath.
One special marker is worth knowing: the <> placeholder in an override is replaced by the measured value. Override with L=<> and a 1000 dimension shows L=1000, a 1500 one L=1500. That keeps the real number while adding text before or after it.
Editing dimensions really covers two different jobs, and people often reach for the wrong tool because they lump them together.
| Kind of edit | Example | Tool |
|---|---|---|
| The geometry of a dimension | Move the dimension line, trim extension lines, line dimensions up | Grips, our dimension alignment LISP, our dimension trimming LISP |
| The text of a dimension | Replace the number with words, add a prefix, go back to the measured value | This article: STM and STMX |
To edit dimension text in AutoCAD one at a time, double-click it or use the Properties palette. That is fine for one or two, but slow and error-prone for dozens spread over several sheets.
Using STM
Load the file with APPLOAD, as described in our article on loading LISP files, then type STM.
| Step | The prompt | What you do |
|---|---|---|
| 1 | Select the texts, mtexts and dimensions to edit: | Window the area, Enter; only texts, mtexts and dimensions are taken |
| 2 | Pick the sample text or dimension: | Pick a text, mtext or dimension as the sample |
Pick a line by mistake at step 2 and AutoCAD says That is not a text, mtext or dimension. Pick again. and asks again, with nothing changed. The LISP also asks again if you miss and pick empty space.
Example 1: a text sample
Take two texts, abc and xyz, one mtext cu, and two dimensions measuring 1000 and 1500. Type STM, window all five, Enter, then pick the sample text D300.
| Object | Before | After |
|---|---|---|
| Text | abc | D300 |
| Text | xyz | D300 |
| Mtext | cu | D300 |
| Dimension measuring 1000 | 1000 | D300 |
| Dimension measuring 1500 | 1500 | D300 |
AutoCAD reports Edited 5 object(s) to match "D300". The two dimensions still measure 1000 and 1500 underneath; only their text changed.
Do not worry about whether the sample fell inside the selection window. If it did, the LISP skips it, so the count at the end covers only objects that actually changed.
The whole command is one undo step. A single U puts all five back to abc, xyz, cu, 1000 and 1500.
Example 2: a dimension sample overridden as L=<>
This is where the LISP goes beyond copying text. A dimension measuring 800 is overridden as L=<>, so it shows L=800. Select two dimensions measuring 1000 and 1500 plus a text cu, then pick the L=800 dimension as the sample.
| Object | Before | After |
|---|---|---|
| Dimension measuring 1000 | 1000 | L=1000 |
| Dimension measuring 1500 | 1500 | L=1500 |
| Text | cu | L=800 |
The dimensions receive the rule L=<>, not the text L=800, so each shows its own measurement. The text has no measurement, so it receives exactly what the sample displays.
Text taken from a dimension sample matches what is on screen, decimal places included. With four decimal places the text becomes L=800.0000; with none it becomes L=800.
If the sample dimension has no override at all, the selected dimensions lose theirs too and show their measured value again. That is a quick way to bring a whole batch back in line with the sample.
Reset dimension text with STMX
Drawings received from elsewhere often contain dimensions overridden with fixed text. What you see looks like a number but is not the measurement: as example 1 shows, dimensions measuring 1000 and 1500 can display exactly the same text.
Type STMX, window the dimensions, Enter. AutoCAD reports Reset 2 dimension(s) to the measured value. Two dimensions showing L=1000 and L=1500 go back to 1000 and 1500. Dimensions you did not select are left alone.
It is worth running STMX on every drawing you receive before relying on its dimensions for calculations. A dimension overridden with a fixed number may be wrong without anyone knowing.
What STM leaves alone
The selection filter takes three object types only: single-line text, multiline text and dimensions. Everything else inside the window is ignored, even when it carries text. That keeps a careless window from rewriting things you never meant to touch. You can safely window a whole title block or a crowded detail and let the filter pick out only the texts and dimensions.
| Object in the window | What STM does |
|---|---|
Single-line text (TEXT) | Takes the sample's content |
Multiline text (MTEXT) | Takes the sample's content |
| Linear, aligned, radius and other dimensions | Take the sample's content as an override |
| Multileaders | Ignored |
| Block attributes and text inside blocks | Ignored |
| Tables | Ignored |
| Lines, polylines, hatches | Ignored |
Two consequences are worth planning for. First, labels written as multileaders need a different tool; select them and change their text in the Properties palette. Second, text that lives inside a block definition is not reached, because the selection sees the block reference, not the text inside it. Edit such text in the Block Editor, as described in our article on editing blocks.
The code: a lisp to change text from a sample
Every helper function carries the prefix iic-stm-, so the file can be loaded alongside other LISP files without overwriting them. For single-line text, the LISP strips multiline formatting codes such as \A1; or \P, because single-line text does not understand them.
;;; ==================================================================
;;; STM-IIC-EN.LSP - edit many texts and dimensions from one sample
;;; Vien Tin hoc Xay dung (IIC) - Truong Dai hoc Xay dung Ha Noi
;;; https://iic.huce.edu.vn - Tel: 0989 427 809
;;; ------------------------------------------------------------------
;;; Lenh:
;;; STM quet chon mot loat TEXT, MTEXT va DIM can sua, Enter,
;;; roi bam MOT text hoac dim mau. Moi doi tuong da chon nhan
;;; noi dung cua mau.
;;; - mau la TEXT/MTEXT: text va mtext nhan dung chu ay, dim
;;; hien chu ay thay cho so do.
;;; - mau la DIM: dim nhan dung quy tac ghi de cua mau. Mau ghi
;;; "L=<>" thi dim nao cung hien "L=" kem SO DO CUA CHINH NO.
;;; Mau khong ghi de gi thi cac dim tro ve hien so do that.
;;; Text va mtext nhan chu dang hien tren dim mau.
;;; STMX chon cac dim, xoa phan ghi de: dim hien lai so do that.
;;;
;;; Ten lenh KHONG dat la MT nhu nhieu ban lisp tren mang: MT la lenh
;;; tat co san cua AutoCAD de mo MTEXT, dat trung thi mat lenh tat ay.
;;;
;;; Nap tep: go APPLOAD, chon tep nay, bam Load.
;;; Tep luu bang ma UTF-8. Sua bang Notepad thi nho luu lai dung UTF-8.
;;; ==================================================================
(vl-load-com)
;;; ------------------------------------------------------------------
;;; Phan chung - moi ham phu mang tien to iic-stm- de khong de len
;;; ham cung ten cua tep lisp khac dang nap trong cung ban ve.
;;; ------------------------------------------------------------------
(defun iic-stm-bang-ten ()
(princ "\nLISP written by RDSIC - Institute of Information Technology in Civil Engineering")
(princ "\nwebsite: https://iic.huce.edu.vn")
(princ "\nTel: 0989 427 809")
(princ)
)
(defun iic-stm-tai-lieu () (vla-get-ActiveDocument (vlax-get-acad-object)))
;; Bo ma dinh dang cua MTEXT (\A1; \H2.5; \fArial|b0; \C1; \P ...) de lay
;; chu tron, dung cho TEXT vi TEXT khong hieu cac ma ay.
(defun iic-stm-tron (s / kq i n c k p)
(setq kq "" i 1 n (strlen s))
(while (<= i n)
(setq c (substr s i 1))
(cond
((or (= c "{") (= c "}")) nil)
((and (= c "\\") (< i n))
(setq k (substr s (1+ i) 1))
(cond
((member (strcase k) '("A" "H" "F" "C" "Q" "T" "W" "S"))
(setq p (vl-string-search ";" s i))
(setq i (if p (1+ p) n)))
((= (strcase k) "P") (setq kq (strcat kq " ") i (1+ i)))
((member (strcase k) '("L" "O" "K")) (setq i (1+ i)))
(t (setq kq (strcat kq k) i (1+ i)))
))
(t (setq kq (strcat kq c)))
)
(setq i (1+ i))
)
kq
)
;; Chu dang HIEN tren mot kich thuoc: lay MTEXT nam trong khoi an danh
;; cua no. Day moi la chu nguoi xem thay, da tinh ca ghi de lan so do.
(defun iic-stm-chu-dim (d / e ed kq)
(setq e (entnext (tblobjname "BLOCK" (cdr (assoc 2 d)))) kq "")
(while (and e (= kq ""))
(setq ed (entget e))
(if (= (cdr (assoc 0 ed)) "MTEXT")
(setq kq (vla-get-TextString (vlax-ename->vla-object e)))
)
(setq e (entnext e))
)
(iic-stm-tron kq)
)
;; Doc mau. Tra ve (chu-tron chu-mtext ghi-de-dim).
(defun iic-stm-doc-mau (en / d loai o gd)
(setq d (entget en) loai (cdr (assoc 0 d)) o (vlax-ename->vla-object en))
(cond
((= loai "TEXT")
(list (cdr (assoc 1 d)) (cdr (assoc 1 d)) (cdr (assoc 1 d))))
((= loai "MTEXT")
(list (iic-stm-tron (vla-get-TextString o)) (vla-get-TextString o)
(iic-stm-tron (vla-get-TextString o))))
((= loai "DIMENSION")
(setq gd (vla-get-TextOverride o))
(list (iic-stm-chu-dim d) (iic-stm-chu-dim d) gd))
)
)
;; Ap mau vao mot doi tuong. Tra ve T neu da sua.
(defun iic-stm-ap (en mau / d loai o)
(setq d (entget en) loai (cdr (assoc 0 d)) o (vlax-ename->vla-object en))
(cond
((= loai "TEXT")
(entmod (subst (cons 1 (car mau)) (assoc 1 d) d)) (entupd en) T)
((= loai "MTEXT")
(vla-put-TextString o (cadr mau)) T)
((= loai "DIMENSION")
(vla-put-TextOverride o (caddr mau)) (vla-Update o) T)
(t nil)
)
)
;;; ------------------------------------------------------------------
;;; Lenh STM
;;; ------------------------------------------------------------------
(defun c:STM (/ *error* ss e nguon mau xong i en n)
(defun *error* (m)
(vla-EndUndoMark (iic-stm-tai-lieu))
(if (not (wcmatch (strcase m) "*CANCEL*,*QUIT*,*BREAK*"))
(princ (strcat "\nError: " m))
)
(princ)
)
(iic-stm-bang-ten)
(princ "\nSelect the texts, mtexts and dimensions to edit:")
(setq ss (ssget '((0 . "TEXT,MTEXT,DIMENSION"))))
(if ss
(progn
;; bam mau: bam truot thi bam lai, bam nham loai thi bao roi bam lai,
;; Enter de thoi.
(while (not xong)
(setvar "ERRNO" 0)
(setq e (entsel "\nPick the sample text or dimension: "))
(cond
((and (null e) (= (getvar "ERRNO") 7)) (princ "\nMissed. Pick again."))
((null e) (setq xong T))
((member (cdr (assoc 0 (entget (car e)))) '("TEXT" "MTEXT" "DIMENSION"))
(setq nguon (car e) mau (iic-stm-doc-mau nguon) xong T))
(t (princ "\nThat is not a text, mtext or dimension. Pick again."))
)
)
(if mau
(progn
(vla-StartUndoMark (iic-stm-tai-lieu))
(setq i 0 n 0)
(while (< i (sslength ss))
(setq en (ssname ss i))
(if (and (not (equal en nguon)) (iic-stm-ap en mau))
(setq n (1+ n))
)
(setq i (1+ i))
)
(vla-EndUndoMark (iic-stm-tai-lieu))
(princ (strcat "\nEdited " (itoa n) " object(s) to match \"" (car mau) "\"."))
)
)
)
(princ "\nNo texts, mtexts or dimensions selected.")
)
(princ)
)
;;; ------------------------------------------------------------------
;;; Lenh STMX - xoa ghi de, dim hien lai so do that
;;; ------------------------------------------------------------------
(defun c:STMX (/ *error* ss i o n)
(defun *error* (m)
(vla-EndUndoMark (iic-stm-tai-lieu))
(if (not (wcmatch (strcase m) "*CANCEL*,*QUIT*,*BREAK*"))
(princ (strcat "\nError: " m))
)
(princ)
)
(iic-stm-bang-ten)
(princ "\nSelect the dimensions to reset to their measured value:")
(setq ss (ssget '((0 . "DIMENSION"))))
(if ss
(progn
(vla-StartUndoMark (iic-stm-tai-lieu))
(setq i 0 n 0)
(while (< i (sslength ss))
(setq o (vlax-ename->vla-object (ssname ss i)))
(if (/= (vla-get-TextOverride o) "")
(progn (vla-put-TextOverride o "") (vla-Update o) (setq n (1+ n)))
)
(setq i (1+ i))
)
(vla-EndUndoMark (iic-stm-tai-lieu))
(princ (strcat "\nReset " (itoa n) " dimension(s) to the measured value."))
)
(princ "\nNo dimensions selected.")
)
(princ)
)
(princ "\nSTM-IIC-EN loaded: STM edits to match a sample, STMX resets dimensions.")
(iic-stm-bang-ten)
A version with Vietnamese prompts: stm-iic.lsp.
Which tool for which job
| Job | Use |
|---|---|
| Many texts and dimensions take the same content | STM |
| Many dimensions gain text but keep their value | STM with a dimension sample overridden as ...<>... |
| Dimensions go back to their measured value | STMX |
| Replace one phrase with another across the drawing | FIND, see our article on editing text in bulk |
| Add up, align or resize text in bulk | our bulk text LISP |
Frequently asked questions
How do I edit many texts and dimensions at once?
Load stm-iic-en.lsp, type STM, window the texts and dimensions, press Enter, then pick one text or dimension as the sample.
Does editing dimension text with the LISP change the measurement?
No. Only the displayed text changes; the measured value stays.
How do I add a prefix to many dimensions but keep their numbers?
Override one dimension as, say, L=<> and use it as the sample for STM. Each dimension then shows L= followed by its own measurement.
How do I reset overridden dimensions to their measured value?
Type STMX and select them.
Why is the command not called MT like the version online?
MT is a built-in alias that opens MTEXT. Loading a LISP named MT takes that alias away.
What if I change the wrong objects?
Type U once. The whole STM command is one undo step.