For that kind of work, I still prefer the layer command:
(defun c:lo (/ i ss en el)
(if (setq i -1
ss (ssget))
(progn
(while (setq en (ssname ss (setq i (1+ i))))
(setq el (strcase (cdr (assoc 8 (entget en)))))
(if (not (member el LayOffList))
(setq LayOffList (cons el LayOffList))))
(command "_.LAYER")
(foreach l LayOffList
(command "_Off" l))
(command "")))
(prin1))
(defun c:ol ()
(if LayOffList
(progn
(command "_.LAYER")
(foreach l LayOffList
(command "_On" l))
(command "")))
(prin1))
No matter which, dealing with turning the current layer off probably should be addressed. -David