Jump to content

Finding (and detaching) Raster Image and PDF references in AutoLISP


Recommended Posts

Posted

I'm looking to automate the removal of unreferenced XREFs. However, I can't even find them. They don't exist in the "block" table with the other XREFs/blocks, so I'm a bit lost as I couldn't find any solutions online. 

Posted

found this one under a layer of dust :

 

;;; https://lispbox.wordpress.com/2016/05/01/remove-any-unloaded-unreferenced-xrefsimagespdfsdgns-and-dwfs-in-a-one-click/
;;; 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)

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...