Copied this in the depths of time, sorry no reference to where it came from. This deletes and then purges all objects on a layer doing what you want so long as there are no elements for example in a block that are on the specified layer.
Can change this to have an 'entsel' an entity and grab the layer name from using assoc and 8, though I am sure someone will have this all set up, this will give you a start
(defun c:laydelLayerNamw (/ ent l_name ss cntr amt ssent)
(setq MyLayer "LayuerName")
(setvar 'clayer "0")
(progn
(setq ss (ssget "X" (list (cons 8 MyLayer))) ;; create a selection set of all entites on layer
cntr (1- (sslength ss)) ;; set 'cntr' to number of items in selection set
amt (itoa cntr) ;; make a string from an integer
)
;; does the sel set have anything in it
(if (> cntr 1)
(while (>= cntr 0) ;; as long as 'cntr' is greater than or equal to 0 keep looping
(setq ssent (ssname ss cntr)) ;; extract the ename from the sel set
(entdel ssent) ;; delete that entity
(setq cntr (1- cntr)) ;; subtract 1 from cntr
)
)
)
(command "zoom" "all" "zoom" ".95x")
(command "_.purge" "LA" MyLayer "N")
(princ (strcat "\nErased " amt " items"))
(princ)
)