Rename an xref that I do not know the name lisp Hello good evening

Rename an xref that I do not know the name lisp Hello good evening

Anonymous
Not applicable
1,146 Views
10 Replies
Message 1 of 11

Rename an xref that I do not know the name lisp Hello good evening

Anonymous
Not applicable

I need your help, I have been asked at work to change the names of the references in multiple files and I wanted to do it with a bath script but I have seen that they have different names, so the only thing I know is the file " dwg "to which it is referenced which is always the same, let's see if you can give me a little hand to do it in lisp and then execute that lisp with a script in each plane.

 

Greetings and thank you very much for your help

0 Likes
1,147 Views
10 Replies
Replies (10)
Message 2 of 11

pbejse
Mentor
Mentor

@Anonymous wrote:

.. so the only thing I know is the file " dwg "to which it is referenced which is always the same..


 

How is that again ? I'm not understanding that bit 🙂 We are talking about more than one xref in one file YES?

 

 

0 Likes
Message 3 of 11

hak_vz
Advisor
Advisor

@Anonymous  In other words, what you want to say is that you have multiple files that in xref have same files but those references were (or are not) renamed by users or are not named according some standard.

 

Usually reference name equals to file name. Since xrefs are special block object their name can be changed. For large set of drawings you can use batch file, but for smaller set of files this can be done by simply running a script inside each file.

Let suppose a scenario where you have CSV with desired xref name and referenced file name stored in CSV file. 

 

CSV record would be:

wanted reference name 1, file path or name1

wanted reference name 2, file path or name2

wanted reference name 3, file path or name3

 

We would first create a list of all files referenced inside whole file set to create CSV file with unique set of file names (if references are inside same directory) or file paths if not. YOu would edit that CSV according to above format , and then simple lisp file can be executed on all files to make changes in accordance to it.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 11

Anonymous
Not applicable

Thanks for helping me, the referenced file is called "Substation.dwg" but inside the file where that refx is inserted, some call it "Substation layout", "subestation", "Layout" and I want them all to be called the same, apart from that , I have another reference called "Format A3"

 

Greetings

 

0 Likes
Message 5 of 11

pbejse
Mentor
Mentor

@Anonymous wrote:

Thanks for helping me, the referenced file is called "Substation.dwg" but inside the file where that refx is inserted, some call it "Substation layout", "subestation", "Layout" and I want them all to be called the same, apart from that , I have another reference called "Format A3"

 


 

Substation.dwg will be "Substation"

Format A3.dwg ->  "Format A3"

In other words keep the name of the drawing file as Reference name

OR

You want a specific Reference name per Xref?

Substation.dwg --> preffered name "Substation Layout"

 

These questions are being asked as so there are no confusion @Anonymous 

 

 

 

0 Likes
Message 6 of 11

hak_vz
Advisor
Advisor

@pbejse   I have started working on code using Kean Walmsley's  batch-processing-autocad-drawings-from-lisp-without-sdi .  Attached code should be modified  (in comments) to enable generation of file list inside multiple directories and creation of list to change names of xref blocks. At the moment I'm flooded with work so if you can use this

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 7 of 11

pbejse
Mentor
Mentor

@hak_vz wrote:

so if you can use this

 


or --> Repair XREF Names from Autodesk AppStore, best of all, its FREE

 

 

 

Message 8 of 11

Shneuph
Collaborator
Collaborator

I'd have to look into it later, but I'm wondering if you can do this with "reference manager" which I think comes standard with newer releases of AutoCAD?

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
0 Likes
Message 9 of 11

hak_vz
Advisor
Advisor

Here is a lisp file that resets external reference names  to be  equal to its file name.

You can either run it at file load or inside batch

 

(defun c:resetXrefs nil (resetXrefs))	
(defun resetXrefs ( / getXblocks str_to_lst xblocks xref fname)

	(defun getXblocks ( / adoc name lst)
	  (vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
	  (if (equal (vla-get-IsXref block) :vlax-true)(setq lst (cons (vla-get-Name block) lst))))
	  lst
	)
	(defun str_to_lst (str del / len lst pos )
		(setq len (1+ (strlen del)))
		(while (setq pos (vl-string-search del str))
			(setq lst (cons (substr str 1 pos) lst)
				  str (substr str (+ pos len))
			)
		)
		(reverse (cons str lst))
	)
	
	(if (setq xblocks (getXblocks))
		(progn
			(foreach xname xblocks
				(setq xref (vla-item(vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) xname))
				(setq fname (last (str_to_lst (vlax-get xref 'Path) "\\")))
				(command "RENAME" "B" xname (substr  fname 1 (vl-string-position (ascii ".") fname)))
			)
			(princ "\nAll x-refs names were reset to its file name!")
		)
	)
	(princ "\nDone")
	(princ)
)

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 10 of 11

Anonymous
Not applicable

Thank you very much everyone for your answers, I will try to do what you have told me, to see if I can do it.

 

Pbejse, if I have an external reference that the name is always the same "Subestation.dwg. What happens is that inside the plane, each person has named it in a different way and I would like them to all have the same name" Subestation layout "

 

Greetings

0 Likes
Message 11 of 11

pbejse
Mentor
Mentor

@Anonymous wrote:

Pbejse, if I have an external reference that the name is always the same "Subestation.dwg. What happens is that inside the plane, each person has named it in a different way and I would like them to all have the same name" Subestation layout "


What you are wanting is to supply the preferred name, Do you have system for naming the reference? or just random name, if the latter then you need to "source" of list of drawing files and its preferred name, it can be an external file or a dialog that prompts the user for Search and Replace.

 

That will throw the Autodesk app link i posted out of the window then 🙂

 

0 Likes