Lisp to detach all pdfs

Lisp to detach all pdfs

mpa-la
Advocate Advocate
1,719 Views
3 Replies
Message 1 of 4

Lisp to detach all pdfs

mpa-la
Advocate
Advocate

Hello, I would like a lisp that detaches all pdfs.  The closest I could find is below.  (For credit, I found at https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-detach-all-images-and-underl... Could someone edit it so that it only does pdfs, not xrefs and images?  I don't know enough lisp to do so.  Thanks!  Allison

 

(defun c:detachall ( / mspcoll dictcoll)
(vl-load-com)
(vl-cmdf "_.-xref" "D" "*")
(vl-cmdf "_.-image" "D" "*")
(setq mspcoll (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for ent mspcoll
(if
(or
(eq (vl-catch-all-apply 'vla-get-objectname (list ent)) "AcDbDwfReference")
(eq (vl-catch-all-apply 'vla-get-objectname (list ent)) "AcDbPdfReference")
(eq (vl-catch-all-apply 'vla-get-objectname (list ent)) "AcDbDgnReference")
(eq (vl-catch-all-apply 'vla-get-objectname (list ent)) "AcDbOle2Frame")
)
(vla-delete ent)
)
)
(setq dictcoll (vla-get-dictionaries (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for di dictcoll
(if
(or
(eq (vl-catch-all-apply 'vla-get-name (list di)) "ACAD_IMAGE_DICT")
(eq (vl-catch-all-apply 'vla-get-name (list di)) "ACAD_PDFDEFINITIONS")
(eq (vl-catch-all-apply 'vla-get-name (list di)) "ACAD_DGNDEFINITIONS")
(eq (vl-catch-all-apply 'vla-get-name (list di)) "ACAD_DWFDEFINITIONS")
)
(progn
(vlax-for d di
(vla-delete d)
)
(vla-delete di)
)
)
)
(vl-cmdf "_.externalreferences")
(princ)
)

 

0 Likes
Accepted solutions (1)
1,720 Views
3 Replies
Replies (3)
Message 2 of 4

Moshe-A
Mentor
Mentor
Accepted solution

@mpa-la  hi,

 

give this a try.

 

enjoy

moshe

 

 

(vl-load-com)

; detach pdf underlay (defun c:delpdf (/ ss tbl dict) (if (setq ss (ssget "_X" '((0 . "PDFUNDERLAY")))) (progn (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (setq tbl (tblsearch "layer" (cdr (assoc '8 (entget ename))))) (if (not (= (logand (cdr (assoc '70 tbl)) 4) 4)) ; skip locked layers (entdel ename) ) ); foreach (setq dict (vla-get-dictionaries (vla-get-activedocument (vlax-get-acad-object)))) (vlax-map-collection (vla-item dict "ACAD_PDFDEFINITIONS") 'vla-delete) (vlax-release-object dict) ); progn ); if (princ) ); c:delpdf
0 Likes
Message 3 of 4

mpa-la
Advocate
Advocate

Perfect, thanks so much!!

0 Likes
Message 4 of 4

ronjonp
Advisor
Advisor

This should work too .. although you'll onlys ee the changes upon next open. Not sure of ramifications so use at our own risk 😉

(if (setq e (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_PDFDEFINITIONS"))))
  (entdel e)
)
0 Likes