hi,
as I wrote in topic
http://www.theswamp.org/index.php?topic=15712.0here a demo lsp to manage renamed files and all xrefs quickly,
caution : path for dwg files is harcoded, thus you must modify
pathDwgs to test it
Because we do not have all the same needs, my purpose is simply to show a way and no to post a full ready solution for everyone.
it's a very simple solution
![smiley :-)](http://www.theswamp.org/Smileys/black/smiley.gif)
but it makes all I need about xrefs when I rename a bunch of files.
all questions are welcome,
thx to reply if you test it with something else then acad 2007.
About sample in zip:
there are 3 dwg using xrefs : _principal.dwg carre.dwg cercle.dwg
I rename them to : ARC__principal.dwg ARC_carre.dwg ARC_cercle.dwg thus all xrefs's path are brokenBruno Toniutti
;FUNCTION:
; purpose it's to show a simple way to manage renamed xrefs via a batch odbx process
; Thus user's interface is not a key point
;
;
;USE:
; (BATodbxXrefsRenameDemo listOldnameNewname) or (BATodbxXrefsRenameDemo nil)
; listOldnameNewname = '((Oldname1 Newname1)(Oldname2 Newname2)....)
; OldnameX = vl-filename-base
; NewnameX = [Autolisp path/]filename.dwg
; listOldnameNewname doesn't need to be a full list of substitutions,
; process will ask for xrefs's substitution missing
;
; sample 1:
; (BATodbxXrefsRenameDemo nil)
;
; sample 2:
; (setq lstA '(("carre" "ARC_carre.dwg")))
; (BATodbxXrefsRenameDemo lstA)
;
;PROGRAMMING:
; Bruno Toniutti
;
;VERSIONS:
; 1.070404 specific light release for TheSwamp.org
;
;NOTES:
; This software is provided "as is" without express or implied warranty.
; For display, acet-ui-status from express tools is used
; 1.070404 tested with MAP 3D 2007 and Win XP sp2
;-----------------------------------------------------------------------------------------------------
; error function
(defun errorFunction ()
(setq *error* saveError)
(acet-ui-status)
(if (and objBlock (not (vlax-object-released-p objBlock))) (vlax-release-object objBlock))
(if (and odbx (not (vlax-object-released-p odbx))) (vlax-release-object odbx))
(foreach x '(pathDwgs odbxSaveFlag file files odbx index oldFileName yetRedefine newFileName xrefsListGlobal saveError objBlock)
(set x nil)
)
(gc)
(princ)
)
(defun BATodbxXrefsRenameDemo (xrefsListGlobal / pathDwgs odbxSaveFlag file files odbx index oldFileName yetRedefine newFileName saveError objBlock)
; to modify: pathDwgs (to create your own manner to get a path or dwg files)
(setq pathDwgs "Z:/")
; variables set
(setq
saveError *error*
*error* errorFunction
index 0
)
; main
; to modify: files (to create your own manner to get a list of dwg files)
(if (setq files (vl-directory-files pathDwgs "*.dwg"))
(progn
(if (< (atoi (substr (getvar "ACADVER") 1 2)) 16)
(setq odbx (vlax-get-or-create-object "ObjectDBX.AxDbDocument"))
(setq odbx (vlax-get-or-create-object (strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2))))
)
; main loop
(foreach file files
(acet-ui-status (strcat "File : " (itoa (setq index (1+ index))) " on " (itoa (length files)) " files \n" file) "BATodbxXrefsRename is working...")
(if (vl-catch-all-error-p (vl-Catch-All-Apply '(lambda () (vla-open odbx (strcat pathDwgs file)))))
(alert (strcat "Odbx connection no available with file :\n" file))
(progn
(setq odbxSaveFlag nil)
(vlax-for objBlock (vla-get-blocks odbx)
(if (= (vlax-get objBlock 'IsXRef) -1)
(progn
(setq oldFileName (vl-filename-base (vla-get-path objBlock)))
(if (setq yetRedefine (vl-member-if '(lambda (x) (= (car x) oldFileName)) xrefsListGlobal))
(if (cadar yetRedefine)
(progn
(vla-put-path objBlock (cadar yetRedefine))
(setq odbxSaveFlag T)
)
)
(progn
(if (setq newFileName (getfiled (strcat "Select new xref to replace " oldFileName ".dwg") pathDwgs "dwg" 0))
(progn
; to modify : newFileName
; (if you don't want keep path, or simply change path, or attach a file that doesn't exist, or what you want etc...)
(vla-put-path objBlock newFileName)
(setq odbxSaveFlag T)
)
(alert (strcat "No file selected, " oldFileName ".dwg will be kept."))
)
(setq xrefsListGlobal (cons (list oldFileName newFileName) xrefsListGlobal))
)
)
)
)
)
(if odbxSaveFlag (vla-saveas odbx (strcat pathDwgs file)))
)
)
)
(acet-ui-status)
(vlax-release-object odbx)
)
(alert "None dwg found")
)
(princ)
)