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.

Match Text Content in AutoCAD: Batch Update TEXT & MTEXT Strings

Batch match and update text content across multiple TEXT and MTEXT objects in AutoCAD using MTC.lsp. Free AutoLISP script to speed up drafting.
Match Text Content Instantly Across Multiple Objects

If you have ever had to update dozens of room labels, equipment tags, or revision notes across an AutoCAD sheet, you know how painful the default text editing process is. Double-clicking a text object, copying the string, exiting, double-clicking another text object, pasting, and repeating that loop thirty times is a huge waste of drafting time.

That is where MTC.lsp (Match Text Content) comes in handy. It extracts the text string from a source object and instantly overwrites multiple destination text objects in one click—without changing their original layer, style, size, or color settings.


What Makes MTC Better Than Standard Copy/Paste?

When updating repeated annotations, using standard AutoCAD text tools presents a few common frustrations:

  • Saves your formatting: Standard MATCHPROP or copying text objects often overwrites existing text styles, heights, or layers. MTC.lsp only swaps the string value itself, leaving all other object properties intact.

  • Supports window selection: Instead of picking target text objects one by one, you can drag a crossing box over an entire area to update every text string at once.

  • Works with TEXT and MTEXT: You don't have to worry about whether your source or destination is Single-line Text (TEXT) or Multiline Text (MTEXT)—the script handles both seamlessly.


Step-by-Step Instructions

Here is how to run the script in your drawing session:

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

  2. Type MTC in the command prompt and press Enter.

  3. Click your source text object (the text content you want to copy).

  4. Select your destination text objects. You can click individual text items or use a window selection box to grab multiple objects at once.

  5. Press Enter to confirm. The command line will display the exact count of updated text objects.


AutoLISP Code (MTC.lsp)

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

(defun c:MTC ( / acDoc ssSource entSource strSource ssTarget i entTarget objTarget *error*)
  (defun *error* (msg)
    (if acDoc (vla-EndUndoMark acDoc))
    (princ "\nCAD Lisp [www.daolpro.com]")
    (princ)
  )
  (vl-load-com)
  (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-StartUndoMark acDoc)
  (setq ssSource (ssget ":S" '((0 . "TEXT,MTEXT"))))
  (if ssSource
    (progn
      (setq entSource (ssname ssSource 0))
      (setq strSource (vla-get-TextString (vlax-ename->vla-object entSource)))
      (princ "\nSelect destination text(s) to match [Window selection allowed]: ")
      (setq ssTarget (ssget '((0 . "TEXT,MTEXT"))))
      (if ssTarget
        (progn
          (setq i 0)
          (repeat (sslength ssTarget)
            (setq entTarget (ssname ssTarget i))
            (setq objTarget (vlax-ename->vla-object entTarget))
            (vla-put-TextString objTarget strSource)
            (setq i (1+ i))
          )
          (princ (strcat "\n>> Successfully matched " (itoa i) " text object(s)."))
        )
        (princ "\n-> No destination text selected.")
      )
    )
    (princ "\n-> No source text selected.")
  )
  (vla-EndUndoMark acDoc)
  (princ "\nCAD Lisp [www.daolpro.com]")
  (princ)
)

Practical Use Cases

  • Batch Room/Grid Renumbering: Quickly sync duplicated room labels or elevation tags across floor plans.

  • Updating Title Block Details: Match project notes or date entries across multiple callouts without modifying individual text heights or styles.

Post a Comment