Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are different ways to create an alert in AutoLISP, but here is one possibility for displaying the value of a selected TEXT or MTEXT object:

; Alerts the user of the selected Text or MText value
(defun c:textvaluealert ()
  (setq obj (car (entsel "\nSelect Text or MText object: ")))
  (cond
    ((and obj (= "TEXT" (cdr (assoc 0 (entget obj)))))
     (setq val (cdr (assoc 1 (entget obj))))
     (alert (strcat "The Text value is: " val)))
    ((and obj (= "MTEXT" (cdr (assoc 0 (entget obj)))))
     (setq val (cdr (assoc 1 (entget obj))))
     (alert (strcat "The MText value is: " val)))
    (t (alert "Please select a Text or MText object.")))
  (princ))

This code defines a new AutoLISP command TEXTVALUEALERT that prompts the user to select a Text or MText object, then checks the object type and extracts its value (from the 1 group code) if it is found. If a valid object is selected, an alert dialog box is displayed with the value. If no or an invalid object is selected, a different alert message is shown.

To use this code, copy and paste it into a new or existing .lsp file and load it into AutoCAD by typing AP (or APPLOAD) and selecting the file. Then, run the command by typing TEXTVALUEALERT (or whatever name you chose) and selecting a Text or MText object in the drawing.