Arnold Williams offered this tip for getting rid of unused layers. "AutoCAD does not let you purge an unused layer if it is current. This little tool gets around that by making Layer 0 current first, then running the Purge command. If the previous current layer is not purged in this process, then it is restored as the current layer again after purging is complete. If that previous current layer is purged, then layer 0 remains current."
(defun c:PUL ( / CLyr)
(vl-cmdf "_.undo" "_begin")
(if (not (eq (getvar "clayer") "0"))
(setq CLyr (getvar "clayer"))
(setvar "clayer" "0")
(if (and CLyr (tblsearch "LAYER" CLyr))
(setvar "clayer" CLyr)
(vl-cmdf "_.undo" "_end")
NOTES FROM CADALYST TIP PATROL:
Good idea. Nothing is more frustrating with purging than when you realize you're on a nonreferenced layer. This is a nice way to purge and not have to remember to set your default layer to zero.