IMO this is much easier using VLA ... give this a try:
(defun c:foo (/ a d)
;; RJP » 2022-04-13
;; All blocks internals to layer 0, color byblock and linetype byblock
(vlax-for l (vla-get-layers (setq d (vla-get-activedocument (vlax-get-acad-object))))
(cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a))))
)
(vlax-for b (vla-get-blocks d)
(if
(and (= 0 (vlax-get b 'isxref) (vlax-get b 'islayout)) (not (wcmatch (vla-get-name b) "*|*")))
(vlax-for o b
(cond ((vlax-write-enabled-p o)
(vl-catch-all-apply 'vla-put-layer (list o "0"))
(vl-catch-all-apply 'vla-put-linetype (list o "ByBlock"))
(vl-catch-all-apply 'vla-put-color (list o 0))
)
)
)
)
)
(foreach l a (vlax-put l 'lock -1))
(vla-regen d acallviewports)
(princ)
)
Update per sample drawing below.
(defun c:foo2 (/ a d f)
;; RJP » 2022-04-13
(vlax-for l (vla-get-layers (setq d (vla-get-activedocument (vlax-get-acad-object))))
(cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a))))
)
(vlax-for b (vla-get-blocks d)
(setq f (and (= 0 (vlax-get b 'isxref) (vlax-get b 'islayout))))
(vlax-for o b
(cond ((vlax-write-enabled-p o)
;; Only internals of block definitions to layer 0
(and f (vl-catch-all-apply 'vla-put-layer (list o "0")))
;; Everything else
(vl-catch-all-apply 'vla-put-linetype (list o "ByBlock"))
(vl-catch-all-apply 'vla-put-color (list o 0))
)
)
)
)
(foreach l a (vlax-put l 'lock -1))
(vla-regen d acallviewports)
(princ)
)