Another approach:
Create a block that has line segments, circles, or other simple object for each (and on that) layer. Insert it into the drawing and use the following to make the block reference invisible:
(defun c:jbPutInvisible (/ ent)
(setq ent (entsel))
(if ent
(vla-put-Visible (vlax-ename->vla-object (car ent)) :vlax-false)))
(defun c:jbPutAllVisible (/)
(vlax-for b (vla-get-blocks(vla-get-ActiveDocument(vlax-get-acad-object)))
(vlax-for x b
(if (vlax-property-available-p x 'visible T)
(vla-put-Visible x :vlax-true)))))
Now the block reference can't be erased so the block, and included layers, can't be purged. Include any other object table data in the same way: other blocks, textstyles, dimstyles, etc.
Just a thought,
jb