Jump to content

Replace old xref files with a set of new xref files


SimonC

Recommended Posts

Hi Good Afternoon, evening, morning,

 

I am looking for any assistance possible, as from the title i am looking at some kind of Lisp code that will change the X-Ref file name from 'x' to 'y' for multiple x-refs on multiple drawings.

 

I have found some information that pointed to a thread back in 2010, instead of copying the code into this thread i have attached the link below

 

http://www.cadtutor.net/forum/archive/index.php/t-38673.html

 

I would like someone to confirm if the LISP code that is metioned in the above thread worked and if someone could please explain how i would go about loading it into my computer and autocad softaware.

 

Case history.....

 

Our office in Hamburg has a huge number of x-refs (3000) that have been created and we now wish to update the x-ref file name from a German based accronym to a universal accronym for our global offices. Is there a way that when we open an existing drawing containing x-refs that the Lisp function would rename the x-refs to the new x-ref file name?

 

once we have renamed the x-refs we are lookling to relocate them on an international file server for all offices to use, i belive that reference manager can be used for this, its the x-ref file name renaming that has me stumped

 

I would appreciate any assistance where ever possible....

 

Many Thanks

 

 

Kind Regards

 

Simon

Link to comment
Share on other sites

...if someone could please explain how i would go about loading it into my computer and autocad softaware.

 

After reading the links you provided, I believe the code will work for your use with some minor editing.

 

To load the code do the following:

-Save the file into a common directory (C:\_CADsetup\LiSP)

-Type APPLOAD into the command line and proceed to locate the file in the directory you initially save it.

-Add the file to the Startup Suite (briefcase) via drag-n-drop

-Click CLOSE button

 

To initiate the code/command:

-Type in the command alias provided within the code shown as red (defun c:xrefnamechange (/ b bcol path)

-Follow any prompts (if any)

Link to comment
Share on other sites

After reading the links you provided, I believe the code will work for your use with some minor editing.

 

To load the code do the following:

-Save the file into a common directory (C:\_CADsetup\LiSP)

-Type APPLOAD into the command line and proceed to locate the file in the directory you initially save it.

-Add the file to the Startup Suite (briefcase) via drag-n-drop

-Click CLOSE button

 

To initiate the code/command:

-Type in the command alias provided within the code shown as red (defun c:xrefnamechange (/ b bcol path)

-Follow any prompts (if any)

 

Hi David,

 

I changed the code as recommended in the code text to reflect the old and new x-ref names and folder locations:

 

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

;>>>>> Enter all xref names below in this format >>>>>>

;>>>>> ("OldXrefName" . "NewXrefName") >>>>>>

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

("GL" . "EARTHSymbol")

("S" . "Shield")

("VERT4992" . "RS422")

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

And

 

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

;>>> 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 "Z:\\CADE\\SYM\\A" "S:\\AutoCAD Customisation\\Working")

(xrefpathchange "Z:\\CADE\\SYM\\A" "S:\\AutoCAD Customisation\\Working")

(xrefpathchange "Z:\\CADE\\SYM\\SONST" "S:\\AutoCAD Customisation\\Working")

 

i followed your setup step by step, however when i inputed the code command xrefnamechange i got the following error message in the command box

 

Command: xrefnamechange

; error: Automation Error. File access error

Command:

As a beginner to all this i am going to take a stab in the dark and question the use of double \\ in the (xrefpathchange "Z:\\CADE\\SYM\\A" "S:\\AutoCAD Customisation\\Working") part of the code could this be the reason?

If you have any other sugestions or advice it would be greatly appreciated

Many Thanks

Simon

 

 

Link to comment
Share on other sites

I'm not the best person to answer your question but in case nobody else comes along I'll do my best.

 

The double backslash is correct. LISP interprets a backslash as "something special follows, forget you saw me". Therefore you need two backslashes to send one (IYSWIM).

 

a FILE ACCESS ERROR suggests a file cannot be read or writen. I'm not sure if it would make a difference but are the XREFs available in both new & old folders?

Link to comment
Share on other sites

Hi, Thank you for the promt reply,

 

I have just checked and i do have read write access to both folders, as for the second part of you reply..... No, the X-Refs are only avaialble in the source directory Z:\\CADE\\SYM\\A

the destination directory S:\\AutoCAD Customisation\\Working is empty, should i copy the "original named" X-Ref into the destination folder whereby the LISP function will then re-Name it to its "new name"?

 

Many Thanks

 

Regards

 

Simon

Link to comment
Share on other sites

Hi,

 

Tried that and still no joy,.... if i were to break the code and just use the X-Ref rename part of the code in Green (half of the code) .... How, where and how do i halt the code sucessfully?

 

;................................................. ..............................

;

; >

;

; >

;

; 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") >>>>>>

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 

("X-TEST-1a" . "X-TEST-1b")

("X-TEST-2a" . "X-TEST-2b")

("X-TEST-3a" . "X-TEST-3b")

 

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

)

(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 "c:\\AutoCAD Customisation" "c:\\AutoCAD Customisation\\Working")

(xrefpathchange "c:\\AutoCAD Customisation" "c:\\AutoCAD Customisation\\Working")

(xrefpathchange "c:\\AutoCAD Customisation" "c:\\AutoCAD Customisation\\Working")

 

(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

Link to comment
Share on other sites

Out of my comfort zone now but if you run the VLISP editor you can set break points or step through your code. Hopefully somebody who knows what they are talking about will be along soon.

 

On another subject, please use code tags around your code which will get rid of the :( faces and will also stop a moderator telling you to do so.

Link to comment
Share on other sites

sorry ive tried twice now to turn off the smiles and cant ...... but i theink you may get what i mean : x and : (

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...