­
 This function can be used if you have moved an xref to another location or if you both have renamed the xref as well as moved it to a new folder.

First argument is the old name
Second argument is the new name
Third argument is the path for the new xref
(XrefRename "XR_01-LIB A" "XR_201" "W:\\project\\1234\\")

This can be done in batch with our JTB SmartBatch or see our JTB FixRefs that can rename xrefs and much more. 

More Free AutoLISP and Visual LISP code snippets for AutoCAD


 Click here to download the code as a file.

 

(defun XrefRename (oldname newname newpath)
  (if (and (findfile (strcat newpath newname ".dwg"))
    (ssget "X" (list '(0 . "INSERT") (cons 2 oldname))))
    (progn
      ; rename the xref if it is found
      (command "rename" "b" oldname newname)
      ; change the path of the xref if it is found
     (command
       "-xref"
       "p"
       newname
       (strcat newpath newname)
     )
   )
  )
)
Have any questions? Contact us

­