请帮改一下成能够开关指定图层表
下面这个是开关图层的,想改成够开关laylst图层表,谢谢.(defun c:tt(/ laylst mm_a mm_sw)
(setvar "cmdecho" 0)
(setvar "Expert" 1)
(setq laylst (list "图层1" "图层2" "图层2"))
(vlax-for mm_layer (vla-get-Layers
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
(setq mm_a (vla-get-name mm_layer))
(if (= mm_a laylst);;这里laylst换成单一"图层1"就行,
(progn
(setq mm_sw (vla-get-layeron mm_layer))
(cond ((= mm_sw :vlax-true) (vl-cmdf "layer" "off" laylst ""))
((= mm_sw :vlax-false) (vl-cmdf "layer" "on" laylst ""))
);cond
);progn
);if
)
(setvar "Expert" 0)
(setvar "cmdecho" 1)
(princ)
)
应该不难改,自己试试,你都钻石会员了... 改不如写。
话说楼主用vlisp开关图层,vl-cmdf不需要用。
;;图层反向开关 LST图层列表 如果开则关,关则开
;;code by edata @mjtd.com 2014-8-4
(defun sk_layon&off(lst / a en sk_col)
(if(=(type lst) 'LIST)
(while(setq a(car lst))
(if(and(= (type a) 'STR)(setq en(tblobjname "layer" a)))
(progn
(setq elist(entget en))
(setq sk_col(cdr(assoc 62 elist)))
(setq sk_col (* sk_col -1))
(entmod(subst(cons 62 sk_col)(assoc 62 elist)elist))
)
)
(setq lst(cdr lst))
)
)
)
;;图层开关 LST图层列表 on&off=T为开 nil为关
;;code by edata @mjtd.com 2014-8-4
(defun sk_layon(lst on&off / a en sk_col)
(if(=(type lst) 'LIST)
(while(setq a(car lst))
(if(and(= (type a) 'STR)(setq en(tblobjname "layer" a)))
(progn
(setq elist(entget en))
(setq sk_col(cdr(assoc 62 elist)))
(if ((if on&off < >) sk_col 0)
(progn
(setq sk_col (* sk_col -1))
(entmod(subst(cons 62 sk_col)(assoc 62 elist)elist))
)
)
(entmod(subst(cons 62 sk_col)(assoc 62 elist)elist))
)
)
(setq lst(cdr lst))
)
)
)
(defun c:tt(/ lst)
(setq lst '("0" "layer1" "layer2" "layer3" "layer4" "layer5" "layer6" "layer7" "layer8""layer10" "layer11" "layer12"))
;(sk_layon&off lst);;图层反向开关 LST图层列表 如果开则关,关则开
(sk_layon lst nil);;图层开关 LST图层列表 on&off=T为开 nil为关
(princ)
)
VLISP方式
;;图层反向开关 LST图层列表 如果开则关,关则开
;;code by edata @mjtd.com 2014-8-4
(defun sk_layon&off2(lst / obj)
(vlax-for obj (vla-get-layers(vla-get-activedocument(vlax-get-acad-object)))
(if (member (strcase (vla-get-name obj)) (mapcar 'strcase lst))
(if (= (vla-get-layeron obj) :vlax-true)
(vla-put-layeron obj :vlax-false)
(vla-put-layeron obj :vlax-true)
)
)
)
)
;;图层开关 LST图层列表 on&off=T为开 nil为关
;;code by edata @mjtd.com 2014-8-4
(defun sk_layon2(lst on&off / obj)
(vlax-for obj (vla-get-layers(vla-get-activedocument(vlax-get-acad-object)))
(if (member (strcase (vla-get-name obj)) (mapcar 'strcase lst))
(if on&off (vla-put-layeron obj :vlax-true) (vla-put-layeron obj :vlax-false))
)
)
)
(defun c:tt()
(setq lst'("0" "layer1" "layer2" "layer3" "layer4" "layer5" "layer6" "layer7" "layer8" "layer9" "layer10" "layer11" "layer12"))
(sk_layon2 lst nil)
)
本帖最后由 kwok 于 2014-8-4 19:27 编辑
edata 发表于 2014-8-4 10:50 static/image/common/back.gif
VLISP方式
3Q . 本帖最后由 kwok 于 2014-8-4 19:27 编辑
图层名列表表相减. (vl-remove-if '(lambda(x) (member x lst1)) lst))
不知有没有别的方法.
edata 发表于 2014-8-4 10:50
VLISP方式
大师,为什么我这边只能关图层不能开图层
页:
[1]