PDA

View Full Version : LISP to detach all XREF,PDF,IMAGE,ALL UNDERLAYS



sweichel
2011-07-01, 02:24 PM
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.


(vl-cmdf "-Image" "D" "*")

and I found this in another thread.


(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.

Tharwat
2011-07-01, 03:54 PM
This may help you with it ..



(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

marko_ribar
2011-07-01, 07:46 PM
Because some type of objects that are attached into dwg you can't detach without dialog box "externalreferences", you should manually detach them...



(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... :(

sweichel
2011-07-01, 08:11 PM
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?




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



(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... :(

BlackBox
2011-07-01, 08:59 PM
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. :confused:

Straight from Developer Documentation:





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.

BlackBox
2011-07-01, 09:02 PM
Frankly Autocad should already have a detach all option.


???



(command "._-xref" "detach" "*")

Tharwat
2011-07-01, 09:03 PM
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

BlackBox
2011-07-01, 09:09 PM
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 ^^)

sweichel
2011-07-01, 10:11 PM
???



(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.

marko_ribar
2011-07-02, 03:00 PM
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 :



(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 :


(if (or cond1 cond2 ... condnew1 condnew2 ...) (vla-delete ent))

BlackBox
2011-07-02, 03:53 PM
Deleting an overlay does not remove the link to the source file. I'd provide you more but I'm on posting from iPhone.

BlackBox
2011-07-02, 06:47 PM
Deleting an overlay does not remove the link to the source file. I'd provide you more but I'm on posting from iPhone.

Now that I'm home, here's some additional information:




DWF underlays can be detached from a drawing file.

You can detach DWF underlays that are no longer needed in a drawing. When you detach a DWF underlay, all instances of the underlay are removed from the drawing, the underlay definition is purged, and the linking path to the DWF file is removed.

Note
Erasing an individual instance of a DWF underlay is not the same as detaching it. A DWF underlay must be detached to remove the link from your drawing to the DWF file


Source (http://www.kxcad.net/autodesk/autocad/AutoCAD_2008_Users_Guide/WS1a9193826455f5ffa23ce210c4a30acaf-5b7d.htm)

marko_ribar
2011-07-02, 08:08 PM
Just click on Procedure - same link as you posted, and you'll see that there is no other way to detach underlay objects then through palette "externalreferences"... All I wanted is to try to help (OP has hundreds of dwg files to revise, so without other way to detach - through routine, maybe the best way is to use what can be done, and that is to delete them)... The link to the underlay objects will remain, but he'll be able to see objects that are unlinked entities of dwg...

M.R.

marko_ribar
2011-07-02, 11:18 PM
This routine will do the trick, but it overwrites current dwg with new dwg without all underlays... Before using, it is strongly recommended that you make copy of all directories with all dwg files so that originals remain unchanged...



(defun c:detachall (/ adoc msp dwgname dwgscr scrf)
(vl-load-com)
(setq adoc (vla-get-activedocument (vlax-get-acad-object)))
(setq msp (vla-get-modelspace adoc))
(setq dwgname (vla-get-fullname 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")
)
(vl-cmdf "_.-wblock" dwgname "Y" "*")
(setq dwgscr (strcat (vl-string-right-trim "dwg" dwgname) "scr"))
(setq scrf (open dwgscr "w"))
(princ "close" scrf)
(princ "\n" scrf)
(princ "Y" scrf)
(princ "\n" scrf)
(princ "open" scrf)
(princ "\n" scrf)
(princ dwgname scrf)
(princ "\n" scrf)
(princ "shell" scrf)
(princ "\n" scrf)
(princ (strcat "erase " dwgscr) scrf)
(princ "\n" scrf)
(close scrf)
(vl-cmdf "script" dwgscr)
(princ)
)


M.R.

BlackBox
2011-07-03, 02:54 AM
Hey, I'm not the one with this issue. I'm simply trying to provide accurate information on which a solid decision can be made. If half-right procedures works for you and or the OP, who am I to judge. That just wouldn't fly in my office.

Good luck with that. :wink:

marko_ribar
2011-07-03, 08:16 AM
Here is how you can quickly revise whole directory with *.dwg files in it...

Make sure you made copy of whole directory, for files in it will be overwritten...

Add this line to your acaddoc.lsp



(load "revise.lsp")


copy this file - code (revise.lsp) into ACAD Support directory...



(defun c:revise (/ adoc msp dwgname)
(vl-load-com)
(setq adoc (vla-get-activedocument (vlax-get-acad-object)))
(setq msp (vla-get-modelspace adoc))
(setq dwgname (vla-get-fullname 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 "_.-wblock" dwgname "Y" "*")
(princ)
)


Start AutoCAD...
Load this file - code (reviseall.lsp) and start it



(defun c:reviseall ( / pthfn pth filens fn fnlst)
(setq pthfn (getfiled "Select one file in Folder where DWG files for revision are stored" "/" "dwg" 16))
(setq pth (substr pthfn 1 (vl-string-position (ascii "\\") pthfn 0 T)))
(if (setq filens (vl-directory-files pth "*.dwg"))
(foreach f filens
(progn (setq fn (strcat pth "\\" f)) (setq fnlst (cons fn fnlst)))
)
)
(setq revscr (open "c:/revscr.scr" "w"))
(foreach fn fnlst
(princ "open" revscr)
(princ "\n" revscr)
(princ fn revscr)
(princ "\n" revscr)
(princ "revise" revscr)
(princ "\n" revscr)
(princ "close" revscr)
(princ "\n" revscr)
(princ "Y" revscr)
(princ "\n" revscr)
)
(princ "open" revscr)
(princ "\n" revscr)
(princ pthfn revscr)
(princ "\n" revscr)
(princ "shell" revscr)
(princ "\n" revscr)
(princ "erase c:\\revscr.scr" revscr)
(princ "\n" revscr)
(close revscr)
(vl-cmdf "script" "c:/revscr.scr")
(princ)
)


After execution of routine, your files in selected directory will be without any underlays attached... You can check this by starting "XREF" command and you'll see that dialog box is now empty...

Regards,
M.R. :) :beer:

Opie
2011-07-03, 09:09 PM
I would suggest looking into the various dictionaries to see if there is something in there that may relate to this topic. Autodesk has added many new features into AutoCAD via dictionaries.

azarko
2011-07-04, 09:32 AM
My variant


(defun C:Detachall (/ *error*
mip:layer-status-restore mip:layer-status-save
delete-xref-img-underlay delete-all-dict
)
(defun *error* (msg)
(mip:layer-status-restore)
(princ msg)
(princ)
) ;_ end of defun
(defun mip:layer-status-restore ()
(foreach item *PD_LAYER_LST*
(if (not (vlax-erased-p (car item)))
(vl-catch-all-apply
'(lambda ()
(vla-put-lock (car item) (cdr (assoc "lock" (cdr item))))
(vla-put-freeze
(car item)
(cdr (assoc "freeze" (cdr item)))
) ;_ end of vla-put-freeze
) ;_ end of lambda
) ;_ end of vl-catch-all-apply
) ;_ end of if
) ;_ end of foreach
(setq *PD_LAYER_LST* nil)
) ;_ end of defun

(defun mip:layer-status-save ()
(setq *PD_LAYER_LST* nil)
(vlax-for item (vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
) ;_ end of vla-get-layers
(setq *PD_LAYER_LST*
(cons (list item
(cons "freeze" (vla-get-freeze item))
(cons "lock" (vla-get-lock item))
) ;_ end of cons
*PD_LAYER_LST*
) ;_ end of cons
) ;_ end of setq
(vla-put-lock item :vlax-false)
(if (= (vla-get-freeze item) :vlax-true)
(vl-catch-all-apply
'(lambda () (vla-put-freeze item :vlax-false))
) ;_ end of vl-catch-all-apply
) ;_ end of if
) ;_ end of vlax-for
) ;_ end of defun

(defun delete-xref-img-underlay (/ count txt)
(mip:layer-status-save)
(vlax-for Blk (vla-get-Blocks
(vla-get-activedocument (vlax-get-acad-object))
) ;_ end of vla-get-Blocks
(if (and (= (vla-get-IsXref Blk) :vlax-false)
(not (wcmatch (vla-get-name Blk) "*|*"))
) ;_ end of and
(progn
(setq count 0
txt (strcat " Erase Xref and Underlay in "
(vla-get-name Blk)
) ;_ end of strcat
) ;_ end of setq
(grtext -1 txt)
(vlax-for Obj Blk
(setq count (1+ count))
(if (zerop (rem count 10))
(grtext -1 (strcat txt " : " (itoa count)))
) ;_ end of if
(if
(and (vlax-write-enabled-p Obj)
(or
(and ;_ XREF
(= (vla-get-ObjectName obj) "AcDbBlockReference")
(vlax-property-available-p Obj "Path")
) ;_ end of and
(and ;_ UNDERLAY
(wcmatch (vla-get-ObjectName obj) "*Reference")
(vlax-property-available-p Obj "UnderlayName")
) ;_ end of and
(= (vla-get-ObjectName obj) "AcDbRasterImage") ;_ IMAGE
) ;_ end of or
) ;_ end of and
(VL-CATCH-ALL-APPLY 'vla-Delete (list Obj))
) ;_ end of if
) ;_ end of vlax-for
) ;_ end of progn
) ;_ end of if
) ;_ end of vlax-for
(mip:layer-status-restore)
) ;_ end of defun
(defun delete-all-dict (dict)
;;; dict - dict name (like "ACAD_IMAGE_DICT", "ACAD_PDFDEFINITIONS" ... )
(vl-catch-all-apply
'(lambda ()
(vlax-map-Collection
(vla-item
(vla-get-dictionaries
(vla-get-activedocument (vlax-get-acad-object))
) ;_ end of vla-get-dictionaries
dict ;_ "ACAD_IMAGE_DICT"
) ;_ end of vla-Item
'vla-delete
) ;_ end of vlax-map-Collection
) ;_ end of lambda
) ;_ end of vl-catch-all-apply
) ;_ end of defun

(vl-load-com)
(delete-xref-img-underlay)
(command "_-xref" "_d" "*")
(while (> (getvar "CMDACTIVE") 0) (command))
(mapcar 'delete-all-dict
(list "ACAD_IMAGE_DICT"
"ACAD_PDFDEFINITIONS"
"ACAD_DWFDEFINITIONS"
"ACAD_DGNDEFINITIONS"
) ;_ end of list
) ;_ end of mapcar
(command "_.regenall")
(command "_.externalreferences")
(princ)
) ;_ end of defun

greg.battin
2011-07-04, 01:02 PM
My variant


(defun C:Detachall (/ *error*
mip:layer-status-restore mip:layer-status-save
delete-xref-img-underlay delete-all-dict
)
(defun *error* (msg)
(mip:layer-status-restore)
(princ msg)
(princ)
) ;_ end of defun
(defun mip:layer-status-restore ()
(foreach item *PD_LAYER_LST*
(if (not (vlax-erased-p (car item)))
(vl-catch-all-apply
'(lambda ()
(vla-put-lock (car item) (cdr (assoc "lock" (cdr item))))
(vla-put-freeze
(car item)
(cdr (assoc "freeze" (cdr item)))
) ;_ end of vla-put-freeze
) ;_ end of lambda
) ;_ end of vl-catch-all-apply
) ;_ end of if
) ;_ end of foreach
(setq *PD_LAYER_LST* nil)
) ;_ end of defun

(defun mip:layer-status-save ()
(setq *PD_LAYER_LST* nil)
(vlax-for item (vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
) ;_ end of vla-get-layers
(setq *PD_LAYER_LST*
(cons (list item
(cons "freeze" (vla-get-freeze item))
(cons "lock" (vla-get-lock item))
) ;_ end of cons
*PD_LAYER_LST*
) ;_ end of cons
) ;_ end of setq
(vla-put-lock item :vlax-false)
(if (= (vla-get-freeze item) :vlax-true)
(vl-catch-all-apply
'(lambda () (vla-put-freeze item :vlax-false))
) ;_ end of vl-catch-all-apply
) ;_ end of if
) ;_ end of vlax-for
) ;_ end of defun

(defun delete-xref-img-underlay (/ count txt)
(mip:layer-status-save)
(vlax-for Blk (vla-get-Blocks
(vla-get-activedocument (vlax-get-acad-object))
) ;_ end of vla-get-Blocks
(if (and (= (vla-get-IsXref Blk) :vlax-false)
(not (wcmatch (vla-get-name Blk) "*|*"))
) ;_ end of and
(progn
(setq count 0
txt (strcat " Erase Xref and Underlay in "
(vla-get-name Blk)
) ;_ end of strcat
) ;_ end of setq
(grtext -1 txt)
(vlax-for Obj Blk
(setq count (1+ count))
(if (zerop (rem count 10))
(grtext -1 (strcat txt " : " (itoa count)))
) ;_ end of if
(if
(and (vlax-write-enabled-p Obj)
(or
(and ;_ XREF
(= (vla-get-ObjectName obj) "AcDbBlockReference")
(vlax-property-available-p Obj "Path")
) ;_ end of and
(and ;_ UNDERLAY
(wcmatch (vla-get-ObjectName obj) "*Reference")
(vlax-property-available-p Obj "UnderlayName")
) ;_ end of and
(= (vla-get-ObjectName obj) "AcDbRasterImage") ;_ IMAGE
) ;_ end of or
) ;_ end of and
(VL-CATCH-ALL-APPLY 'vla-Delete (list Obj))
) ;_ end of if
) ;_ end of vlax-for
) ;_ end of progn
) ;_ end of if
) ;_ end of vlax-for
(mip:layer-status-restore)
) ;_ end of defun
(defun delete-all-dict (dict)
;;; dict - dict name (like "ACAD_IMAGE_DICT", "ACAD_PDFDEFINITIONS" ... )
(vl-catch-all-apply
'(lambda ()
(vlax-map-Collection
(vla-item
(vla-get-dictionaries
(vla-get-activedocument (vlax-get-acad-object))
) ;_ end of vla-get-dictionaries
dict ;_ "ACAD_IMAGE_DICT"
) ;_ end of vla-Item
'vla-delete
) ;_ end of vlax-map-Collection
) ;_ end of lambda
) ;_ end of vl-catch-all-apply
) ;_ end of defun

(vl-load-com)
(delete-xref-img-underlay)
(command "_-xref" "_d" "*")
(while (> (getvar "CMDACTIVE") 0) (command))
(mapcar 'delete-all-dict
(list "ACAD_IMAGE_DICT"
"ACAD_PDFDEFINITIONS"
"ACAD_DWFDEFINITIONS"
"ACAD_DGNDEFINITIONS"
) ;_ end of list
) ;_ end of mapcar
(command "_.regenall")
(command "_.externalreferences")
(princ)
) ;_ end of defun


azarko,
this works beautifully.
thanks
~Greg

marko_ribar
2011-07-04, 01:20 PM
After, attaching *.dgn, and then detaching it either using XREF dialog box, or azarko code, I still have layers definitions of unreferenced *.dgn only visible through "PURGE" command... It is impossible to delete them in same session with (command "purge" "a" "*" "n")... Only when I save this, empty of dgn, dwg file, close it and reopen, then I loose this definitions... My variant with command wblock, close and reopen, seems to does just that what is needful for getting rid of these unreferenced layers...

M.R.
See attached *.zip and check what I meant...

marko_ribar
2011-07-04, 06:40 PM
Much more simplified, based on dictionary names definitions :

* dictionary names :


(defun c:dict ( / dictcoll dictlst)
(vl-load-com)
(setq dictcoll (vla-get-dictionaries (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for di dictcoll
(setq dictlst (cons (vl-catch-all-apply 'vla-get-name (list di)) dictlst))
)
(setq dictlst (reverse dictlst))
(princ dictlst)
(textscr)
(princ)
)


* detachall lsp - simplified :


(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)
)


M.R.
P.S. After detachall.lsp, dwg has to be saved and reopened in order to get rid of dgn unreferenced layers stored in purge definitions...
:-)

sweichel
2011-07-05, 02:56 PM
Much more simplified, based on dictionary names definitions :

* dictionary names :


(defun c:dict ( / dictcoll dictlst)
(vl-load-com)
(setq dictcoll (vla-get-dictionaries (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for di dictcoll
(setq dictlst (cons (vl-catch-all-apply 'vla-get-name (list di)) dictlst))
)
(setq dictlst (reverse dictlst))
(princ dictlst)
(textscr)
(princ)
)


* detachall lsp - simplified :


(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)
)


M.R.
P.S. After detachall.lsp, dwg has to be saved and reopened in order to get rid of dgn unreferenced layers stored in purge definitions...
:-)

Wow.. Fantastic Marko!!
Thank you very much..