PDA

View Full Version : rename an xref (not repath)


voigtmark
2007-10-19, 03:37 PM
I have been trying to get some code to work and have just about scrapped everything. A friend of mine posted and question and here is the code he recieved. Can this code be modified to rename an external reference? I would like to rename an xref from "???a1" (question marks representing different filenames with the "a1" as the last 2 characters of the file name) to "A1". The part that makes this frustrating is with the rename command you can use wildcards in the dialog but not at the command line. (if this was the case I would have been done a long time ago. Thanks in advance for the help.


(defun c:Test (/ ActDoc LoName)

(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vlax-for lo (vla-get-Layouts ActDoc)
(setq LoName (vla-get-Name lo))
(if
(and
(vl-string-search "8" LoName)
(vl-string-search "5" LoName)
(vl-string-search "11" LoName)
)
(vla-put-ActiveLayout ActDoc lo)
)
)
(princ)
)

Opie
2007-10-19, 04:11 PM
Do you want to rename the File Name or the Reference Name?

Also, that code does not rename anything. It just sets an certain layout tab active.

voigtmark
2007-10-19, 08:05 PM
Your correct, I didn't grab all of the code from my file. I am trying to rename the xref not the file name like you would do in reference manager by clicking the name and typing it in. Below is the code for renaming the layouts. I am not very familiar with the visual lisp coding. If this code is way off base let me know. I am grasping at straws at the moment.


(defun c:8LAYOUTFIX (/ ActDoc LoName)

(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vlax-for lo (vla-get-Layouts ActDoc)
(setq LoName (vla-get-Name lo))
(if
(and
(vl-string-search "8" LoName)
(vl-string-search "5" LoName)
(vl-string-search "11" LoName)
)
(vla-put-ActiveLayout ActDoc lo)
)
)

(command "zoom" "all")
(command "layout" "r" "" "8.5x11")

(princ)
)

T.Willey
2007-10-19, 08:59 PM
(defun c:Test (/ OldName)

(vlax-for blk (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(if
(and
(equal (vla-get-IsXref blk) :vlax-true)
(wcmatch (setq OldName (vla-get-Name blk)) "*a1")
)
(vla-put-Name blk (strcat (substr OldName 1 (- (strlen OldName) 2)) "A1"))
)
)
(princ)
)

voigtmark
2007-10-19, 09:55 PM
this functions but is not doing quite what I want it to. My xref name is "Sw01a1.dwg" (the "Sw01" is different on all projects. this designates building and floor) The routine appends the file name to "Sw01A1"(inserts the lowercase "a" with the uppercase "A".) I want to change the xref name to just "A1". thanks for the help I am a mile closer.

T.Willey
2007-10-19, 10:01 PM
this functions but is not doing quite what I want it to. My xref name is "Sw01a1.dwg" (the "Sw01" is different on all projects. this designates building and floor) The routine appends the file name to "Sw01A1"(inserts the lowercase "a" with the uppercase "A".) I want to change the xref name to just "A1". thanks for the help I am a mile closer.

Change
(vla-put-Name blk (strcat (substr OldName 1 (- (strlen OldName) 2)) "A1"))
to
(vla-put-Name blk "A1"))

voigtmark
2007-10-19, 10:13 PM
Can I make this ignore whether or not the letters in the xref name are upper or lower case? I didnt realize the "*a1" was case sensitive.

T.Willey
2007-10-19, 11:10 PM
Can I make this ignore whether or not the letters in the xref name are upper or lower case? I didnt realize the "*a1" was case sensitive.

You're killing me here. Next time you do it on your own, with us just answering questions instead of giving you a whole program, okay. :wink:

Change
(wcmatch (setq OldName (vla-get-Name blk)) "*a1")
to
(wcmatch (strcase (setq OldName (vla-get-Name blk))) "*A1")
You could even change it to
(wcmatch (strcase (vla-get-Name blk)) "*A1")
Since you don't need to keep the old xref name anymore.

voigtmark
2007-10-22, 02:11 PM
Sorry, didnt mean to become a bother. I went throught the ACAD help files (which sometimes are really not all that helpful). This forum is WAY better than the help files as thing get explained better here. I truly do appreciate your help.:smile:

Opie
2007-10-22, 03:15 PM
I have briefly looked into this, but since an XREF dwg is handled similarly to a block, doesn't the rename command handle this? I know the reference name in the External Reference Palette is not automatically updated.

Just a question. ;)

voigtmark
2007-10-22, 04:10 PM
If you enter "-rename" at the command line it will not accept wildcards. it will only accept the full block name. I am trying to do this because we have about 80 users that (some not all) will not follow the proper naming conventions of our xrefs. this directly relates to our layering and viewport structures of our construction doucuments.

Opie
2007-10-22, 05:39 PM
If you enter "-rename" at the command line it will not accept wildcards. it will only accept the full block name. I am trying to do this because we have about 80 users that (some not all) will not follow the proper naming conventions of our xrefs. this directly relates to our layering and viewport structures of our construction doucuments.
That's right. You mentioned that already. Sorry.

Maybe you could get a list of the XREFs and then with that list, provide the appropriate name(s) for the rename command.