Here is a quick example of how to achieve this using AutoLISP:
(defun c:test ( / i l s )
(if (setq s (ssget '((0 . "INSERT"))))
(repeat (setq i (sslength s))
(setq l (processblock (cdr (assoc 2 (entget (ssname s (setq i (1- i)))))) l))
)
)
(command "_.regen")
(princ)
)
(defun processblock ( n l / e x )
(cond
( (member n l))
( (setq e (tblobjname "block" n))
(setq l (cons n l))
(while (setq e (entnext e))
(entmod (append (setq x (entget e)) '((62 . 9))))
(if (= "INSERT" (cdr (assoc 0 x)))
(setq l (processblock (cdr (assoc 2 x)) l))
)
)
)
)
l
)