Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

multiple layout rename

5 REPLIES 5
Reply
Message 1 of 6
Anonymous
394 Views, 5 Replies

multiple layout rename

I have several layout tabs (eg. named :- 2777-0-NW-E01, 2777-0-NE-E01, 2777-0-SW-E01, 2777-0-SE-E01) and I would like to replace the E01 with E02. Is there a lisp program similar to the find and replace function that could rename mutliple layouts.

Thanks in advance
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: Anonymous

You can try the following:

(defun renlayout (old-str new-str / ll n new_n)
(setq ll (layoutlist))
(foreach n ll
(setq new_n (vl-string-subst new-str old-str n))
(command "_.-layout" "_r" n new_n)
) ;_ end of foreach
) ;_ end of defun

old-str is the old string eg E01 and new-str is the new string eg E02

Angeliki

Message 3 of 6
Anonymous
in reply to: Anonymous

cadop_1_uk@yahoo.co.uk wrote:
> I have several layout tabs (eg. named :- 2777-0-NW-E01, 2777-0-NE-E01,
> 2777-0-SW-E01, 2777-0-SE-E01) and I would like to replace the E01 with E02. Is
> there a lisp program similar to the find and replace function that could rename
> mutliple layouts. Thanks in advance

Try this:

(vl-load-com)
(defun C:RenLay ( / n x)
(setq n 1)
(vlax-for x (vla-get-Layouts
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
(if (not (eq (strcase (vla-get-name x)) "MODEL"))
(vla-put-Name x
(vl-string-subst "E02" "E01"
(vla-get-name x)
)
)
)
(setq n (1+ n))
)
(princ)
)


--
R.K. McSwain
http://rkmcswain.blogspot.com
Message 4 of 6
Anonymous
in reply to: Anonymous

aanast - thanks for that, I got the error message :- too few aruments, I still like to see it work


R.K. McSwain - thanks for that, that worked.
Message 5 of 6
Anonymous
in reply to: Anonymous

You got the message "too few arguments", because you tried to call it as a command. I have made it so as to be used as a function. That means you have to write a call like the following: (renlayout "E01" E02") You can also invoke it from your own lisp code. I think it is better to have it as a function, beacuse you can pass different values as arguments. I saw R.K McSwain's code and I have now included some changes to this function. It doesn't touch Model Layout and checks the name of the Layout if it matches the first string. Angeliki
Message 6 of 6
Anonymous
in reply to: Anonymous

Sorry,

I forgot to send the revised code with the previous message.


(defun renlayout (old-str new-str / ll n new_n)
(command "_.undo" "_be")
(setq ll (layoutlist))
(foreach n ll
(cond
((= (strcase n) "MODEL"))
((wcmatch n (strcat "*" old-str "*"))
(setq new_n (vl-string-subst new-str old-str n))
(command "_.-layout" "_r" n new_n)
)
) ;_ end of foreach
) ;_ end of foreach
(command "_.undo" "_e")
) ;_ end of defun

Angeliki

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost