I would also check the blocks to see if they are xrefs or layouts. So in your code, I would change this portion.
(vlax-for block (vla-get-blocks *thisdwg*);iterate block table
(if (= 0 (vla-get-count block))
(setq nullblocks (cons (vla-get-name block) nullblocks))))
to
(vlax-for block (vla-get-blocks *thisdwg*);iterate block table
(if (and
(= 0 (vla-get-count block))
(equal (vla-get-IsXref block) :vlax-false)
(equal (vla-get-IsLayout block) :vlax-false)
)
(setq nullblocks (cons (vla-get-name block) nullblocks))))
Also if you don't want to use the command purge, then you could store the block definition, instead of just the name, and use that to delete the block; delete method of the block definition.