Here's one I wrote last year to address the old R14 method of naming LFN xrefs. It should do what you want.
Jeff
;| Routine to find any xref's in the drawing and if they are in the same directory as the drawing, strip the path down to just the xref'ed drawing name. If the xref insert name does not match the actual drawing name (ala R14 rename to XREF1, XREF2, etc.) change it to match. Written by Jeff Mishler July 3, 2003 Removed (commeted out) path stripping, 7/7/03 |;
(defun C:XR2 (/ *ACAD* *BLOCKS* *DOC* BLK BLKNAME
BLKPATH DWGPATH SS XENT XREFDBASE)
(vl-load-com)
(or *acad* (setq *acad* (vlax-get-acad-object)))
(or *doc* (setq *doc* (vla-get-activedocument *acad*))) (setq *blocks* (vla-get-blocks *doc*)) (setq dwgPath (vla-get-path *doc*))
(vlax-for x *blocks*
(if (= (vla-get-isxref x) :vlax-true)
(progn
(if (setq ss
(ssget "x"
(list (cons 0 "INSERT")
(cons 2 (vla-get-name x)))
)
)
(progn
(setq blk (vlax-ename->vla-object (ssname ss 0)))
(setq xEnt x)
(blk_fix blk)
(if (setq xrefDBase (vla-get-xrefdatabase x))
(vlax-for xx (vla-get-blocks xrefDBase)
(if (= (vla-get-isXref xx) :vlax-true)
(progn
(setq xEnt xx)
(vlax-for xxx (vla-get-modelspace xrefDBase)
(if
(and
(= (vla-get-objectname xxx) "AcDbBlockReference")
(= (vla-get-name xxx)(vla-get-name xEnt))
)
(blk_fix xxx)
)
)
)
)
)
)
)
)
)
)
)
(princ)
)
(defun blk_fix (blk / )
(setq blkname (vla-get-name blk))
(setq blkpath (vla-get-path blk))
;;; (if (wcmatch (strcat (strcase blkpath))
;;; (strcat (strcase dwgpath) "*")
;;; )
;;; (vla-put-path
;;; blk
;;; (while (wcmatch blkpath "*\\*")
;;; (setq blkpath (substr blkpath 2))
;;; )
;;; )
;;; )
(while (wcmatch blkpath "*\\*")
(setq blkpath (substr blkpath 2))
)
(while (wcmatch blkpath "*.*")
(setq blkpath (substr blkpath 1 (1- (strlen blkpath)))) ) (if (not (= blkname blkpath)) (vla-put-name xEnt blkpath) )
)
akdrafter said:
Hello Again,
If I have some xrefs that have had their "Reference Name" renamed, is
there an easy way of renaming the xref back to the original xref (file)
name?