BLOACH85 发表于 2022-7-6 14:51:30

关于颜色的问题

嘿,我拼凑了这个简单的lisp例程,它只改变你特定图层的颜色,例如图层=钢色=黄色,它将把它改为图层=钢色=红色或颜色=10。但这是我的问题,我还希望能够选择任何对象,然后选择我的颜色工具栏(我使用lisp制作),并将对象更改为该颜色,甚至线型,而无需转到lt工具栏或颜色工具栏。我会把代码贴在下面。
 
(defun c:a1 (/ *error*);red
(defun *error* (msg)
   (and Osmode# (setvar "osmode" Osmode#))
   (command "_.undo" "_e")
   (if
   (not
   (member
   msg
   '("console break" "Function cancelled" "quit / exit abort")
   ) ;_ member
   ) ;_ not
            (princ (strcat "\nError: " msg))
   ) ;_ if
   ) ;_ defun
'(command "color" 1)
(princ)
)

 
看,这只是一个简单的命令操作,带有一个错误例程。(以防万一)如果有人知道怎么做,现在就告诉我。
 
(这个例程的目的是因为我们使用的是颜色相关的打印样式,所以我们的线条厚度是根据我们的颜色设置的,而不是创建20个差异层。为什么不创建一些,只更改颜色呢?

Lee Mac 发表于 2022-7-6 15:18:05

不太清楚您想要的是什么,但可以这样选择实体并更改其颜色:
 

(defun c:a1 ()
(command "_chprop" (cadr (ssgetfirst)) "" "_C" "1" "")
(princ))

 
(不需要错误陷阱)

Lee Mac 发表于 2022-7-6 15:30:23

实际上,可能需要一个IF语句:
 

(defun c:a1 ()
(if (cadr (ssgetfirst))
(command "_chprop" (cadr (ssgetfirst)) "" "_C" "1" ""))
(princ))

BLOACH85 发表于 2022-7-6 15:38:13

好的,这是我想要的,我需要它来改变一个特定层的颜色,也改变一个特定选定对象的颜色。两者都不是或。

Lee Mac 发表于 2022-7-6 16:05:17

也许 吧:
 

(defun c:a1 (/ ss col ent)
(if (and (setq ss (ssget))
      (setq col (acad_colordlg 0 T)))
   (progn
   (setq ent (ssname ss 0))
   (command "-layer" "_C" col (cdr (assoc 8 (entget ent))) "")
   (command "_chprop" ss "" "_C" "BYLAYER" ""))
   (princ "\n<!> No Colour/Object Selected <!>"))
(princ))
页: [1]
查看完整版本: 关于颜色的问题