Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: LISP to detach all XREF,PDF,IMAGE,ALL UNDERLAYS

  1. #1
    Member
    Join Date
    2005-08
    Posts
    8
    Login to Give a bone
    0

    Default LISP to detach all XREF,PDF,IMAGE,ALL UNDERLAYS

    Anyone know of a LISP routine to remove or rather detach all XREFS, PDF, IMAGE, other underlays from a drawing.

    When I clean up drawings that I receive I want to be able to simply detach everything to get down to only the actual entities that are in the drawing. It doesn't matter if the XREFS are referenced. I will still want them gone as with everything else.

    I know the following will get rid of images.

    Code:
    (vl-cmdf "-Image" "D" "*")
    and I found this in another thread.

    Code:
    (defun c:XD (/ *blks* ref xname)
    (vl-load-com)
    (setq *blks*
           (vla-get-Blocks
    	 (vla-get-ActiveDocument
    	   (vlax-get-acad-object)
    	 )
           )
    )
    (vlax-for item *blks*
      (if (eq (vla-get-IsXref item) :vlax-true)
        (progn
          (setq ref (tblsearch "BLOCK" (setq xname (vla-get-Name item))))      
          (if (eq (logand (cdr (assoc 70 ref)) 32) 32)
    	(command "-xref" "_R" xname)
    	(command "-xref" "_D" xname)
          )	
        )
      )
    )
    (vl-cmdf "-Image" "D" "*")
    (princ)
    
    )
    Which I found here: http://forums.augi.com/showthread.php?t=64428&page=2 Thanks to jmcshane.
    Last edited by sweichel; 2011-07-01 at 03:43 PM. Reason: [code] tags added

  2. #2
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: LISP to detach all XREF,PDF,IMAGE,ALL UNDERLAYS

    This may help you with it ..

    Code:
    (defun c:Test (/ acdoc ss)
      ;; Tharwat 01. 07. 2011
      (vl-load-com)
      (setq acdoc (vla-get-activedocument
                    (vlax-get-acad-object)
                  )
      )
      (if (setq ss (ssget "_x" '((0 . "OLE2FRAME,IMAGE,INSERT"))))
        (
         (lambda (i / sset vl e)
           (while
             (setq sset (ssname ss (setq i (1+ i))))
              (setq vl (vlax-ename->vla-object sset))
              (setq e (entget sset))
              (cond
                (
                 (eq (cdr (assoc 0 e)) "OLE2FRAME")
                 (vla-delete vl)
                )
                (
                 (eq (cdr (assoc 0 e)) "IMAGE")
                 (vl-cmdf "_.-image" "_detach" (vla-get-name vl) "")
                )
                (
                 (and (eq (cdr (assoc 0 e)) "INSERT")
                      (vlax-property-available-p vl 'Path)
                 )
                 (vl-cmdf "_.-xref" "_detach" (vla-get-name vl) "")
                )
              )
           )
         )
          -1
        )
        (alert
          "No Xref file(s) or Image(s) or even OLE found to detach !!"
        )
      )
      (vla-regen acdoc acAllViewports)
      (princ)
    )
    Tharwat

  3. #3
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: LISP to detach all XREF,PDF,IMAGE,ALL UNDERLAYS

    Because some type of objects that are attached into dwg you can't detach without dialog box "externalreferences", you should manually detach them...

    Code:
    (defun c:Test (/ acdoc ss)
      ;; Tharwat 01. 07. 2011 - modified
      (vl-load-com)
      (setq acdoc (vla-get-activedocument
                    (vlax-get-acad-object)
                  )
      )
      (if (setq ss (ssget "_X" '((0 . "DGNUNDERLAY,DWFUNDERLAY,PDFUNDERLAY,OLE2FRAME,IMAGE,INSERT"))))
        (
         (lambda (i / sset vl e)
           (while
             (setq sset (ssname ss (setq i (1+ i))))
              (setq vl (vlax-ename->vla-object sset))
              (setq e (entget sset))
              (cond
                (
                 (eq (cdr (assoc 0 e)) "OLE2FRAME")
                 (vla-delete vl)
                )
                (
                 (eq (cdr (assoc 0 e)) "IMAGE")
                 (vl-cmdf "_.-image" "_detach" (vla-get-name vl) "")
                )
                (
                 (and (eq (cdr (assoc 0 e)) "INSERT")
                      (vlax-property-available-p vl 'Path)
                 )
                 (vl-cmdf "_.-xref" "_detach" (vla-get-name vl) "")
                )
                (
                 (eq (cdr (assoc 0 e)) "DGNUNDERLAY")
    ;             (vla-delete vl)
                 (vl-catch-all-error-p (setq vl (vl-catch-all-apply 'vla-detach (list vl))))
                )
                (
                 (eq (cdr (assoc 0 e)) "DWFUNDERLAY")
    ;             (vla-delete vl)
                 (vl-catch-all-error-p (setq vl (vl-catch-all-apply 'vla-detach (list vl))))
                )
                (
                 (eq (cdr (assoc 0 e)) "PDFUNDERLAY")
    ;             (vla-delete vl)
                 (vl-catch-all-error-p (setq vl (vl-catch-all-apply 'vla-detach (list vl))))
                )
              )
           )
         )
          -1
        )
        (alert
          "No Xref file(s) or Image(s) or DWF(s) or DGN(s) or PDF(s) or OLE(s) found to detach !!"
        )
      )
      (vla-purgeall acdoc)
      (vla-regen acdoc acAllViewports)
      (if (ssget "_X" '((0 . "DGNUNDERLAY,DWFUNDERLAY,PDFUNDERLAY")) )
      (vl-cmdf "_.externalreferences")
      )
      (princ)
    )
    M.R. I tried, but no success...

  4. #4
    Member
    Join Date
    2005-08
    Posts
    8
    Login to Give a bone
    0

    Default Re: LISP to detach all XREF,PDF,IMAGE,ALL UNDERLAYS

    Manually...?? That is sorta self defeating...
    So lets say I have 30 files from an architect and each of them has half a dozen pdf's and half a dozen dwf attached. I have to sit there manually 360 times clicking detach? Frankly Autocad should already have a detach all option.

    Are you saying this is just not possible due to the dialog window?



    Quote Originally Posted by marko_ribar View Post
    Because some type of objects that are attached into dwg you can't detach without dialog box "externalreferences", you should manually detach them...

    Code:
    (defun c:Test (/ acdoc ss)
      ;; Tharwat 01. 07. 2011 - modified
      (vl-load-com)
      (setq acdoc (vla-get-activedocument
                    (vlax-get-acad-object)
                  )
      )
      (if (setq ss (ssget "_X" '((0 . "DGNUNDERLAY,DWFUNDERLAY,PDFUNDERLAY,OLE2FRAME,IMAGE,INSERT"))))
        (
         (lambda (i / sset vl e)
           (while
             (setq sset (ssname ss (setq i (1+ i))))
              (setq vl (vlax-ename->vla-object sset))
              (setq e (entget sset))
              (cond
                (
                 (eq (cdr (assoc 0 e)) "OLE2FRAME")
                 (vla-delete vl)
                )
                (
                 (eq (cdr (assoc 0 e)) "IMAGE")
                 (vl-cmdf "_.-image" "_detach" (vla-get-name vl) "")
                )
                (
                 (and (eq (cdr (assoc 0 e)) "INSERT")
                      (vlax-property-available-p vl 'Path)
                 )
                 (vl-cmdf "_.-xref" "_detach" (vla-get-name vl) "")
                )
                (
                 (eq (cdr (assoc 0 e)) "DGNUNDERLAY")
    ;             (vla-delete vl)
                 (vl-catch-all-error-p (setq vl (vl-catch-all-apply 'vla-detach (list vl))))
                )
                (
                 (eq (cdr (assoc 0 e)) "DWFUNDERLAY")
    ;             (vla-delete vl)
                 (vl-catch-all-error-p (setq vl (vl-catch-all-apply 'vla-detach (list vl))))
                )
                (
                 (eq (cdr (assoc 0 e)) "PDFUNDERLAY")
    ;             (vla-delete vl)
                 (vl-catch-all-error-p (setq vl (vl-catch-all-apply 'vla-detach (list vl))))
                )
              )
           )
         )
          -1
        )
        (alert
          "No Xref file(s) or Image(s) or DWF(s) or DGN(s) or PDF(s) or OLE(s) found to detach !!"
        )
      )
      (vla-purgeall acdoc)
      (vla-regen acdoc acAllViewports)
      (if (ssget "_X" '((0 . "DGNUNDERLAY,DWFUNDERLAY,PDFUNDERLAY")) )
      (vl-cmdf "_.externalreferences")
      )
      (princ)
    )
    M.R. I tried, but no success...

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: LISP to detach all XREF,PDF,IMAGE,ALL UNDERLAYS

    Quote Originally Posted by marko_ribar View Post
    Because some type of objects that are attached into dwg you can't detach without dialog box "externalreferences", you should manually detach them...
    I use vla-Detach all the time.

    Straight from Developer Documentation:


    Quote Originally Posted by Developer Documentation, Detach method

    Detach Method

    Detaches an external reference (xref) from a drawing.

    object.Detach()

    Object Block, The object this method applies to.

    Remarks

    Detaching an xref removes the xref from the current drawing. All copies of the xref are erased, and the xref definition is deleted. All xref-dependent symbol table information (such as layers and linetypes) is deleted from the current drawing.

    You cannot detach an xref that contains other xrefs.
    Last edited by RenderMan; 2011-07-01 at 09:10 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: LISP to detach all XREF,PDF,IMAGE,ALL UNDERLAYS

    Quote Originally Posted by sweichel View Post
    Frankly Autocad should already have a detach all option.
    ???

    Code:
    (command "._-xref" "detach" "*")
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  7. #7
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: LISP to detach all XREF,PDF,IMAGE,ALL UNDERLAYS

    Quote Originally Posted by marko_ribar View Post
    Because some type of objects that are attached into dwg you can't detach without dialog box "externalreferences", you should manually detach them...
    Agree only with DWF files , I did hard to get ride of it , but with no result

    And vla-detach function works only for blocks .

    Regards

  8. #8
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: LISP to detach all XREF,PDF,IMAGE,ALL UNDERLAYS

    Quote Originally Posted by tharwat View Post
    And vla-detach function works only for blocks .
    ... And what table (think "tblsearch") are External References a part of, Tharwat?

    (^^ See my DevDoc quote above ^^)
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  9. #9
    Member
    Join Date
    2005-08
    Posts
    8
    Login to Give a bone
    0

    Default Re: LISP to detach all XREF,PDF,IMAGE,ALL UNDERLAYS

    Quote Originally Posted by RenderMan View Post
    ???

    Code:
    (command "._-xref" "detach" "*")
    I meant detach all pdf's or dwf's. I already knew how to do it with xref dwg's and I learned one way with images... but where is autocad's detach all pdfs' and dwf's ? Doesn't exist.

  10. #10
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: LISP to detach all XREF,PDF,IMAGE,ALL UNDERLAYS

    If you don't need to detach all attached objects literally, you can always delete them... Never mind if their path is stored in dwg, for maybe some layers from dgnunderlay objects may remain and you must purge them also manually... My final suggestion is this :

    Code:
    (defun c:detachall (/ adoc msp)
      (vl-load-com)
      (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
      (setq msp (vla-get-modelspace adoc))
      (vlax-for ent	msp
        (vl-catch-all-apply 'vla-detach (list ent))
        (if
          (or
    	(= (vl-catch-all-error-p
    	     (vl-catch-all-apply 'vla-get-file (list ent))
    	   )
    	   nil
    	)
    	(= (vl-catch-all-error-p
    	     (vl-catch-all-apply 'vla-get-path (list ent))
    	   )
    	   nil
    	)
    	(= (vl-catch-all-error-p
    	     (vl-catch-all-apply 'vla-get-imagefile (list ent))
    	   )
    	   nil
    	)
    	(= (vla-get-objectname ent) "AcDbOle2Frame")
          )
           (vla-delete ent)
        )
      )
      (vl-cmdf "_.-xref" "D" "*")
      (vl-cmdf "_.-image" "D" "*")
      (if (ssget "_X" '((0 . "*UNDERLAY")))
        (vl-cmdf "_.externalreferences")
      )
      (princ)
    )
    M.R.
    P.S. For OLE and maybe other object types, add their property condition in :
    Code:
     
    (if (or cond1 cond2 ... condnew1 condnew2 ...) (vla-delete ent))

Page 1 of 3 123 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 2014-07-08, 02:28 PM
  2. .png image will not detach!
    By Openwheeler in forum AutoCAD Map 3D - General
    Replies: 3
    Last Post: 2010-03-10, 04:39 PM
  3. Unable to detach xref
    By michael.12445 in forum AutoCAD General
    Replies: 9
    Last Post: 2008-02-28, 01:19 PM
  4. Detach Image IF it exists
    By jpaulsen in forum AutoLISP
    Replies: 9
    Last Post: 2007-03-02, 11:01 PM
  5. Cannot detach a xref
    By kleenhippie in forum AutoCAD General
    Replies: 2
    Last Post: 2005-08-24, 04:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •