Ask Your Question
1

What is the AutoLISP code to create an alert that displays the value of a TEXT/MTEXT object?

asked 2023-05-12 06:27:33 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-05-12 06:37:02 +0000

devzero gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-12 06:27:33 +0000

Seen: 1 times

Last updated: May 12 '23