;;关闭所选
(defun C:LayerOff (/ las ls nm ss)
  (princ "\n请选取要关闭其图层的对象:")
  (or (setq ss (ssget)) (fsxm-silenceexit))
  (foreach en (fsxm-ss->enlist ss)
    (setq nm (fsxm-getendxf en 8))
    (or	(vl-position nm ls)
	(setq ls (cons nm ls))
    )
  )
  (princ "\n关闭图层:")
  (setq las (vla-get-Layers *doc*))
  (foreach nm ls
    (vla-put-LayerOn (vla-item las nm) 0)
    (princ (strcat nm ","))
  )
  (princ)
)
;;关闭其它
(defun c:LayerOffOther (/ all las ls nm obj ss)
  (princ "\n请选取不要关闭图层的对象:")
  (or (setq ss (ssget)) (fsxm-silenceexit))
  (setq all (fsxm-tbl-namelist "layer"))
  (foreach en (fsxm-ss->enlist ss)
    (setq nm (fsxm-getendxf en 8))
    (setq ls (cons nm ls))
  )
  (princ "\n关闭图层:")
  (setq las (vla-get-Layers *doc*))
  (foreach nm (acad_strlsort all)
    (setq obj (vla-item las nm))
    (cond ((vl-position nm ls) (vla-put-LayerOn obj 1))
	  (t (vla-put-LayerOn obj 0) (princ (strcat nm ",")))
    )
  )
  (princ)
)
;;反向关闭
(defun c:LayerOffSwap (/ md)
  (vlax-for la (vla-get-Layers *doc*)
    (setq md (1- (abs (vlax-get la 'LayerOn))))
    (vla-put-LayerOn la md)
  )
  (princ "\n反向关闭图层操作完成!")
  (princ)
)
;;打开所有
(defun c:LayerOnAll (/)
  (vlax-for la (vla-get-Layers *doc*) (vla-put-LayerOn la 1))
  (princ "\n打开所有图层操作完成!")
  (princ)
)

;;; ------------------------------------------------------------------
;;锁定所选
(defun C:LayerLock (/ las ls nm ss)
  (princ "\n请选取要锁定其图层的对象:")
  (or (setq ss (ssget)) (fsxm-silenceexit))
  (foreach en (fsxm-ss->enlist ss)
    (setq nm (fsxm-getendxf en 8))
    (or	(vl-position nm ls)
	(setq ls (cons nm ls))
    )
  )
  (princ "\n锁定图层:")
  (setq las (vla-get-Layers *doc*))
  (foreach nm ls
    (vla-put-lock (vla-item las nm) 1)
    (princ (strcat nm ","))
  )
  (princ)
)
;;锁定其它
(defun c:LayerLockOther	(/ all las ls nm obj ss)
  (princ "\n请选取不要锁定图层的对象:")
  (or (setq ss (ssget)) (fsxm-silenceexit))
  (setq all (fsxm-tbl-namelist "layer"))
  (foreach en (fsxm-ss->enlist ss)
    (setq nm (fsxm-getendxf en 8))
    (setq ls (cons nm ls))
  )
  (princ "\n锁定图层:")
  (setq las (vla-get-Layers *doc*))
  (foreach nm all
    (setq obj (vla-item las nm))
    (cond ((vl-position nm ls) (vla-put-Lock obj 0))
	  (t (vla-put-Lock obj 1) (princ (strcat nm ",")))
    )
  )
  (princ)
)
;;反向锁定
(defun c:LayerLockSwap (/ md)
  (vlax-for la (vla-get-Layers *doc*)
    (setq md (1- (abs (vlax-get la 'LayerOn))))
    (vla-put-lock la md)
  )
  (princ "\n反向锁定图层操作完成!")
  (princ)
)
;;解锁所选
(defun C:LayerUnlock (/ las ls nm ss)
  (princ "\n请选取要解锁其图层的对象:")
  (or (setq ss (ssget)) (fsxm-silenceexit))
  (foreach en (fsxm-ss->enlist ss)
    (setq nm (fsxm-getendxf en 8))
    (or	(vl-position nm ls)
	(setq ls (cons nm ls))
    )
  )
  (princ "\n解锁图层:")
  (setq las (vla-get-Layers *doc*))
  (foreach nm ls
    (vla-put-lock (vla-item las nm) 0)
    (princ (strcat nm ","))
  )
  (princ)
)
;;LayerUnLockAll解锁所有
(defun c:LayerUnLockAll	()
  (vlax-for la (vla-get-Layers *doc*) (vla-put-Lock la 0))
  (princ "\n解锁所有图层操作完成!")
  (princ)
)
;;; ------------------------------------------------------------------
;;;冻结所选
(defun C:LayerFreeze (/ las ls nm ss)
  (princ "\n请选取要冻结其图层的对象:")
  (or (setq ss (ssget)) (fsxm-silenceexit))
  (foreach en (fsxm-ss->enlist ss)
    (setq nm (fsxm-getendxf en 8))
    (or	(vl-position nm ls)
	(setq ls (cons nm ls))
    )
  )
  (princ "\n冻结图层:")
  (setq las (vla-get-Layers *doc*))
  (foreach nm ls
    (if	(null (vl-catch-all-apply
		'vla-put-Freeze
		(list (vla-item las nm) 1)
	      )
	)
      (princ (strcat nm ","))
    )
  )
  (princ)
)
;;冻结其它
(defun c:LayerFreezeOther (/ all las ls nm obj ss)
  (princ "\n请选取不要冻结图层的对象:")
  (or (setq ss (ssget)) (fsxm-silenceexit))
  (setq all (fsxm-tbl-namelist "layer"))
  (foreach en (fsxm-ss->enlist ss)
    (setq nm (fsxm-getendxf en 8))
    (setq ls (cons nm ls))
  )
  (princ "\n冻结图层:")
  (setq las (vla-get-Layers *doc*))
  (foreach nm (acad_strlsort all)
    (setq obj (vla-item las nm))
    (if	(vl-position nm ls)
      (vl-catch-all-apply 'vla-put-Freeze (list obj 0))
      (if (null (vl-catch-all-apply 'vla-put-Freeze (list obj 1)))
	(princ (strcat nm ","))
      )
    )
  )
  (princ)
)
;;反向冻结
(defun c:LayerFreezeSwap (/ md)
  (vlax-for la (vla-get-Layers *doc*)
    (setq md (1- (abs (vlax-get la 'Freeze))))
    (vl-catch-all-apply 'vla-put-Freeze (list la md))
  )
  (princ "\n反向锁定图层操作完成!")
  (princ)
)
;;解冻所有
(defun C:LayerFreeAll ()
  (vlax-for la (vla-get-Layers *doc*)
    (vl-catch-all-apply 'vla-put-Freeze (list la 0))
  )
  (princ "\n解冻所有图层操作完成!")
  (princ)
)
;;释放所有
(defun c:LayerAllF ()
  (c:LayerOnAll)
  (c:LayerUnLockAll)
  (c:LayerFreeAll)
)
;;;移至当前
(defun c:ToActiveLayer (/ ss)
  (setvar "cmdecho" 0)
  (if (setq ss (ssget))
    (command "chprop"
	     ss
	     ""
	     "la"
	     (getvar "clayer")
	     "color"
	     "bylayer"
	     "ltype"
	     "bylayer"
	     ""
    )
  )
  (princ)
)
;;;图层刷子
(defun c:LayerMatch (/ enp ss)
  (setvar "cmdecho" 0)
  (if (setq enp (entsel "\n选取来源图层的一个对象:"))
    (while (progn (princ "\n选取要刷的目标对像:")
		  (setq ss (ssget ":s"))
	   )
      (command "chprop"
	       ss
	       ""
	       "la"
	       (fsxm-getendxf (car enp) 8)
	       ""
      )
    )
  )
  (princ)
)