Here you go. I have had some time now. The reason why the last one didn't work it because some of the tests that were run could only be run on objects for the block collection. So we shall combind both.
(defun XrefDetach (/ tmpObj)
(vlax-for Layout (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for i (vla-get-Block Layout)
(if
(and
(= (vla-get-ObjectName i) "AcDbBlockReference")
(vlax-property-available-p i 'Path)
(setq tmpObj (vla-Item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object))) (vla-get-Name i)))
(vl-catch-all-error-p
(vl-catch-all-apply 'vla-get-XrefDatabase (list tmpObj))
)
)
(vla-Detach tmpObj)
)
)
)
(princ)
)
This worked here, but you can't use it after a reload. I think that once you reload it keeps the reference to the XrefDatabase property. I don't see a way around it.
Looking back into this thread I saw this.
Michael, you can find unloaded xrefs only by looking for code 71. If present, the xref is unloaded. Otherwise it'll be missing no matter if it's unresolved or not.
But it isn't the case after you reload, at least is wasn't in my drawing.
Command: -xref
Enter an option [?/Bind/Detach/Path/Unload/Reload/Overlay/Attach] <Attach>: u
Enter xref name(s) to unload: NORT-003-E-RFPWR
Xref "NORT-003-E-RFPWR": NORT-003-E-RFPWR.DWG
"NORT-003-E-RFPWR" is unloaded.
Command: (TBLSEARCH "BLOCK" "NORT-003-E-RFPWR")
((0 . "BLOCK") (2 . "NORT-003-E-RFPWR") (70 . 12) (4 . "") (10 0.0 0.0 0.0) (1
. "NORT-003-E-RFPWR.DWG") (-2 . <Entity name: 7effc480>))