TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: pmvliet on June 01, 2004, 12:11:56 PM
-
I have some clients and some users that like renaming layout1 to be the sheet number. ie: instead of layout1 they name it to A-101, A-102, E-101 etc. Each layout is in it's own file. So there is a model tab and say A-101 tab.
Is there a way to rename them globally back to layout1? Does anyone have something already written? I have come up with two options. a way to rename the tab or a way to thaw/unlock all layers, block out the paperspace items, delete the layout and AutoCad will automatically re-create layout1 and then insert the blocked items and return the layers to their previous state...
Any ideas/bits of code.
Thanks,
pieter
-
(defun c:re-name-layout (/ layoutsObj)
(vl-load-com)
(setq layoutsObj
(vlax-get-property
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
'Layouts
)
)
(vlax-put-property
(vla-item layoutsObj 1)
'Name "Layout1"
)
)
-
Hi Mark,
for some reason when i try to run this it say's "; error: Automation Error. Cannot rename the Model layout"
Is it looking for A-101 or A101 or does it really matter?
Thanks,
Pieter
-
as far as I'm aware, you cannot rename or delete the model tab
-
Give this a try:
(defun c:name->layout1 ()
(if (or (and (member "Model" (layoutlist))
(= 2 (length (layoutlist)))
)
(= 1 (length (layoutlist)))
)
(progn
(vlax-for x (vla-get-layouts
(vla-get-activedocument
(vlax-get-acad-object)))
(if (not (= (vla-get-name x) "Model"))
(vla-put-name x "Layout1")
)
)
)
)
(princ)
)
Jeff
-
Nope cannot rename or move a model tab....
Try this VBA macro, it will rename all layout tabs to LayoutX where X is the indexed order...
Sub RNLayout()
Dim ACLayout As AcadLayout
Dim ACLayouts As AcadLayouts
Set ACLayouts = ThisDrawing.Layouts
For Each ACLayout In ACLayouts
If ACLayout.Name <> "Model" Then
ACLayout.Name = "Layout" & ACLayout.TabOrder
End If
Next
End Sub
If this is combined with my BrowseForFolder macro, you will be able to open a specific folder, open each drawing, change each one, save and close each one, all without user intervention.
To do so will require a little bit more code, but it is possible....
-
I am not trying to rename the model tab. I am trying to rename a layout tab that has been renamed to something other then layout1.
Jeff, I'll try yours in the morning and keith I'll need to get some help on the VBA macro...
I gotta run so thanks for the help and I'll be back on Wednesday.
pieter
-
(defun c:re-name-layout (/ layoutsObj)
(vl-load-com)
(setq layoutsObj
(vlax-get-property
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
'Layouts
)
)
(vlax-put-property
(vla-item layoutsObj 1)
'Name "Layout1"
)
)
I'm not sure if pmvliet had any sucess, but I accually had to use this today for about 700+ drawings and it worked great. Glad I keep up with the post's or I would have had a tough time.
-
I'm not sure if pmvliet had any sucess, but I accually had to use this today for about 700+ drawings and it worked great. Glad I keep up with the post's or I would have had a tough time.
Excellent !!
<funny mode>
now about my bill, where should I send it again?
</funny mode>
-
<funny mode>
now about my bill, where should I send it again?
</funny mode>
Didn't you turn down payment HERE (http://theswamp.org/phpBB2/viewtopic.php?t=1321)?
-
It's a little late, but how about this one I cooked up.
;; This routine will rename all layout tabs in all open drawings
;; to "Layoutx" where x = the tab count
(defun c:re-name-all-layouts (/ Tab_name doc x cnt)
(vl-load-com)
(setq Tab_name "Layout")
(vlax-for doc (vla-get-documents (vlax-get-acad-object))
(setq cnt 0)
(vlax-for x (vla-get-layouts doc)
(if (not (= (vla-get-name x) "Model"))
(vla-put-name x
(strcat Tab_name (itoa (setq cnt (1+ cnt))))
)
)
)
)
)
-
cCan this routine be changed to allow would like to see if Tabs could go Tab 1, Tab 2, Tab 3 or Tab A, Tab B, Tab C and so on. Can it also use anything that you want?
-
(setq Tab_name "Layout")
i'd imagine you could just change layout in this line to tab. as far as changing it to alpha instead of numeric not sure which way to point you but i'm sure it could be done. these guys can help you i'm sure
-
This VBA one can do Tab 1 Tab 2 ..... all you need to do is change "Layout" to "Tab "...
Sub RNLayout()
Dim ACLayout As AcadLayout
Dim ACLayouts As AcadLayouts
Set ACLayouts = ThisDrawing.Layouts
For Each ACLayout In ACLayouts
If ACLayout.Name <> "Model" Then
ACLayout.Name = "Layout" & ACLayout.TabOrder
End If
Next
End Sub
To do Tab A, Tab B, Tab C ..... you will need to include a minor change to make it happen...
Sub RNLayout()
Dim ACLayout As AcadLayout
Dim ACLayouts As AcadLayouts
Set ACLayouts = ThisDrawing.Layouts
For Each ACLayout In ACLayouts
If ACLayout.Name <> "Model" Then
ACLayout.Name = "Layout" & Chr(ACLayout.TabOrder + 64)
End If
Next
End Sub
If you have over 26 layouts, you will get wierd names though .... and will crash if more than 255 tabs
-
Keith, man you are fast... 8)
Here is a lisp version.
;;; FUNCTION
;;; This routine will rename all layout tabs with
;;; user entered prefix & number or letter suffix
;;;
;;; ARGUMENTS
;;; none
;;;
;;; USAGE
;;; re-name-layouts
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Copyright© 2004 Charles Alan Butler
;;; ab2draft@TampaBay.rr.com
;;;
;;; VERSION
;;; 1.0 Oct. 01, 2004
;;;
;;; This software is provided "as is" without express or implied ;
;;; warranty. All implied warranties of fitness for any particular ;
;;; purpose and of merchantability are hereby disclaimed. ;
;;; You are hereby granted permission to use, copy and modify this ;
;;; software without charge, provided you do so exclusively for ;
;;; your own use or for use by others in your organization in the ;
;;; performance of their normal duties, and provided further that ;
;;; the above copyright notice appears in all copies and both that ;
;;; copyright notice and the limited warranty and restricted rights ;
;;; notice appear in all supporting documentation. ;
;;;
(defun c:re-name-layouts (/ tab_name doc cnt x suffix new_list)
(vl-load-com)
(setq tab_name (getstring t "\nEnter Tab Name prefix (add trailing space): "))
(cond (tab_name) ((setq tab_name "")))
(initget "Numbers Letters")
(setq suffix (getkword "\nSuffix to use? [Numbers or Letters] : <Numbers> "))
(cond (suffix) ((setq suffix "Numbers")))
(setq *doc* (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for tab (vla-get-layouts ; get list of layout tabs
(vla-get-activedocument (vlax-get-acad-object)))
(if (/= (setq tmpname (vla-get-name tab)) "Model") ; omit MODEL space
(setq new_list (cons (cons (vla-get-taborder tab) tab) new_list))
)
)
;; sort list acording to tab order
(setq new_list (vl-sort new_list
'(lambda (e1 e2) (< (car e1) (car e2)))))
;;remove the taborder numbers
(setq new_list (mapcar 'cdr new_list))
;; rename the tabs
(setq cnt (cond ((= suffix "Numbers") 0) (64)))
(foreach x new_list
(vla-put-name x
(strcat tab_name
(cond
((= suffix "Numbers")
(itoa (setq cnt (1+ cnt))))
((chr (setq cnt (1+ cnt))))
)))
)
(princ)
) ; defun
(prompt "\n*-* Rename Tab layouts Loaded, Enter re-name-layouts to run. *-*")
(princ)
-
Keith, man you are fast... 8)
Here is a lisp version.
;;; FUNCTION
;;; This routine will rename all layout tabs with
;;; user entered prefix & number or letter suffix
;;;
;;; ARGUMENTS
;;; none
;;;
;;; USAGE
;;; re-name-layouts
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Copyright© 2004 Charles Alan Butler
;;; ab2draft@TampaBay.rr.com
;;;
;;; VERSION
;;; 1.0 Oct. 01, 2004
;;;
;;; This software is provided "as is" without express or implied ;
;;; warranty. All implied warranties of fitness for any particular ;
;;; purpose and of merchantability are hereby disclaimed. ;
;;; You are hereby granted permission to use, copy and modify this ;
;;; software without charge, provided you do so exclusively for ;
;;; your own use or for use by others in your organization in the ;
;;; performance of their normal duties, and provided further that ;
;;; the above copyright notice appears in all copies and both that ;
;;; copyright notice and the limited warranty and restricted rights ;
;;; notice appear in all supporting documentation. ;
;;;
(defun c:re-name-layouts (/ tab_name doc cnt x suffix new_list)
(vl-load-com)
(setq tab_name (getstring t "\nEnter Tab Name prefix (add trailing space): "))
(cond (tab_name) ((setq tab_name "")))
(initget "Numbers Letters")
(setq suffix (getkword "\nSuffix to use? [Numbers or Letters] : <Numbers> "))
(cond (suffix) ((setq suffix "Numbers")))
(setq *doc* (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for tab (vla-get-layouts ; get list of layout tabs
(vla-get-activedocument (vlax-get-acad-object)))
(if (/= (setq tmpname (vla-get-name tab)) "Model") ; omit MODEL space
(setq new_list (cons (cons (vla-get-taborder tab) tab) new_list))
)
)
;; sort list acording to tab order
(setq new_list (vl-sort new_list
'(lambda (e1 e2) (< (car e1) (car e2)))))
;;remove the taborder numbers
(setq new_list (mapcar 'cdr new_list))
;; rename the tabs
(setq cnt (cond ((= suffix "Numbers") 0) (64)))
(foreach x new_list
(vla-put-name x
(strcat tab_name
(cond
((= suffix "Numbers")
(itoa (setq cnt (1+ cnt))))
((chr (setq cnt (1+ cnt))))
)))
)
(princ)
) ; defun
(prompt "\n*-* Rename Tab layouts Loaded, Enter re-name-layouts to run. *-*")
(princ)
CAB,
This is really cool! Here is a question that I think can it can be done but I don't know where to start. Please just follow what it is saying.
Ok, lets start with a 4 tabs for sheets
in paper space. Lets say that you name the 4 tabs BFDS, BFDW, CFP01 and
CFP02.
Now take the shape (dwg area in model) of the view port from the tab BFDS and paste it into model space.
You want that shape (dwg area in model) to match the name of the tab. So you name the shape (dwg area in model) BFDS with text.
But I want to have that name of shape (dwg area in model) automatically
change with Rtext. So when you change that tab BFDS to BFINB.
The shape (dwg area in model) will automatically update to BFINB.
That is my question.
How would you do that with the rest of that tabs BFDW, CFP01 and CFP02? Is there a sequence diesel code for each tab?
-
keith,
how do I use your VBA macro. I have 80 files where some of the layout tabs where renamed and some not. I would like to rename to layout1 instead of the sheet number, but if it requires opening every dwg I'll have to ignore it. BrowseForFolder macro?
-
Oneshot,
What you are asking is possible and i think would require a reactor.
I have not delt with reactors so I can not help you at this time.
-
keith,
how do I use your VBA macro. I have 80 files where some of the layout tabs where renamed and some not. I would like to rename to layout1 instead of the sheet number, but if it requires opening every dwg I'll have to ignore it. BrowseForFolder macro?
I'll have to put together that BrowseForFolder macro and post it.... there will be some additional coding required, but it will streamline the process so that it will all happen in a matter of a couple of minutes, rather than a couple of hours of your time.
-
CAB,
This is really cool! Here is a question that I think can it can be done but I don't know where to start. Please just follow what it is saying.
Ok, lets start with a 4 tabs for sheets
in paper space. Lets say that you name the 4 tabs BFDS, BFDW, CFP01 and
CFP02.
Now take the shape (dwg area in model) of the view port from the tab BFDS and paste it into model space.
You want that shape (dwg area in model) to match the name of the tab. So you name the shape (dwg area in model) BFDS with text.
But I want to have that name of shape (dwg area in model) automatically
change with Rtext. So when you change that tab BFDS to BFINB.
The shape (dwg area in model) will automatically update to BFINB.
That is my question.
How would you do that with the rest of that tabs BFDW, CFP01 and CFP02? Is there a sequence diesel code for each tab?
have a look at the A-MTEXT lisp in your Sample > Visual Lisp > Reactors directory. it adds Mtext linked to a circle ~ if you modify the circle, the mtext changes to reflect that. It should be able to be modified to suit your needs.
-
CAB,
This is really cool! Here is a question that I think can it can be done but I don't know where to start. Please just follow what it is saying.
Ok, lets start with a 4 tabs for sheets
in paper space. Lets say that you name the 4 tabs BFDS, BFDW, CFP01 and
CFP02.
Now take the shape (dwg area in model) of the view port from the tab BFDS and paste it into model space.
You want that shape (dwg area in model) to match the name of the tab. So you name the shape (dwg area in model) BFDS with text.
But I want to have that name of shape (dwg area in model) automatically
change with Rtext. So when you change that tab BFDS to BFINB.
The shape (dwg area in model) will automatically update to BFINB.
That is my question.
How would you do that with the rest of that tabs BFDW, CFP01 and CFP02? Is there a sequence diesel code for each tab?
have a look at the A-MTEXT lisp in your Sample > Visual Lisp > Reactors directory. it adds Mtext linked to a circle ~ if you modify the circle, the mtext changes to reflect that. It should be able to be modified to suit your needs.
I have the A-Mtext.lisp open and know I am trying to figure out what do I need to change to make it work to my liking. Can someone help me out?
-
I have been trying to figures this out. I am have no luck with it. Can someone help me out? Thank you!
-
Have you read this thread?
http://theswamp.org/phpBB2/viewtopic.php?t=2357&postdays=0&postorder=asc&highlight=reactor&start=30
-
Have you read this thread?
http://theswamp.org/phpBB2/viewtopic.php?t=2357&postdays=0&postorder=asc&highlight=reactor&start=30
and this
http://theswamp.org/phpBB2/viewtopic.php?t=9&highlight=reactors
-
cab just used your rename routine wooooow works beautifully
-
Okay, I have to ask the question. I tried not to, but I just can't help it, I gotta know.
What the heck is the advantage in changing the name of the layout tab back to layout1?
-
got me... but you know I don't usually question why someone would like to do something .. perhaps I should ... but when it has absolutely no bearing on me, I couldn't care less
-
Well I have a couple reasons:
First I have a 1-button routine that will plot to any device/size paper
but it requires that Layout1 is named Layout 1
Secondly, when you create a plot file or PDF, AutoCad will put the file name and then put a -layout name. For a drawings named A-101.dwg
with a layout called A-101, the plot file is A-101-A-101.plt. It gets to be a real nuisance.
Third, I see no real value and just takes time and more upkeep in a drawing. As soon as you do a saveas, if you don't go and update your layout name you will start getting inconsistencies. It just leads to errors.
Pieter
-
Well I have a couple reasons:
First I have a 1-button routine that will plot to any device/size paper
but it requires that Layout1 is named Layout 1
Secondly, when you create a plot file or PDF, AutoCad will put the file name and then put a -layout name. For a drawings named A-101.dwg
with a layout called A-101, the plot file is A-101-A-101.plt. It gets to be a real nuisance.
Third, I see no real value and just takes time and more upkeep in a drawing. As soon as you do a saveas, if you don't go and update your layout name you will start getting inconsistencies. It just leads to errors.
Pieter
try this string with RText. This is set to read the file name and then tab name. Look at the RText where you put it. I should only say A-101. So when you plt the file, it will say A-101.plt.
$(substr,$(getvar,"dwgname"),1,$(-,$(strlen,($(getvar,"dwgname"))),6))$(getvar,"ctab")
-
I added a dialogue box to Keith's VBA routine and also added the suffix option like CAB's lisp. Edit: Also added a start number so you could designate what number you want the first tab to start numbering from.
http://theswamp.org/lilly.pond/Ron/rename.bmp
Here is the dvb:
http://theswamp.org/lilly.pond/Ron/rename_tabs.dvb
To run it, type -vbarun then renametabs.
For button access ^C^C-vbarun;renametabs;
Ron :D
-
Well I have a couple reasons:
First I have a 1-button routine that will plot to any device/size paper
but it requires that Layout1 is named Layout 1
What happens to layout2?? BTW, look for PLOTTABS on these boards somewhere excellant tool for multiple layouts.
Secondly, when you create a plot file or PDF, AutoCad will put the file name and then put a -layout name. For a drawings named A-101.dwg with a layout called A-101, the plot file is A-101-A-101.plt. It gets to be a real nuisance.
Only if you accept the default at plotting.
Third, I see no real value and just takes time and more upkeep in a drawing. As soon as you do a saveas, if you don't go and update your layout name you will start getting inconsistencies. It just leads to errors.
If you name the layout something too specific and have to rename it, yes it takes time. Or if you're going to rename the layout back to "Layout1, it takes time. We use file numbers and Sheet numbers, the layouts are named after the sheet numbers and the file is the file name. Accepting the default at plotting, we get <filename>-<sheetname> for individual pdf's.
We don't use SAVEAS, it brings all the previous drawing TIME with it. We'll use a previous drawing as a prototype.
carry on, just curious.
-
Just wanted to let you guys know I updated the vba routine to allow the user to designate a number to start numbering from. Check it out
http://theswamp.org/phpBB2/viewtopic.php?p=34725#34725
Ron :D