Build Your Own AutoCAD Text Copy Routine from Scratch — Writing, Saving, and Loading AutoLISP




AutoCAD · AutoLISP · Text Utilities

Here’s a scenario every drafter knows: you need to paste the same text string into a dozen different text objects across your drawing. You can use MA (Match Properties) to copy formatting, but there’s no built-in AutoCAD command that overwrites one text object’s content with another’s.

“Click the source text, click the target — that’s all it takes. This guide walks you through writing, saving, loading, and running a custom AutoLISP routine (MM) that copies text content between objects.”

Even if you’ve never written a line of LISP before, you’ll be able to follow along: copy the finished code → save it → load it into AutoCAD → run it. Every step is covered.


1. What Is AutoLISP?

AutoLISP is AutoCAD’s built-in scripting language. It lets you automate repetitive tasks and create custom commands that don’t exist in the standard AutoCAD toolset.

  • LISP files use the .lsp extension and can be written in plain Notepad — no special software required.
  • No installation needed. AutoLISP comes bundled with AutoCAD (Full version).
  • Capabilities range from one-line macros to complex multi-step automation routines.
⚠️ AutoLISP Is Not Available in AutoCAD LT

The LT version is priced lower in exchange for limited customization — AutoLISP and VBA are not included. You’ll need a full AutoCAD subscription or license to use custom LISP routines.

💡 No Programming Experience? No Problem.

This guide doesn’t assume any coding background. You’ll be working with a complete, ready-to-use script — just copy and paste. For those curious about how it works, each section of the code is explained in plain terms.


2. The MM Routine — Complete Code

Copy the code below into Notepad and save it as MM.lsp. This routine uses the VLA (ActiveX) method, which handles both TEXT and MTEXT objects reliably. If you accidentally click a non-text object, it gracefully prints a warning instead of throwing an error.

;;; ============================================
;;; MM (MatchText) — Copy Text Content Routine
;;; Supports both TEXT and MTEXT objects
;;; ============================================

(DEFUN C:MM (/ source_ent source_obj source_text target_ent target_obj old_cmdecho)

  ;; ① Save and suppress command echo
  (setq old_cmdecho (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)

  (princ "\nText Content Copy (MatchText)")

  ;; ② Prompt user to select the source text
  (setq source_ent (entsel "\nSelect source text to copy content FROM: "))

  (if source_ent
    (progn
      (setq source_obj (vlax-ename->vla-object (car source_ent)))

      ;; ③ Verify the selected object is TEXT or MTEXT
      (if
        (or (= (vla-get-ObjectName source_obj) "AcDbText")
            (= (vla-get-ObjectName source_obj) "AcDbMText")
        )
        (progn
          ;; ④ Retrieve the source text string
          (setq source_text (vla-get-TextString source_obj))
          (princ (strcat "\nContent to copy: \"" source_text "\""))
          (princ "\nSelect target text objects (press Enter to finish): ")

          ;; ⑤ Loop: overwrite each selected target with the source content
          (while (setq target_ent (entsel))
            (setq target_obj (vlax-ename->vla-object (car target_ent)))

            ;; Verify target is also TEXT or MTEXT
            (if
              (or (= (vla-get-ObjectName target_obj) "AcDbText")
                  (= (vla-get-ObjectName target_obj) "AcDbMText")
              )
              (progn
                ;; Overwrite content
                (vla-put-TextString target_obj source_text)
                (princ "\nContent copied. Select next target or press Enter to exit: ")
              )
              (princ "\nSelected object is not a text object. Try again: ")
            )
          )
          (princ "\nText content copy complete!")
        )
        (princ "\nSelected object is not TEXT or MTEXT!")
      )
    )
    (princ "\nSelection cancelled.")
  )

  ;; ⑥ Restore command echo
  (setvar "CMDECHO" old_cmdecho)
  (princ)
)

(princ "\nCommand loaded: MM - Copy text content (TEXT/MTEXT supported)")
(princ)

3. Code Walkthrough

Here’s a plain-English breakdown of the key parts of the routine.

Code What It Does
DEFUN C:MM Defines a function named MM that registers as a typed AutoCAD command. The C: prefix is what makes it callable from the command line.
setvar “CMDECHO” 0 Suppresses command-line noise while the routine runs. The original value is saved and restored at the end.
entsel Prompts the user to click a single object on screen. Returns the entity name and the pick point.
vlax-ename->vla-object Converts an entity name to a VLA object (ActiveX object), enabling access to properties via vla-get- and vla-put- functions.
vla-get-ObjectName Returns the object type name. Used to confirm the selection is “AcDbText” (single-line) or “AcDbMText” (multiline) before proceeding.
vla-get-TextString Reads the current text content from a text object.
vla-put-TextString Overwrites the text content of the target object with the source string.
while Keeps the selection loop running until Enter is pressed, which returns nil and exits the loop.
💡 entget/entmod vs. VLA — What’s the Difference?

① entget/entmod (classic approach): Accesses object properties via DXF group codes (1, 7, 40, etc.). More concise, but can struggle with MTEXT’s internal formatting codes.

② VLA / ActiveX: Accesses properties through vla-get- / vla-put- functions. Slightly more verbose, but handles both TEXT and MTEXT consistently and makes type-checking clean and reliable. This routine uses the VLA approach for exactly that reason.


4. Saving the LISP File

  1. Open Notepad (or any plain-text editor like VS Code) and paste the complete code.
  2. Go to File → Save As.
  3. Change the file type to “All Files (*.*)”.
  4. Enter the filename as MM.lsp and save.
  5. Store it somewhere easy to find — a dedicated folder like C:\CAD_LISP is a good habit.
⚠️ Watch Your Encoding

When saving in Notepad, choose UTF-8 or ANSI encoding. Saving as UTF-8 with BOM can cause load errors in AutoCAD. When in doubt, go with ANSI — it’s the safest option.


5. Loading the Routine into AutoCAD (APPLOAD)

Here’s how to get your saved .lsp file into AutoCAD.

5-1. One-Time Load (Current Session Only)

  1. Type APPLOAD (or shortcut AP) in the command line → Enter
  2. In the “Load/Unload Applications” dialog, browse to and select MM.lsp
  3. Click “Load”
  4. If the status bar shows “MM.lsp loaded successfully”, you’re good to go

Note: this method only lasts for the current AutoCAD session. Once you close AutoCAD, the routine is unloaded and must be loaded again next time.

5-2. Startup Suite Registration (Auto-Load)

To have the routine load automatically every time AutoCAD starts, add it to the Startup Suite.

  1. Type APPLOAD → Enter
  2. In the dialog, click the “Contents…” button (bottom-right)
  3. In the “Startup Suite” window, click “Add…”
  4. Navigate to and select MM.lsp, then click Open
  5. Close both dialogs — registration is complete

From now on, the MM command will be available the moment AutoCAD launches.

💡 Moving the File Breaks the Registration

The Startup Suite stores the full file path to your .lsp file. If you move or rename the folder, AutoCAD won’t be able to find it and the routine won’t load. Pick a permanent home for your LISP files and stick with it.


6. How to Use the MM Command

With the routine loaded, type MM in the command line and press Enter.

  1. Type MM → Enter
  2. Prompt: “Select source text to copy content FROM” → click the text you want to copy
  3. The command line previews what will be copied (e.g., Content to copy: “M6”)
  4. Prompt: “Select target text objects” → click each text object you want to overwrite
  5. Keep clicking as many targets as needed, then press Enter to finish

For example: if your drawing title block has separate fields for “Drawn by,” “Checked by,” and “Approved by” — all filled with different names — and you need to stamp all three with “J. Smith,” just run MM, click the source (“J. Smith”), then click each of the three fields in turn.

💡 Replacing Identical Text Across the Drawing? Use FIND Instead.

If you’re doing a find-and-replace — swapping every instance of “M5” for “M6,” for example — AutoCAD’s built-in FIND command gets that done faster. The MM routine shines when you need to push one specific string into multiple text objects that currently hold different content.

💡 Clicking the Wrong Object Won’t Break Anything

The routine checks the object type before doing anything. If you accidentally click a line, dimension, or hatch, you’ll see a message like “Selected object is not a text object” and can immediately click again — no errors, no crashes.


7. Design Decisions Behind the MM Routine

It looks simple, but a few deliberate design choices make this routine reliable in real-world use.

Design Choice Why It Matters
Object type validation Clicking a non-text object (line, dimension, block, etc.) produces a descriptive warning instead of crashing with an unhandled error.
TEXT + MTEXT support Both single-line (DTEXT) and multiline (MTEXT) objects are handled uniformly. The source can be TEXT and the target MTEXT, or vice versa — it doesn’t matter.
CMDECHO save and restore Suppresses internal command-line chatter during execution, then restores the setting to whatever it was before the routine ran.
Content preview before overwriting After selecting the source, the routine displays the content string in the command line so you can confirm you clicked the right object before touching any targets.
Repeat loop (while) You can overwrite as many targets as you need in a single run. Press Enter when done — no need to restart the command for each object.

8. MM vs. MA — Which One Do You Need?

MM (custom LISP) MA — Match Properties (built-in)
What it copies Text content (the string itself) Text formatting (height, style, color, layer, etc.)
Changes content? ✅ Yes — overwrites with source string ❌ No — content stays as-is
Changes formatting? ❌ No — formatting stays as-is ✅ Yes — matches source formatting
Typical use case Stamping multiple objects with a single string (e.g., unifying various names to “J. Smith”) Cleaning up inconsistent fonts, heights, or layers across text objects

Use MM to change content, use MA to change formatting. Run them in sequence — MM first, then MA — to standardize both content and appearance in one pass.


9. Troubleshooting

9-1. “Unknown command: MM”

  • The routine isn’t loaded. Use APPLOAD to load MM.lsp again.
  • Also check the .lsp file for typos — mismatched parentheses are the most common cause of load failures.

9-2. ActiveX / VLA Errors

  • This routine relies on VLA (ActiveX) functions, which require the Visual LISP COM layer to be initialized first via (vl-load-com).
  • AutoCAD usually handles this automatically, but if you see VLA-related errors, type (vl-load-com) directly in the command line and try again.
  • To make this permanent, add (vl-load-com) as the first line of your MM.lsp file.

9-3. “Malformed list” / Mismatched Parentheses

  • LISP uses parentheses heavily, and every opening paren must have a matching closing paren. An off-by-one error will prevent the file from loading.
  • A plain text editor like VS Code highlights matching brackets automatically, making these errors easy to spot. The built-in VLIDE editor inside AutoCAD does this too.

9-4. Text Inside a Block Won’t Change

  • Text inside a block (INSERT) is stored as an ATTRIB (attribute), not as a regular TEXT or MTEXT entity. This routine doesn’t target attributes.
  • To edit block attributes, use the Block Editor (BEDIT), the Enhanced Attribute Editor (EATTEDIT), or write a separate attribute-handling routine.
💡 VLIDE — AutoCAD’s Built-In LISP Editor

Type VLIDE in the command line to open AutoCAD’s Visual LISP Integrated Development Environment. It offers bracket matching, syntax highlighting, and a built-in debugger — far more useful than plain Notepad once you start writing more complex routines.


Commands at a Glance

Command Shortcut Function
APPLOAD AP Load a LISP file / register to Startup Suite
VLIDE Open the built-in Visual LISP IDE
MATCHPROP MA Copy object properties (formatting) — built-in command
FIND Find and replace text strings across the drawing
MM (LISP) MM Copy text content from one object to others — custom routine

Wrapping Up

AutoLISP looks intimidating at first — all those nested parentheses — but the underlying logic is straightforward: select an object, read a property, write it somewhere else. That’s exactly what MM does, and it’s a genuinely useful tool to have in your drafting toolkit.

  • MM for content, MA for formatting — run them back to back and you can fully standardize any block of text objects in seconds.
  • Save your LISP files in a dedicated folder and register them in the Startup Suite so they’re always ready when AutoCAD opens.
  • Once MM is part of your workflow, it tends to open the door to writing more routines. What repetitive task in your drawings would you automate next?

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top