请教各位一个关于物体颜色的问题
;show the color of you select(defun c:sc(/ a a1 tn tf ff)
(setq a (entsel))
(setq a1 (entget(car a)))
(setq tn(assoc 8 a1))
(setq tf(tblsearch "LAYER" (cdr tn)))
(prompt "\nThe color index of its layer is: ")(terpri)
(setq ff (cdr(assoc 62 tf)))
)
执行命令
选中一个物体,自动显示这个物体所在图层的颜色。。。
但是如何修改成自动显示这个物体本身的颜色呢?因为有些物体的颜色不随层的。
谢谢各位!
(setq ff (cdr (assoc 62 a1))) vormittag 发表于 2012-11-20 18:02 static/image/common/back.gif
试了,不行啊,出来nil
;show the color of you select
(defun c:sc(/ a a1 tn tf ff)
(if (setq a (entsel)) (progn
(setq a1 (entget(car a)))
(prompt "\nThe color index of its layer is: ")(terpri)
(if (assoc 62 al)
(setq ff (cdr(assoc 62 al)))
(progn
(setq tn (cdr(assoc 8 a1)))
(setq tf (tblsearch "LAYER" tn))
(setq ff (cdr(assoc 62 tf)))
))
))
)
(defun c:sc (/ a a1 tn tf ff)
(setq a (entsel))
(setq a1 (entget (car a)))
(cond
((setq clr (assoc 62 a1))
(princ (cdr clr))
)
((setq tf (tblsearch "LAYER" (cdr (assoc 8 a1))))
;; (prompt "\nThe color index of its layer is: ")
;; (terpri)
(princ (cdr (assoc 62 tf)))
))
(princ)
) ZZXXQQ 发表于 2012-11-20 19:46 static/image/common/back.gif
谢谢!试了,但是是不行啊 Andyhon 发表于 2012-11-20 20:02 static/image/common/back.gif
(defun c:sc (/ a a1 tn tf ff)
(setq a (entsel))
(setq a1 (entget (car a)))
谢谢,代码可以达到我的想法!
膜拜! 本帖最后由 llsheng_73 于 2013-10-23 17:21 编辑
tjherrlu 发表于 2012-11-21 17:43 static/image/common/back.gif
谢谢,代码可以达到我的想法!
膜拜!
图元对象的颜色值虽然是组码62相关的,但当它为随层时并不会出现,这个时候(assoc 62 ename)会返回NIL
如果进一步进行(cdr....),它会出错,这时要取得它的颜色就只能通过所在图层去获取,相对来说比较麻烦
可以用vla-get很简单的回避这个问题
(vlax-get-property(vlax-ename->vla-object(car(entsel)))'COLOR)
同样的,如果要修改它的颜色也是,不能简单的进行(entmod (subst (cons 62 0)(assoc 62 ent)ent)),也会因为62组码有时并不存在而需要特殊处理
可以用vla-put来回避
(vlax-put-property(vlax-ename->vla-object(car(entsel)))'COLOR 1);1根据具体需要改成相应数值
页:
[1]