Here's a good start for you with some comments to help you learn. It does not explode the blocks but will do the layering. Welcome to CadTutor!
(defun c:foo (/ co d la ln lp rgb x)
;; RJP » 2019-08-27
;; Not much error checking!
;; Unlock all layers
(vlax-for a (vla-get-layers (setq d (vla-get-activedocument (vlax-get-acad-object))))
(vlax-put a 'lock 0)
)
;; Iterate all drawing objects
(vlax-for a (vla-get-blocks d)
(vlax-for b a
;; Get truecolor object
(setq co (vla-get-truecolor b))
;; Get RGB values for layername and check to swap black for white etc...
(setq rgb (mapcar '(lambda (x) (vlax-get co x)) '(red green blue)))
;; Check for bylayer, index color or change rgb if 0,0,0 or 0,0,1
(setq rgb
(cond ((= 256 (vla-get-color b))
;; Uses the index color of the layer the object is already on
(list (vla-get-color (vla-add (vla-get-layers d) (vla-get-layer b))))
)
;; Index color
((null (assoc 420 (entget (vlax-vla-object->ename b)))) (list (vla-get-color b)))
;; Black to white
((equal '(0 0 0) rgb) '(255 255 255))
;; Almost black to black
((equal '(0 0 1) rgb) '(0 0 0))
;; Just return RGB
(rgb)
)
)
;; Set RGB colors if list has 3 elements
(and (= 3 (length rgb)) (vla-setrgb co (car rgb) (cadr rgb) (caddr rgb)))
;; Create layer prefix based on object type
(setq lp (cond ((= "AcDbHatch" (vla-get-objectname b)) "Hatch")
("Linework")
)
)
;; Uncomment below to create layer prefix based on object type not grouped as "Linework"
;; (setq lp (substr (vla-get-objectname b) 5))
;; Add new layer
(setq la (vla-add (vla-get-layers d) (setq ln (strcat lp " - " (vl-princ-to-string rgb)))))
;; Set layer color
(if (= 1 (length rgb))
(vla-put-color la (car rgb))
(vla-put-truecolor la co)
)
;; Make object color bylayer
(vla-put-color b 256)
;; Move object to layer
(vla-put-layer b ln)
)
)
;; Purge 3 times
(repeat 3 (vla-purgeall d))
(princ)
)