JeepMaster Posted July 27, 2009 Share Posted July 27, 2009 I've found a way to rename xrefs with this script and it works fine. It basically changes the old xref to a new xref. -rename b TBA0_old TBA0_new -xref p TBA0_new "C:\NEW XREF\TBA0_new.dwg" The problem is I have a lot of different xrefs thats changed and a lot of dwgs to repath. The floor plan of a 20 story building changed it's format. Level 0 changed from xxxFP00 to xxxFPP1, xxxFP01 to xxxFP00, xxxFP02 to xxxFP01... So basically everything is shifted one level, and I have a whole bunch of dwgs with different xrefs to fix. I could write a script to fix each level I guess, but it should be simple to make it into a lisp file, but I don't know how to go about this. Please help. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 27, 2009 Share Posted July 27, 2009 You might be able to use this to rename them: http://www.cadtutor.net/forum/showpost.php?p=240490&postcount=28 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 27, 2009 Share Posted July 27, 2009 Nice one Ron. I believe your code could be incorporated into a bit of ObjectDBX to use on a whole folder of drawings Lee Quote Link to comment Share on other sites More sharing options...
JeepMaster Posted July 27, 2009 Author Share Posted July 27, 2009 You might be able to use this to rename them: http://www.cadtutor.net/forum/showpost.php?p=240490&postcount=28 Ronjonp, Unless I'm reading it wrong, but it seems like that lisp only repath dwgs. I can use reference manager to do that. I can't seem to get it to work eitherway. I needed to rename xrefs. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 27, 2009 Share Posted July 27, 2009 You could use: (vla-put-Name <XrefObject> <Name>) But a duplicate xref definition would need to be created with the same name, as shown in this example with a block: http://www.cadtutor.net/forum/showpost.php?p=242147&postcount=24 Lee Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 28, 2009 Share Posted July 28, 2009 Here's a quickie that should do what you need. just add to the list of block names ("existname" . "newname") (defun c:blkrenamer (/ b bcol) (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (foreach blk '(("xxxFP00" . "xxxFPP1") ("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01")) (if (not (vl-catch-all-error-p (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk)))) ) ) (vla-put-name b (cdr blk)) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
JeepMaster Posted July 28, 2009 Author Share Posted July 28, 2009 Here's a quickie that should do what you need. just add to the list of block names ("existname" . "newname") (defun c:blkrenamer (/ b bcol) (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (foreach blk '(("xxxFP00" . "xxxFPP1") ("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01")) (if (not (vl-catch-all-error-p (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk)))) ) ) (vla-put-name b (cdr blk)) ) ) (princ) ) Thanks Ron, this one works great, but I still can't get the repath lisp to work. I don't think it will do as it changes the xref path. For my purpose, my xref path is actually unchanged, but the actual xref drawing is. Anyways, I've managed to modify your rename lisp and made it work for my purpose. But I need to make it as user friendly as possible so I can share it with my all my co-workers. How can I make the -xref command loop like the (foreach...) function? And some kind of error trap to move on to the next xref if this xref doesn't exist. Here's what I have so far. (defun c:Xrefchanger (/ b bcol) (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (foreach blk '( ;****************************************************** ;******* Enter xref names below in this format ****** ;******* ("OldXrefName" . "NewXrefName") ****** ;****************************************************** ("oldxref1" . "newxref1") ("oldxref2" . "newxref2") ;****************************************************** ) (if(not (vl-catch-all-error-p (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk)))) ) ) (vla-put-name b (cdr blk)) ) ) ;*********************************************************************** ;***** Enter new xerf name and full path below in this format ********* ;**** "NewXrefName" "c:\\new path\\NewXrefName.dwg" ********* ;*********************************************************************** (command "-xref" "p" "newxref1" "c:\\new xref\\newxref1.dwg") ;*********************************************************************** (princ) ) Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 28, 2009 Share Posted July 28, 2009 Try this one to rename and change the name of the dwg in the path. I did not test it heavily... It seems from doing this in the past that the results can only be viewed immediately using CLASSICXREF...when you reopen the drawing the changes should take effect. (defun c:blkrenamer (/ b bcol path) (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (foreach blk '(("xxxFP00" . "xxxFPP1") ("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01")) (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")) ) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
JeepMaster Posted July 28, 2009 Author Share Posted July 28, 2009 I'm getting: bad argument type: VLA-OBJECT nil Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 28, 2009 Share Posted July 28, 2009 Should be: (defun c:blkrenamer (/ b bcol path) (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (foreach blk '(("xxxFP00" . "xxxFPP1") ("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01")) (if (and (= (vla-get-isxref [b][color=Red]blk[/color][/b]) :vlax-true) (not (vl-catch-all-error-p (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk)))))) ) (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")) ) ) ) ) (princ) ) Me thinks Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 28, 2009 Share Posted July 28, 2009 I'm getting: bad argument type: VLA-OBJECT nil My bad. Give it a whirl now Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 28, 2009 Share Posted July 28, 2009 Should be: (defun c:blkrenamer (/ b bcol path) (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (foreach blk '(("xxxFP00" . "xxxFPP1") ("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01")) (if (and (= (vla-get-isxref [b][color=Red]blk[/color][/b]) :vlax-true) (not (vl-catch-all-error-p (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk)))))) ) (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")) ) ) ) ) (princ) ) Me thinks (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) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 28, 2009 Share Posted July 28, 2009 (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) ) Ahh, of course :oops: Quote Link to comment Share on other sites More sharing options...
JeepMaster Posted July 28, 2009 Author Share Posted July 28, 2009 Thanks Ron, It works now. I've added my other XRE.lsp on there so it will refresh all loaded xrefs right after it. This is what I have now. (defun c:blkrenamer (/ b bcol path) (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (foreach blk '(("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01") ) (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")) ) ) ) ) (c:XRE) (princ) ) (defun c:xre (/ cObj cName) (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--- Refreshed loaded Xrefs! ---") (princ) ); end of c:xre Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 28, 2009 Share Posted July 28, 2009 Thanks Ron,It works now. I've added my other XRE.lsp on there so it will refresh all loaded xrefs right after it. This is what I have now. (defun c:blkrenamer (/ b bcol path) (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (foreach blk '(("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01") ) (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")) ) ) ) ) (c:XRE) (princ) ) (defun c:xre (/ cObj cName) (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--- Refreshed loaded Xrefs! ---") (princ) ); end of c:xre You could add (vla-reload b) like so and it should reload without the need for the other lisp . Glad we got it sorted out....I'm gone fishing for the next 5 days so Lee will have to pick up from here (defun c:blkrenamer (/ b bcol path) (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (foreach blk '(("xxxFP00" . "xxxFPP1") ("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01")) (if (and (= (vla-get-isxref b) :vlax-true) (not (vl-catch-all-error-p (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk)))))) ) (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) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 29, 2009 Share Posted July 29, 2009 ...I'm gone fishing for the next 5 days so Lee will have to pick up from here... I'd be happy to Quote Link to comment Share on other sites More sharing options...
JeepMaster Posted July 29, 2009 Author Share Posted July 29, 2009 Thanks so much Ron, It works perfectly now. I know this will save a lot of people's time when some smarta$$ decides to change their floor plan name in the middle of the project. A few dwg is fine, but when you have over 80 dwgs to fix, then times that by 3 since it affects Mech, Elect, Struct....that's a lot of time wasted. Quote Link to comment Share on other sites More sharing options...
JeepMaster Posted July 29, 2009 Author Share Posted July 29, 2009 I'd be happy to Thanks Lee,It seems to work great now. Unless you want to improve it some more. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 29, 2009 Share Posted July 29, 2009 I'm glad it works for you... I doubt I could improve on a code posted by Ron... Quote Link to comment Share on other sites More sharing options...
wannabe Posted July 30, 2009 Share Posted July 30, 2009 Try this: Start --> Programs --> Autodesk --> AutoCAD 20xx --> Reference Manager I designed an application to cater for these needs and then discovered this Autodesk freebie so abandoned my plans. Hope this helps. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.