;;; Remove any unloaded (unreferenced) XREFs,IMAGE's,PDF's,DGN's and DWF's in a one click
;;; Combined from existing subroutines by Igal Averbuh 2016
;;; Based on https://www.theswamp.org/index.php?topic=51337.0
;;; With respect to T.Willey

; Detach any unloaded (unreferenced) XREFs
(defun C:dux ()
(vlax-for BIND_xrefname (vla-get-blocks (vla-get-ActiveDocument (vlax-get-Acad-object)))
(if (= (vla-get-isxref BIND_xrefname) ':vlax-true)
(progn
(setq BIND_cont (entget (vlax-vla-object->ename BIND_xrefname))
BIND_cont (tblsearch "BLOCK" (cdr (assoc 2 BIND_cont)))
)
(if (or (= (cdr (assoc 70 BIND_cont)) 4) (= (cdr (assoc 70 BIND_cont)) 12))
(vla-Detach BIND_xrefname)
)
)
)
)
)

(defun c:RID ( / isDefReferenced dict data name tData lst imName )
; Remove image definition of unreferenced and unloaded definitions.
(defun isDefReferenced ( aEname / cnt data )
(setq cnt 0)
(foreach i (entget aEname)
(if
(and
(equal (car i) 330)
(setq data (entget (cdr i)))
(= (cdr (assoc 0 data)) "IMAGEDEF_REACTOR")
)
(foreach j data
(if (and (equal (car j) 330) (entget (cdr j)))
(setq cnt (+ cnt 1))
)
)
)
)
(> cnt 0)
)
;-------------------------------------------------------
(setq dict (namedobjdict))
(setq data (entget dict))
(setq name "ACAD_IMAGE_DICT")
(if (setq data (dictsearch dict name))
(foreach i data
(cond
((and imName (equal (car i) 350))
;check to see if unreferenced or unload
(setq tData (entget (cdr i)))
(if (or (equal (cdr (assoc 280 tData)) 0) (not (isDefReferenced (cdr i))))
(setq lst (cons (cons imName (cdr i)) lst))
)
)
((equal (car i) 3) (setq imName (cdr i)))
(t (setq imName nil))
)
)
)
(if lst
(progn
(setq dict (cdr (assoc -1 data)))
(foreach i lst
(dictremove dict (car i))
(entdel (cdr i))
)
(prompt (strcat "\n Removed " (itoa (length lst)) " image definition(s)."))
)
)
(princ)
)

(defun c:RPD ( / isDefReferenced dict data name tData lst imName )
; Remove pdf definition of unreferenced and unloaded definitions.
(defun isDefReferenced ( aEname / cnt data )
(setq cnt 0)
(foreach i (entget aEname)
(if
(and
(equal (car i) 330)
(setq data (entget (cdr i)))
(= (cdr (assoc 0 data)) "IMAGEDEF_REACTOR")
)
(foreach j data
(if (and (equal (car j) 330) (entget (cdr j)))
(setq cnt (+ cnt 1))
)
)
)
)
(> cnt 0)
)
;-------------------------------------------------------
(setq dict (namedobjdict))
(setq data (entget dict))
(setq name "ACAD_PDFDEFINITIONS")
(if (setq data (dictsearch dict name))
(foreach i data
(cond
((and imName (equal (car i) 350))
;check to see if unreferenced or unload
(setq tData (entget (cdr i)))
(if (or (equal (cdr (assoc 280 tData)) 0) (not (isDefReferenced (cdr i))))
(setq lst (cons (cons imName (cdr i)) lst))
)
)
((equal (car i) 3) (setq imName (cdr i)))
(t (setq imName nil))
)
)
)
(if lst
(progn
(setq dict (cdr (assoc -1 data)))
(foreach i lst
(dictremove dict (car i))
(entdel (cdr i))
)
(prompt (strcat "\n Removed " (itoa (length lst)) " pdf definition(s)."))
)
)
(princ)
)

(defun c:RDD ( / isDefReferenced dict data name tData lst imName )
; Remove dgn definition of unreferenced and unloaded definitions.
(defun isDefReferenced ( aEname / cnt data )
(setq cnt 0)
(foreach i (entget aEname)
(if
(and
(equal (car i) 330)
(setq data (entget (cdr i)))
(= (cdr (assoc 0 data)) "IMAGEDEF_REACTOR")
)
(foreach j data
(if (and (equal (car j) 330) (entget (cdr j)))
(setq cnt (+ cnt 1))
)
)
)
)
(> cnt 0)
)
;-------------------------------------------------------
(setq dict (namedobjdict))
(setq data (entget dict))
(setq name "ACAD_DGNDEFINITIONS")
(if (setq data (dictsearch dict name))
(foreach i data
(cond
((and imName (equal (car i) 350))
;check to see if unreferenced or unload
(setq tData (entget (cdr i)))
(if (or (equal (cdr (assoc 280 tData)) 0) (not (isDefReferenced (cdr i))))
(setq lst (cons (cons imName (cdr i)) lst))
)
)
((equal (car i) 3) (setq imName (cdr i)))
(t (setq imName nil))
)
)
)
(if lst
(progn
(setq dict (cdr (assoc -1 data)))
(foreach i lst
(dictremove dict (car i))
(entdel (cdr i))
)
(prompt (strcat "\n Removed " (itoa (length lst)) " dgn definition(s)."))
)
)
(princ)
)

(defun c:RWD ( / isDefReferenced dict data name tData lst imName )
; Remove dwf definition of unreferenced and unloaded definitions.
(defun isDefReferenced ( aEname / cnt data )
(setq cnt 0)
(foreach i (entget aEname)
(if
(and
(equal (car i) 330)
(setq data (entget (cdr i)))
(= (cdr (assoc 0 data)) "IMAGEDEF_REACTOR")
)
(foreach j data
(if (and (equal (car j) 330) (entget (cdr j)))
(setq cnt (+ cnt 1))
)
)
)
)
(> cnt 0)
)
;-------------------------------------------------------
(setq dict (namedobjdict))
(setq data (entget dict))
(setq name "ACAD_DWFDEFINITIONS")
(if (setq data (dictsearch dict name))
(foreach i data
(cond
((and imName (equal (car i) 350))
;check to see if unreferenced or unload
(setq tData (entget (cdr i)))
(if (or (equal (cdr (assoc 280 tData)) 0) (not (isDefReferenced (cdr i))))
(setq lst (cons (cons imName (cdr i)) lst))
)
)
((equal (car i) 3) (setq imName (cdr i)))
(t (setq imName nil))
)
)
)
(if lst
(progn
(setq dict (cdr (assoc -1 data)))
(foreach i lst
(dictremove dict (car i))
(entdel (cdr i))
)
(prompt (strcat "\n Removed " (itoa (length lst)) " dwf definition(s)."))
)
)
(princ)
)

(defun c:eid ()
(c:dux)
(c:rid)
(c:rpd)
(c:rdd)
(c:rwd)
(vl-cmdf "_.externalreferences")
(princ)
)
(c:eid)

Advertisements