Since the result of an EXPLODE command simply becomes the Previous selection set, there's no need to save the last object, Explode, and then step through and find all newer objects. It can be simpler:
(defun C:X2L (/ ss)
(prompt "\nTo Explode Block(s) to Layer 01_layer,")
(if (setq ss (ssget "_:L" '((0 . "INSERT"))))
(progn ; then
(initcommandversion)
(command
"_.explode" ss ""
"_.chprop" "_previous" "" "_layer" "01_layer" ""
); command
); progn
); if
(prin1)
)
which also prevents selection of inappropriate objects, and even lets you do it to as many Blocks as you want, all at the same time.
That assumes that the Layer in question exists in the drawing. If it might not, that can be accommodated.
Kent Cooper, AIA