Not to happy with the code but here is one that will freeze all but selected layers
The selected layers are turned off temporally as you select them.
;; CAB 08.21.08 [ Limited Testing ] version 3
;; User pick of layers to remain Thawed, freeze all others
;; Picked layers turn off as picked, when Enter is pressed
;; picked layers are thawed & turned on and all others are frozen
;;
;; modified to allow current layer to be frozen, makes the first
;; thawed layer current
;;
;; If a layer in an xref is selected the layer the xref is on can
;; not be frozen
;;
;; Layer 0 in an xref will not be frozen
;;
;; added uiso to restore the previous layer states
;;
(defun c:liso (/ laylst thalst ent lname xrlays)
(vl-load-com)
;; get current layer settings
(defun getlayerdata (doc / lst)
(vlax-for layObj (vla-get-layers doc)
(setq lst (cons (list layObj
(vla-get-freeze layObj)
(vla-get-layeron layObj)
)
lst)))
lst
)
(defun xrefp (ent / elist blist)
(and
(setq elist (entget ent))
(setq blist (entget (tblobjname "BLOCK" (cdr (assoc 2 elist)))))
(= 4 (logand (cdr (assoc 70 blist)) 4))
)
)
(defun LayerOff (layname doc) ; added for version 3
(vla-put-LayerOn (vla-item (vla-get-layers doc) layname) :vlax-false)
)
(command ".undo" "begin")
(setq *laysts (getlayerdata (vla-get-activedocument (vlax-get-acad-object)))
*clayer (getvar "clayer")
)
(prompt "\nLayers picked will turn off during selection.")
(while (setq ent (nentsel "\nPick layers to keep thawed. Enter when done"))
(setq lname (cdr (assoc 8 (entget (car ent)))))
(if (vl-position lname xrlays)
(prompt "\nFlagged xref layer can not be frozen.")
(if (and (= lname "0") (cadddr ent) (xrefp (last (nth 3 ent))))
(prompt "\nLayer 0 in xref can not be frozen.")
(progn
(setq thalst (cons lname thalst))
(LayerOff lname (vla-get-activedocument (vlax-get-acad-object)))
(if (and (cadddr ent) (xrefp (car (nth 3 ent))))
(progn ; save the xref layer
(setq xrlays (cons (cdr (assoc 8 (entget (last (nth 3 ent))))) xrlays)
thalst (cons (car xrlays) thalst)
)
)
)
)
)
)
)
(if thalst
(progn
(setq laylst (list (cdr (assoc 2 (tblnext "layer" t))))
clayer (getvar "clayer")
)
(while (setq lay (cdr (assoc 2 (tblnext "layer"))))
(if (and lay
(not (member lay thalst))
(/= lay clayer)
)
(setq laylst (cons lay laylst))
)
)
(if (vl-position *clayer laylst)
(setvar "clayer" (car thalst))
)
(command "._Layer")
(mapcar '(lambda (x) (command "_f" x)) laylst)
(command "")
(command "._Layer")
(mapcar '(lambda (x) (command "_ON" x)) thalst)
(command "")
)
)
(command ".undo" "end")
(princ)
)
(prompt "\n*-* Layers Isolate loaded, Enter LayISO to run. *-*")
(princ)
;; restore previous layer settings
(defun c:uiso (/ doc)
(setq doc (vla-get-activedocument (vlax-get-acad-object))
clayer (vla-get-activelayer doc)
)
(if *laysts
(progn
(vlax-for layObj (vla-get-layers doc)
(if (and (setq lyrdat (assoc layObj *laysts))
(not (equal clayer layObj))
)
(progn
(vla-put-freeze layObj (cadr lyrdat))
(vla-put-layeron layObj (caddr lyrdat))
(if (= *clayer (vla-get-name layObj))
(vla-put-activelayer doc layObj)
)
)
)
)
(setq lyrdat (assoc clayer *laysts))
(if (/= *clayer (vla-get-name (car lyrdat)))
(vla-put-freeze (car lyrdat) (cadr lyrdat))
)
(vla-put-layeron (car lyrdat) (caddr lyrdat))
(vla-regen doc acactiveviewport)
)
)
)
<edit: code updated>