In need of Batch xref rename lisp routine

In need of Batch xref rename lisp routine

Anonymous
Not applicable
1,295 Views
5 Replies
Message 1 of 6

In need of Batch xref rename lisp routine

Anonymous
Not applicable

Hi,

I am in a need for a batch xref rename lisp routine at a minimum. At this time I am having to open each drawing and rename and repath the xrefs. This will take years.

I am not sure on how to make a lisp command, but I know how to load them into AutoCAD.

I have hundreds of drawings that need the xrefs renamed and/or repathed. I am looking for a batch lisp command that I could load a bunch of those drawings up at a time and run it.

The company has sold and of course they want the new name on all the title block xrefs.

I will need to rename the title block name most important. I can use the reference manager to repath the xrefs in batches.

The situation I have right now all the old xrefs go into an archive folder and the new title blocks are outside of that folder.

Old title blocks: K:\Engineering\EN Controlled\Drawing Files\AutoCAD Files\Title blocks\archive

New title blocks K:\Engineering\EN Controlled\Drawing Files\AutoCAD Files\Title blocks

Hopefully, this makes sense. Thank you for your help.

0 Likes
1,296 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant
0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks for replying.

Yes, for repathing my xrefs, but I can't rename in the reference manager that I know of.

0 Likes
Message 4 of 6

pendean
Community Legend
Community Legend
0 Likes
Message 5 of 6

Anonymous
Not applicable

That did not help me. I need to do one task. Batch rename xrefs in the drawings. I would like to rename xrefs in a 100 or more drawings at a time. I don't want to open each drawing. 

 

I have tried to use this lisp routine but it is not working for me (it won't load or do anything in autocad).

I don't know enough about lisp to debug to make it work. 

Any help is much appreicated.

 

;...............................................................................
;
; << Replace old xref files with a set of new xref files >>
;
; << Version 1.0 >>
;
; NOTE: If new xrefs are in a different folder, you must call out
; XrefPathChange.lsp from the code below.
;
;...............................................................................

(defun c:xrefnamechange (/ b bcol path)
(vl-load-com)
(setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
(foreach blk '(
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>> Enter all xref names below in this format >>>>>>
;>>>>> ("OldXrefName" . "NewXrefName") >>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

("Building 1 - Titleblock Xellia 24 x 36.dwg" . "Building 1 - Titleblock Sagent 24 x 36.dwg")
("Titleblock Xellia 24 x 36.dwg" . "Building 1 - Titleblock Sagent 24 x 36.dwg")

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
)
(if
(and
(not (vl-catch-all-error-p (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk))))))
(= (vla-get-isxref b) :vlax-true)
)
(progn (vla-put-name b (cdr blk))
(if (= (setq path (vl-filename-directory (vla-get-path b))) "")
(vla-put-path b (strcat (cdr blk) ".dwg"))
(vla-put-path b (strcat path "\\" (cdr blk) ".dwg"))
)
(vla-reload b)
)
)
)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>> XrefPathChange.lsp call out here. >>>>
;>>> Enter all xref paths to be changed in this format. >>>>
;>>> (xrefpathchange "c:\\Oldfolder\\oldfolder" "c:\\newfolder\\newfolder") >>>>
;>>> Note: Remove code if new xref path is unchanged. >>>>
;>>> Add ; infront of each line to block code. >>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

(xrefpathchange "K:\\Engineering\\EN Controlled\\Drawing Files\\AutoCAD Files\\Title blocks\\archive\\Building 1 - Titleblock Xellia 24 x 36.dwg" "K:\\Engineering\\EN Controlled\\Drawing Files\\AutoCAD Files\\Title blocks\\Building 1 - Titleblock Sagent 24 x 36.dwg")
(xrefpathchange "K:\\Engineering\\EN Controlled\\Drawing Files\\AutoCAD Files\\Title blocks\\archive\\Titleblock Xellia 24 x 36.dwg" "K:\\Engineering\\EN Controlled\\Drawing Files\\AutoCAD Files\\Title blocks\\Building 1 - Titleblock Sagent 24 x 36.dwg")

(XReload)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(princ)
);end of c:XrefNameChange

 

;...........................................................
;.... Xref Path Change sub routine by ronjonp ......
;...........................................................
(defun xrefpathchange (path1 path2 / newpath xrpath)
(vl-load-com)
(vlax-map-collection
(vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
(function
(lambda (x)
(if (= (vla-get-isxref x) :vlax-true)
(progn (setq xrpath (strcase (vlax-get x 'path) t)
path1 (strcase path1 t)
path2 (strcase path2 t)
)
(if (and (vl-string-search path1 xrpath)
(setq newpath (vl-string-subst path2 path1 xrpath))
(findfile newpath)
)
(if (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-path (list x newpath)))
(princ (strcat "\n**OLD path found but was not changed!\n" xrpath))
(princ (strcat "\n" newpath))
)
)
)
)
)
)
)
(princ)
); end of XrefPathChange


;.............................................................
;.... Xref Reload sub routine .......
;.............................................................
(defun XReload (/ cObj cName); Updated 2007-10-1: added error trap

(defun *error*(msg)
(setvar "modemacro" ".")
(setvar "cmdecho" 1)
(princ "\n...Reload xref terminated!!! ")
(princ)
); end of *error*

(setvar "modemacro" "Reloading loaded xrefs......please wait......")
(setvar "cmdecho" 0)
(setq cObj(tblnext "BLOCK" T))
(while cObj
(setq cName(cdr(assoc 2 cObj)))
(if
(and
(=(logand(cdr(assoc 70 cObj))32)32)
(=(logand(cdr(assoc 70 cObj))4)4)
); end and
(progn
(vl-cmdf "_.xref" "_unload" cName)
(vl-cmdf "_.xref" "_reload" cName)
); end progn
); wnd if
(setq cObj(tblnext "BLOCK"))
); end while
(setvar "modemacro" ".")
(setvar "cmdecho" 1)
(prompt "\n--- Xref change finished! ---")
(princ)
); end of XReload

0 Likes
Message 6 of 6

Anonymous
Not applicable

I am currently reading and trying to understand Lisp programming, this way I can make my own lisp to do what I need it to do and not bother anyone. 

This might be a better explanation of what I'm doing in each drawing.

 

Rename xref, repath xref, and rename layout tab process

  1. Open dwg
  2. Rename Xref from: Building 1 - Titleblock Xellia 24 x 36.dwg to Building 1 - Titleblock Sagent 24 x 36. Dwg                                              Titleblock Xellia 24 x 36 to Building 1 - Titleblock Sagent 24 x 36. Dwg
  3. Repath to new xref (can use reference manager for that if need be)
  4. Rename layout tab to Layout
  5. Save
  6. close    
0 Likes