Either it's deja-vu or this is the same post thats at Autodesk discussion groups 
Well, whichever one you find first mate.
Code:
(defun c:cghid ()
;;;check if newlayer exists and create it if it doesn't
;;;substitute NEWLAYER with your layer name in 3 places
(if (not (tblsearch "LAYER" "NEWLAYER"))
(command "-layer" "m" "NEWLAYER" "")
) ;_if
(setq layerName (tblnext "LAYER" 1))
(while layerName
(if (= (cdr (assoc 6 layerName)) "HIDDEN")
(progn
(setq hiddenLayerEntities
(ssget "X"
(list (cons 8 (cdr (assoc 2 layerName))))
)
)
(if hiddenLayerEntities
(COMMAND "change" hiddenLayerEntities
"" "p" "layer"
"NEWLAYER" ""
) ;_ end of command
) ;_if
) ;_progn
) ;_if
(setq layerName (tblnext "LAYER"))
) ;_while
) ;_defun