0

I am trying to create a function wherein it would ask a user to select a text (either TEXT/MTEXT) then it would simply alert the value of that TEXT/MTEXT's color, layer, contents, and height which are stated in the properties.

I have this code but an error of "Program ERROR: bad argument type: stringp nil"

                (defun c:selecttext()
                (setq textobj (car (entsel "\nSelect text or mtext: ")))
                (if (and textobj (member (cdr (assoc 0 (entget textobj))) '("TEXT" "MTEXT")))
                (progn
                  (setq textinfo (entget textobj))
                  (setq textvalue (cdr (assoc 1 textinfo)))
                  (setq textheight (cdr (assoc 40 textinfo)))
                  (setq textcolor (cdr (assoc 62 textinfo)))
                  (setq textlayer (cdr (assoc 8 textinfo)))
                  (alert (strcat "Text contents: " textvalue "\nHeight: " (rtos textheight) "\nColor: " textcolor "\nLayer: " textlayer)))
                (alert "Please select a valid text or mtext object."))
              (princ))

1 Answers1

0

Got it to work. It seems that colors appear as text in the properties tab but are actually stored as numbers, like how Cyan is equal to 4. Thus, I had to use itoa to convert the integer of Cyan(4) into a string.

                (defun c:selecttext(/ textinfo textvalue textheight textcolor textlayer textobj)
                (setq textobj (car (entsel "\nSelect text or mtext: ")))
                (if (and textobj (member (cdr (assoc 0 (entget textobj))) '("TEXT" "MTEXT" "ATTRIB")))
                (progn
                  (setq textinfo (cdr (entget textobj)))
                  (setq textvalue (cdr (assoc 1 textinfo)))
                  (setq textheight (cdr (assoc 40 textinfo)))
                  (setq textcolor (cdr (assoc 62 textinfo)))
                  (setq textlayer (cdr (assoc 8 textinfo)))
                  (alert (strcat "Text contents: " textvalue "\nHeight: " (rtos textheight) "\nColor: " (itoa textcolor) "\nLayer: " textlayer)))
                (alert "Please select a valid text or mtext object."))
              (princ))