slidster Posted March 16, 2012 Posted March 16, 2012 (edited) Hello, I'll start by mentioning I am not familiar with writing LISP expressions. Someone was nice enough to write this one for me. Unfortunately I can not quite get it to work and I was hoping someone here could help me out. My company updated the servers and along with that the file paths to our xrefs. Here is an example of the before and after: W:\06-5214 Dunhams Farm\000\Cad This same path is now: W:\HILLSBOROUGH\W_WINDOWS\06-5214 Dunhams Farm\000\Cad The goal is to have this LISP run on the opening of new drawings and automatically redirect the xref paths by inserting the red section above. When I execute the LISP that was written for me it is redirecting the XRef's but it is adding the folders to the path twice, like this: W:\HILLSBOROUGH\W_WINDOWS\HILLSBOROUGH\W_WINDOWS\06-5214 Dunhams Farm\000\Cad Is there a way to revise the LISP to only insert the folders once? I really appreciate any help. Here is the routine: ((lambda ( / activeDwgObj pathStr block-list xref-list xrefPathStr) (vl-load-com) (princ "\nUpdating XREF paths....") (setq activeDwgObj (vla-get-activedocument (vlax-get-acad-object)) pathStr (vlax-get activeDwgObj 'Path) ) (vlax-for for-item (vla-get-blocks activeDwgObj) (setq block-list (append block-list (list for-item))) ) (setq xref-list (vl-remove-if '(lambda (x) (= (vla-get-isxref x) :vlax-false)) block-list)) (foreach n xref-list (setq xrefPathStr (vlax-get n 'Path)) (if (eq (substr xrefpathstr 1 1) ".") (vlax-put n 'Path (strcat (vl-string-subst "W:\\HILLSBOROUGH\\W_WINDOWS" "W:" PathStr 0) (substr xrefPathStr 2))) (vlax-put n 'Path (vl-string-subst "W:\\HILLSBOROUGH\\W_WINDOWS" "W:" xrefPathStr 0)) ) ) )) Edited March 16, 2012 by slidster Quote
Lee Mac Posted March 16, 2012 Posted March 16, 2012 Welcome to the forum Please read the Code Posting Guidlines and edit your post. Quote
slidster Posted March 16, 2012 Author Posted March 16, 2012 Thanks guys, I think the post is now formatted properly. Quote
irneb Posted March 19, 2012 Posted March 19, 2012 Here's a quicky ... untested: ((lambda (/ path newPathPrefix) (vl-load-com) (setq newPathPrefix "W:\\HILLSBOROUGH\\W_WINDOWS") (vlax-for blk (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (if (and (= (vla-get-IsXRef blk) :vlax-true) (not (wcmatch (strcase (setq path (vla-get-Path blk))) (strcat newPathPrefix "*")))) (vl-catch-all-apply 'vla-put-Path (list blk (strcat newPathPrefix (substr path 2)))) ) ) ) ) I'm not exactly sure what's going wrong in the code you have. I can't see why it's adding the path twice - unless you're opening the drawing twice. Anyhow, mine is first checking if the required path is already added before it goes and adds it. So it should stop adding twice ... hopefully Also I'm using a "try" "apply" feature to not have it crash when using nested xrefs. Probably not needed, but then again you never know. Quote
slidster Posted March 20, 2012 Author Posted March 20, 2012 Irneb, Thanks so much for your help. We are so close!! When I use your code the path is being changed but it is leaving an extra colon, like this: W:\HILLSBOROUGH\W_WINDOWS:\06-5214 Dunhams Farm\000\Cad Any idea on how to get rid of this? Thanks again. -Steve Quote
Lee Mac Posted March 20, 2012 Posted March 20, 2012 Try this Steve, ( (lambda ( / p pr ) (setq pr "W:\\HILLSBOROUGH\\W_WINDOWS") (vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (if (and (eq (vla-get-isxref b) :vlax-true) (not (wcmatch (strcase (setq p (vla-get-path b))) (strcat pr "*"))) ) (vl-catch-all-apply 'vla-put-path (list b (strcat pr (substr p 3)))) ) ) ) ) (vl-load-com) Quote
slidster Posted March 20, 2012 Author Posted March 20, 2012 Lee, It works!! Thanks for your help. The only issue now is that the xref's need to be reloaded in order to display. In the Xref manager the path is correct but the status is "not found". I right click and reload and the xref displays. Can I add a second routine that will reload the xrefs automatically? I searched around the web and found some but none seemed to work. I may not be adding the routines correctly, I just pasted the text after what you have given me. As shown below: ( (lambda ( / p pr ) (vl-load-com) (setq pr "W:\\HILLSBOROUGH\\W_WINDOWS") (vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (if (and (eq (vla-get-isxref b) :vlax-true) (not (wcmatch (strcase (setq p (vla-get-path b))) (strcat pr "*"))) ) (vl-catch-all-apply 'vla-put-path (list b (strcat pr (substr p 3)))) ) ) ) ) (defun c:unreload(/ cObj cName) (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 (princ) ); end of c:unreload Quote
Lee Mac Posted March 20, 2012 Posted March 20, 2012 Maybe this? (untested) ( (lambda ( / p pr ) (setq pr "W:\\HILLSBOROUGH\\W_WINDOWS") (vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (if (and (eq (vla-get-isxref b) :vlax-true) (not (wcmatch (strcase (setq p (vla-get-path b))) (strcat pr "*"))) (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-path (list b (strcat pr (substr p 3)))))) ) (vla-reload b) ) ) ) ) (vl-load-com) Quote
slidster Posted March 20, 2012 Author Posted March 20, 2012 Thats it. You're my hero!!! Thanks to everyone for helping me out with this. It is greatly appreciated. Quote
Lee Mac Posted March 20, 2012 Posted March 20, 2012 You're very welcome Steve, I only had to tweak Irneb's code Quote
slidster Posted March 20, 2012 Author Posted March 20, 2012 OK, I know Im pushing my luck here. Is there an easy way to edit this to replace images as well as xrefs? Quote
Lee Mac Posted March 20, 2012 Posted March 20, 2012 OK, I know Im pushing my luck here. Is there an easy way to edit this to replace images as well as xrefs? Possible, but not an easy modification I'm afraid. Quote
irneb Posted March 21, 2012 Posted March 21, 2012 Sorry for my stupid little mistake earlier . Thanks Lee for correcting! Just a little question ... why go through all this trouble? There is a program which is installed with your ACad which can do this for you. In the Windows start menu, under your ACad installation, you should find something called "Reference Manager". You can open multiple DWGs and find-and-replace portions of their paths. This thing includes XRefs, Images, DWF Underlays, etc. It's very quick and can fix up multiple DWGs in one go. Quote
slidster Posted March 21, 2012 Author Posted March 21, 2012 When I started searching for a solution to this I did not even know the reference manager existed, someone on another forum told me about it. It does work quite well when you know which drawings you are trying to update. At our place we have job folders going back about 20 years, each with subfolders and more subfolders. To go through each one and fish out and update all the CAD files, knowing most will never need to be accessed again, seemed like a waste of time. My other concern is with inexperienced users. When they open up a file they may not even notice there was an xref attached, let alone understand how to use the reference manager. Fortunately for me there are folks like Lee and yourself willing to help me out. Thanks again. Quote
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.