View Full Version : renaming the layout tabs
cadd4la
2005-03-10, 10:48 PM
Hi everyone,
I am looking for a lisp program that will change the layout tab name all at once i.e., if I add a new layout tab and I have L-1, L-2, @ L-3 then I add a new layout between L-1 & L-2.
I then rename the new layout tab L-2 and the two existing tabs behind the new L-2 rename to L-3 (use to be L-2), and L-4 (use to be L-3) or if I can have a dialog box that list them all in the drawing then renumber them and after I click on OK they rename.
Thank for the help
CADD4LA
RobertB
2005-03-11, 05:13 PM
An interesting question. It was rather easy to develop, at least as a starting point. There are issues such as assigning layouts to never change, or a layout without a incrementing number at the end, but those are items I will develop for in-house use. I found it to be best as a VBA event, so that's how I wrote it.
cadd4la
2005-03-13, 06:44 AM
Robert,
I downloaded "LayoutRenumber.dvb" and did a vbaload, then vbarun and typed in LayoutRenumber but nothing happened.
What I am I doing wrong?
Thanks,
Kyle C
"cadd4la"
CADmium
2005-03-13, 07:02 PM
a little Lisp :
(defun DT:LAYOUT-RENAME (OLDNAME NEWNAME)
(vl-load-com)
(if(and(=(type OLDNAME) 'STR)
(=(type NEWNAME) 'STR)
)
(vlax-for ITEM (vla-get-layouts(vla-get-activedocument(vlax-get-acad-object)))
(if(=(strcase(vla-get-name ITEM))(strcase OLDNAME))
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-put-name
(list ITEM NEWNAME)
)
)
)
)
)
)
cadd4la
2005-03-14, 05:33 AM
Thomas,
I can get your code to work for me?
I load the code and type in "DT" and all I get is:
Command: dt
Unknown command "DT". Press F1 for help.
Thank you for the help.
Kyle C.
"cadd4la"
CADmium
2005-03-14, 06:54 AM
in the commandline or in your own Lisp you must call the function so:
(DT:LAYOUT-RENAME "L-2" "L-3")
RobertB
2005-03-15, 05:04 AM
Switch tabs after you load the code. Or rename a layout. Or copy a layout. Or move a layout.
cadd4la
2005-03-27, 02:52 AM
Robert,
I tried what you told me to do but it not working the way I would like it too.
For example, I have a .dwg file that has three tabs in it. (LC-2, LC-3, & LC-4)
1. if i copy LC-3 layout I am getting the layout tab renamed to - (LC-3 (2) 1, LC-3 (2) 2, LC-3 (2) 3, & LC-3 (2) 4), what I am looking for is this (LC-5, LC-2, LC-3, & LC-4) then when I move LC-5 between LC-3, & LC-4 it will renumber LC-4 (the old LC-5), & LC-5 (the old LC-4).
2. If i try rename (LC-3 (2) 1, LC-3 (2) 2, LC-3 (2) 3, & LC-3 (2) 4) to (LC-2, LC-3, LC-4, & LC-5) I keep getting (LC-1, LC-2, LC-3, & LC-4) I don't have a LC-1 in this .dwg file.
I hope you can help me again.
Thanks,
Kyle C
"cadd4la"
cadd4la
2005-03-27, 03:27 AM
Thomas,
I don't understand what you asking me to do.
I did load you .lsp file and enter DT:LAYOUT-RENAME
I get - Press F1 for help.
Please note that I will not be always renumber L-2 to L-3, it may be LC-3 to LC-4 or LI-3 to LI-4.
So if you lisp is designed to put L-2 to L-3 somewhere in the code this is not what I am looking for. I need a dialog box that has an area with maybe a pulldown menu showing or the existing tab names and one for me to enter what I want to rename the tab to. after I pick the sheet number and rename that tab, it then renames the tabs behind it.
I hope you can help me again.
Thanks,
Kyle C
"cadd4la"
lance.81922
2005-03-27, 04:19 PM
Kyle,
Thomas's code is set up so that you have to call it with the name of the layout that you want to change and the new name. so if you have a layout tab called "Layout-Q" and you want to call it "Layout-Z", you would load his code and then type (DT:LAYOUT-RENAME "Layout-Q" "Layout-Z"). You have to give the program both the old and new names, and have to do this every time you use the program. The general instruction, then, is (DT:LAYOUT-RENAME <old name> <new name>). You replace <old name> with the layout name you want to change, and <new name> with what you want that name to be.
cadd4la
2005-03-29, 05:42 AM
Lance,
Thanks for making it a little clearer, but it is still not working fully.
Please note the file has the following tabs: LC-2, LC-3, & LC-4.
I type in the following:
(DT:LAYOUT-RENAME "LC-2" "LC-5") but it don't then change LC-3 to LC-6, & LC-4 to LC-7
I hope Thomas or somebody can help me.
Thanks,
Kyle C
"cadd4la"
lance.81922
2005-03-29, 03:59 PM
Kyle,
Please read my explanation again. When you enter
(DT:LAYOUT-RENAME "LC-2" "LC-5") it does not change LC-3 and LC-4, but rather changes only LC-2 to LC-5. Nothing else. To change the others you must run the program again, substituting "LC-3" for "LC-2" and, for example, "LC-6" for "LC-5". In other words, you then would enter (DT:LAYOUT-RENAME "LC-3" "LC-6") to change "LC-3" to "LC-6".
peter
2005-03-29, 04:22 PM
Here is another variant of the rename layouts routine posted earlier
It allows for substitution of substrings
Peter Jamtgaard
Forgive the eratic indentation of the code the forum has a bug that changes the formatting and the forums team is aware of it.
(defun C:RenameLayouts (/ objLayout strNew strOld )
(setq strOld (getstring "\nOld Text String: ")
strNew (getstring "\nNew Text String: ")
)
(vlax-for objLayout
(vla-get-layouts
(vla-get-activedocument
(vlax-get-acad-object)
)
)
(vl-catch-all-apply
'(lambda (x)(vla-put-name x
(vl-string-subst strNew strOld (vla-get-name x))
)
)
(list objLayout)
)
)
)
cadd4la
2005-03-29, 08:49 PM
Lance,
Again, I thank you for making Thomas' lisp more clearer, but please read my first request again and please focus on the text between the ***
Hi everyone,
I am looking for a lisp program that will change the layout tab name all at once i.e., if I add a new layout tab and I have L-1, L-2, @ L-3 then I add a new layout between L-1 & L-2.
I then rename the new layout tab L-2 ****and the two existing tabs behind the new L-2 rename to L-3 (use to be L-2), and L-4 (use to be L-3)*** or if I can have a dialog box that list them all in the drawing then renumber them and after I click on OK they rename.
I understand what the lisp can do. I now need it to be finished to do what I asked on my first post.
Kyle C.
cadd4la
2005-03-29, 09:11 PM
Peter,
First, thank you for your help.
I tried your code, it is much easier to use then thomas' I don't have to entry (DT:LAYOUT-RENAME <old name> <new name>) command line to change a tab.
Now can you make it do this:
When I change the tab name it also changes all the existing tab names behind the one I changed i.e. I rename the tab named "L-2" to L-3 (use to be L-2) then the tab behind the new L-3 (the old "L-2") automatic changes to "L-4" and so on for all the tab that are behind the one I change?
Also one more question.
When I ran you code and changed L-2 to L-5 on the command line I got this message
#<%catch-all-apply-error%>
What does this mean?
Thanks,
Kyle C.
RobertB
2005-03-31, 03:54 AM
Kyle, did you ever try out the routine I posted? After the event handler is loaded, as soon as you add a layout, move a layout, change to a layout, all the tabs sould be renamed. Without any input from you.
Note, I have attached a revised routine to accomodate a starting integer other than 1.
Also, load this routine before modifying layouts. If it works that way you like, I would advise autoloading the dvb.
cadd4la
2005-04-04, 02:56 AM
Robert,
Thank you very much I tried you new code, it's working great but it has a error problem in it.
When I copy a layout tab and if I change to another tab or move to another tab without naming the new tab I get a Microsoft visual basic error message
run-time error '13':
type mismatch
Also I type in LC-2.1 to see what would happens in the first tab of a existing file with the tabs LC-2, LC-3, & LC-4
I got LC-2.2, LC-2.3, & LC-2.4, I then type in LC-2.1 again on the LC-2.2 tab I could not get LC-2.1 to stay in the tab.
Is this something that you can fix so I can number the tabs both ways?
Thanks,
Kyle C.
cadd4la
RobertB
2005-04-04, 03:54 PM
When I copy a layout tab and if I change to another tab or move to another tab without naming the new tab I get a Microsoft visual basic error message
run-time error '13':
type mismatch
Sorry, I had a bug in my code. Please use the attached revised version.
Also I type in LC-2.1 to see what would happens in the first tab of a existing file with the tabs LC-2, LC-3, & LC-4
I got LC-2.2, LC-2.3, & LC-2.4, I then type in LC-2.1 again on the LC-2.2 tab I could not get LC-2.1 to stay in the tab.
Is this something that you can fix so I can number the tabs both ways?
I think the bug fix also addresses this question.
cadd4la
2005-04-04, 08:04 PM
Robert,
I tried you revised code, it's still giving me Microsoft visual basic error message. The revised code did fix the LC-2.1 problem.
Also, is there a way the code could override AutoCAD from not letting me rename a tab that has that existing name on a different tab. i.e., existing tabs LC-2, LC-3, & LC-4, I Have just added and moved a new tab between LC-3 & LC-4. I need to rename the new tab LC-4 but AutoCAD gives me a message (Layout "LC-4" already exists, not renamed).
Thanks for all your help,
Kyle C.
cadd4la
RobertB
2005-04-06, 10:15 PM
What version of AutoCAD are you running?
How are you adding the new layout? All you need to do is drag the new layout between the existing LC-3 and LC-4 and the new layout will become LC-4 while the old LC-4 becomes LC-5.
cadd4la
2005-04-07, 07:50 PM
Robert,
We our on 2005 and in the next week or two, when I have time we will be on 2006
I am right clicking on one of the tabs going to the move or copy pulldown area then checking the make copy box. The new tab is made at the front of the tabs and the error message pops-up. I click end on the error message and right click on the new tab go to move and pick what tab I want it to go before.
On the error message I click on the debug button
it is highlighting this part of the code
resData(1) = CLng(Right$(Layout.Name, i - 1))
Would you like me to try and send you video of my screen as I do this.
Thanks for all your help,
Kyle C.
cadd4la
RobertB
2005-04-11, 11:52 PM
I see what is happening now. The new layout you are creating thanks to the copy is the first one in the layout order. And AutoCAD gave it a non-numeric name (starting from the last character). Let me do a bit of coding to fix that sort of occurrence.
RobertB
2005-04-12, 11:35 PM
Ok, I have done the bug fix, and then some. I've now added an interface to enable/disable the event handler and change if all layouts rename, or only ones that match the first layout. However, I've posted the latest revision in the VBA (http://forums.augi.com/showthread.php?t=17630) forum.
cadd4la
2005-04-13, 01:48 AM
Robert,
Thank you so much for writing this program for me.
It works great.
Kyle C.
cadd4la
RobertB
2005-04-13, 04:57 AM
Thank you so much for writing this program for me.
It works great.I enjoyed the exercise. I thought it was a neat request.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.