是不是通过选取图元,其所在图层是打开的,未选到的图元其所在图层就闭关。如果是这样,请试用下面两程序。
;;选取图元,关闭其所在图层之外的所有图层
(defun c:gbtc()
(vl-load-com)
(setq cm (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "_undo" "be")
(setq tcmb nil)
(vlax-for layer (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq tcmb (cons (list (vla-get-name layer) layer) tcmb))
)
(if (setq ssa (ssget ))
(progn
(setq tymb (vl-remove-if 'listp (mapcar 'cadr (ssnamex ssa))))
(foreach ent tymb
(setq name (cdr (assoc 8 (entget ent)))
tcmb (vl-remove (assoc name tcmb) tcmb)
)
)
(foreach tcm tcmb
(vla-put-LayerOn (cadr tcm) :vlax-false)
)
)
)
(command "_undo" "e")
(setvar "cmdecho" cm)
(princ)
)
;;打开闭关的所有图层
(defun c:dktc()
(vl-load-com)
(setq cm (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "_undo" "be")
(setq tcmb nil)
(vlax-for layer (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
(if (= (vla-get-LayerOn layer) ':vlax-false)
(vla-put-LayerOn layer :vlax-true)
)
)
(command "_undo" "e")
(setvar "cmdecho" cm)
(princ)
)
(command "LAYER" "Off" "图层" "");关闭这个【图层】
(command "LAYER" "ON" "图层" "");打开这个【图层】
不知道是不是你需要的。
如果要关闭除了选择对象的图层;(setvar "clayer" "图层");设置这个图层为当前,然后逐个关闭其它的图层。
我在 古荡