LISP to Change multiple Sheet Names

LISP to Change multiple Sheet Names

Bmaciejewski
Participant Participant
2,374 Views
7 Replies
Message 1 of 8

LISP to Change multiple Sheet Names

Bmaciejewski
Participant
Participant

Hi there, currently I work with drawings that could have up to 100 sheets and can get reused but mirrored or something changes in the part name. I've been trying to find a solution but is there a way if say my sheets started like

 

5L-1-xxx but i need to create a mirrored version now which would be 5R-1-xxx. Instead of going through every sheet is there a way to change the prefix on all of them at once? 

0 Likes
Accepted solutions (1)
2,375 Views
7 Replies
Replies (7)
Message 2 of 8

james_moore
Advocate
Advocate

If you're talking about attributes, use a global attribute change in a script, and apply the script to all the drawings. 

the format, of the command line sequence, is

-ATTEDIT

No, don't edit one at a time

No, don't select from the visible objects

block name filter (or leave at "*" for inserts of any block with attributes)

tag name filter (or leave at "*" for all attribute tag strings)

value filter (or leave at "*" for all attribute value strings)

current value

new value

 

SO... following that pattern...

Command sequence:

-ATTEDIT

N

N

*

*

*

5L-1-

5R-1-

 

You could get more specific by using the filters... the following sequence will only select from attribute values that start with 5L-1-.

-ATTEDIT

N

N

*

*

5L-1-*

5L-1-

5R-1-

 

It might be quicker to just open each drawing and use "find" to find and replace, which will work on both text and attributes.  However, if you're running ACE or another version of AutoCAD that includes a "drawing wide utilities" option that allows you to apply a script across all drawings, the combination of using ACAD script and AutoLISP methods is quickest in my experience.  You can combine the two languages within a script too... I think the below lines should do what you're asking, if applied to each drawing as a script.  Save those lines to a text file with a .scr extension, and simply drag it into your ACAD drawing.

 

-ATTEDIT

N

N

*

*

5L-1-*

5L-1-

5R-1-

(setq TEXTSTRINGS (ssget "X" '((1 . "5L-1-*"))))

(repeat (sslength TEXTSTRINGS)  (setq ONESTRING (car TEXTSTRINGS))  (vl-string-subst "5R-1-" "5L-1-" ONESTRING)  (setq TEXTSTRINGS (cdr TEXTSTRINGS)))

 

Note that the above can be in a script, but the line starting with "(repeat "  must NOT be broken in two to be loaded from within a script file.

0 Likes
Message 3 of 8

Bmaciejewski
Participant
Participant

Sample1.PNG

Im going to mess with what you just posted and see if that works, figured this might help too with what Im looking to do.

 

SAMPLE 2.PNG

As you can see im just going through and manually changing these. 

0 Likes
Message 4 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

THIS could help.

Message 5 of 8

Bmaciejewski
Participant
Participant

This worked exactly how i wanted it. Thank you!

Message 6 of 8

userlevel6
Advocate
Advocate

I see.  Changing tab names would be a different matter using LISP & script.  Would have to loop through the list of tabs, similar to the LISP statement I wrote to change found text strings, but the list of strings to change would have to be built differently.  I've used something like it for plotting before, but at home now & will have to look later to find the right statement to get that list.

0 Likes
Message 7 of 8

Bmaciejewski
Participant
Participant

Oh no worries, and I appreciate the help and looking at this. @ВeekeeCZ Was able to find something that was exactly what I needed. 

 

I guess in better terms I should of looked to see if there was a Find Replace code/addon for sheets but this Lisp worked perfectly. 

0 Likes
Message 8 of 8

vladimir_michl
Advisor
Advisor

If you need a more complex renaming scheme (like swapping parts of the names), you can use the RRename utility for renaming layouts, blocks, linetypes, views, etc. It is based on regular expressions. See:

CAD Forum - RENAME on steroids - complex renaming of AutoCAD objects.

 

Vladimir Michl, www.arkance-systems.cz - www.cadforum.cz

0 Likes