How to batch bind multiple XREFs when some are Unloaded or Not Found?

How to batch bind multiple XREFs when some are Unloaded or Not Found?

yu85.info
Collaborator Collaborator
396 Views
7 Replies
Message 1 of 8

How to batch bind multiple XREFs when some are Unloaded or Not Found?

yu85.info
Collaborator
Collaborator

Hi everyone,

 

I’m trying to merge a large number of DWG drawings into one consolidated file, while preserving each drawing’s coordinates. My current workflow is:

 

1. Start with an empty DWG file.

 

 

2. Use XATTACH to insert many DWG files as external references.

 

 

3. Attempt to BIND all XREFs into the host drawing.

 

 

 

The issue: some of the XREFs contain nested references that no longer exist (e.g., old XREFs that are now Unloaded or Not Found). This prevents BIND from working and throws errors like “Cannot bind unresolved reference…”

 

I’m looking for one of the following:

 

A LISP or utility that can automatically detach or purge any UNLOADED or NOT FOUND XREFs (including nested ones), before I run BIND.

 

Or, an alternative method to bulk-merge many DWG files into a single DWG, while preserving world coordinates and without needing to manually clean each file.

 

 

Any suggestions, scripts, or best practices would be much appreciated.

 

Thanks in advance!

0 Likes
397 Views
7 Replies
  • xref
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor

This post should provide you with a solution to detach xrefs that are not found 

Solved: Reload XREFs, Detach unloaded AND "not found" XREFs - Autodesk Community

Then you can use something like Lee Macs Script Writer to apply to all dwgs in a folder

Script Writer | Lee Mac Programming


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 8

yu85.info
Collaborator
Collaborator

Thanks but I did not quite get your explanation.
I got this LISP that works
just need some how to make it work on multiple files

(defun C:Detachall (/ *error*
 
mip:layer-status-restore mip:layer-status-save
 
delete-xref-img-underlay delete-all-dict
 
)
 
(vl-load-com)
 
(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
0 Likes
Message 4 of 8

paullimapa
Mentor
Mentor

Assuming the lisp file you found is called detachall.lsp and it’s saved in a folder listed under Options>Files>Support File Search Path and Trusted Locations then when running Lee Macs Script Writer enter the following on the Script Line

_.open *file* (load”detachall.lsp”) (c:detachall) _.qsave _.close

Then select the folder containing all the dwgs to batch process

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 8

yu85.info
Collaborator
Collaborator

Thanks again. The script does work but it seems to be stuck for very long time not doing anything. When I run this LISP manually it works in a second

yu85info_0-1750071041992.png

 

0 Likes
Message 6 of 8

paullimapa
Mentor
Mentor

That’s odd. I wonder if one or more dwgs in the folder you selected may be causing this. To test make a test folder and only include a couple of dwgs to batch process and run Script Writer on that test folder. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 7 of 8

yu85.info
Collaborator
Collaborator

Thanks for your time. Your Lisp you gave me in your first reply works very good. Regarding the batch process I gave up the LISP and made a nice .NET app with a simple GUI. Works nicely. 

Thanks again for your help. 

0 Likes
Message 8 of 8

paullimapa
Mentor
Mentor

glad that worked out for you...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes