I work with single Layout drawings, but thought your post was interesting, and I can imagine how frustrating that must be.
So, I wrote this quickly; seem to work in limited testing here, where each XREF in each Layout (of multiple Layouts) was on the same, unlocked Layer:
Code:
(vl-load-com)
(defun c:XDM () (c:XrefDetachMultiple))
(defun c:XrefDetachMultiple
(/ *error* ss acDoc oBlocks e v xrefName oXref objectId i oSs)
(defun *error* (msg)
;;<-- restore locked layers here (if any)
(if oSs (vla-delete oSs))
(if acDoc (vla-endundomark acDoc))
(cond ((not msg)) ; Normal exit
((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit)
((princ (strcat "\n** Error: " msg " ** "))) ; Fatal error, display it
)
(princ)
)
(if (setq ss (ssget ":S:E:L" '((0 . "INSERT"))))
(progn
(setq oBlocks (vla-get-blocks
(setq acDoc (vla-get-activedocument
(vlax-get-acad-object)
)
)
)
)
(setq e (ssname ss 0))
(setq v (vlax-ename->vla-object e))
(setq xrefName (vla-get-name v))
(if
(= :vlax-true
(vla-get-isxref (setq oXref (vla-item oBlocks xrefName)))
)
(progn
(vla-startundomark acDoc)
(if
(and
(setq ss
(ssget "_x" (list '(0 . "INSERT") (cons 2 xrefName)))
)
(setq objectId (vla-get-objectid v))
(setq i 0)
)
(progn
(vlax-for x
(setq oSs (vla-get-activeselectionset acDoc))
(if (/= objectId (vla-get-objectid x))
(progn
;;<-- check for locked layers here
(vla-delete x)
(setq i (1+ i))
)
)
)
(prompt
(strcat "\n >> "
(itoa i)
" duplicate XREF"
(if (= 1 i)
""
"s"
)
" deleted. "
)
)
)
)
(progn
(vla-detach oXref)
(prompt
(strcat "\n >> XREF \"" xrefName "\" detached. \n")
)
)
)
(prompt "\n** Selected block is not an XREF ** \n")
)
)
)
(*error* nil)
)
Example from Command Line:
Code:
Command: XDM
Select objects:
>> 3 duplicate XREFs deleted.
>> XREF "TITLEBLOCK" detached.
Command:
Cheers