CADLISPMASTER
Stop wasting time on repetitive AutoCAD tasks. CAD LISP Master provides free, efficient AutoLISP codes and clear tutorials designed to automate your workflow and speed up your drafting.

Batch Change Text Height in AutoCAD: Scale TEXT & MTEXT Instantly

Batch change and unify text heights across TEXT and MTEXT objects in AutoCAD using TSZ.lsp. Free AutoLISP script with smart height memory.
Change and Match Multiple Text Sizes Instantly

When combining drawings from different consultants or assembling project sheets from multiple sources, inconsistent text sizes are a common issue. Fixing text heights manually using the Properties panel (CHPROP) or the MATCHPROP command forces you to click through objects one by one—a slow and tedious process when working with dozens of labels across a plan.

The TSZ.lsp (Text Size Adjustment) routine allows you to batch update text heights across any selection box in seconds. It remembers your previously applied text height for continuous use, filters out non-text geometry automatically, and includes a quick Reset keyword to change target dimensions mid-session.


Key Workflow Highlights

  • Automatic Entity Filtering: Drag a broad crossing box over your entire drawing area. The script automatically filters the selection to modify only TEXT and MTEXT objects while leaving lines, blocks, and dimensions untouched.

  • Persistent Size Memory: Stores your last entered text height in a global variable. On subsequent uses, simply hit Enter to reapply the same height without retyping the value.

  • Quick Value Reset: Need to switch to a different label scale? Type Reset (or R) at the command prompt to define a new base height instantly.


How to Execute the Script

  1. Load TSZ.lsp into AutoCAD using the APPLOAD command.

  2. Type TSZ in the command line and hit Enter.

  3. Set your text height:

    • Enter your target numerical height value (e.g., 2.5 or 100).

    • On subsequent runs, press Enter to keep your saved height, or type Reset to enter a new value.

  4. Select the target area on your screen using a window selection box.

  5. Press Enter to confirm. All selected text elements will immediately scale to the target height.


AutoLISP Code (TSZ.lsp)

Copy the code below and save it as TSZ.lsp inside your AutoCAD support folder:

(vl-load-com)
(defun c:TSZ ( / input ss i ent obj old-error old-osnap acDoc )
  (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-StartUndoMark acDoc)
  (setq old-osnap (getvar "OSMODE"))
  (setq old-error *error*)
  
  (defun *error* (msg)
    (if old-osnap (setvar "OSMODE" old-osnap))
    (if acDoc (vla-EndUndoMark acDoc))
    (setq *error* old-error)
    (princ "\nCAD Lisp [www.daolpro.com]")
    (princ)
  )

  (if (not g_txtsize)
    (setq g_txtsize (getreal "\nEnter new text height: "))
    (progn
      (initget "Reset")
      (setq input (getreal (strcat "\nEnter text height or [Reset] <" (rtos g_txtsize 2) ">: ")))
      (cond
        ((= input "Reset")
         (setq g_txtsize (getreal "\nEnter new text height: "))
        )
        ((numberp input)
         (setq g_txtsize input)
        )
      )
    )
  )
  
  (if g_txtsize
    (progn
      (prompt "\nSelect text objects to change size: ")
      (if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
        (progn
          (setq i 0)
          (while (< i (sslength ss))
            (setq ent (ssname ss i))
            (setq obj (vlax-ename->vla-object ent))
            (vla-put-height obj g_txtsize)
            (setq i (1+ i))
          )
          (prompt (strcat "\nSuccessfully changed to size " (rtos g_txtsize 2) "."))
        )
        (prompt "\nNo text selected.")
      )
    )
  )

  (if old-osnap (setvar "OSMODE" old-osnap))
  (if acDoc (vla-EndUndoMark acDoc))
  (setq *error* old-error)
  (princ "\nCAD Lisp [www.daolpro.com]")
  (princ)
)

Drafting Standards Tip

When preparing sheets for plotting, maintain standardized text height ratios (e.g., 2.5mm for general notes, 3.5mm for room titles, 5.0mm for drawing numbers) so your printed layouts remain clean and easy to read across all view scales.

Post a Comment