我正在尝试创建一个函数,它会要求用户选择一个文本(TEXT/MTEXT),然后它会简单地提醒属性中规定的该 TEXT/MTEXT 的颜色、图层、内容和高度的值.
我有这段代码,但出现“程序错误:错误的参数类型: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))
开始工作了。似乎颜色在属性选项卡中显示为文本,但实际上存储为数字,例如 Cyan 等于 4。因此,我不得不使用 itoa 将 Cyan(4) 的整数转换为字符串。
(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))