Jump to content

Rename layout tabs to dwg name + suffix -Help with codes


Recommended Posts

Posted (edited)

Thanks Lee Mac for the code you posted here above.

 

I'm a newb when it comes to LISP but I've modified the Lisp to simply rename the tab to the dwg name if only one layout is present and the Number or Letter option if there's more than 1.

 

Maybe someone might find this useful.

 

; Credit to Lee Mac for the base code found here (http://www.cadtutor.net/forum/showthread.php?68439-Rename-layout-tabs-to-dwg-name-suffix-Help-with-codes&p=468523&viewfull=1#post468523)

; I've modified that to present an option for no prefix if only one layout is present in the drawing
; and Numbers and Letter as per the original code for more than one layout.

; Again, thanks to Lee Mac.

; Modified by 3dwannab on the 23/03/2018
; Commands 'LAYOUTS_RENAME_TO_DRAWING_NAME' or 'RENLAY' will fire up the lisp.

(defun c:RENLAY nil (c:LAYOUTS_RENAME_TO_DRAWING_NAME))
(defun c:LAYOUTS_RENAME_TO_DRAWING_NAME ( / ans cnt fun lst tab) (vl-load-com)

; if the layout number > 1 present this option
(if (> (length (layoutlist)) 1)
(progn
	(initget "Numbers Letters")
	(setq ans
		(cond
			(
				(getkword
					(strcat "\nChoose Layout naming (suffix type) : [Numbers/Letters] <"
						(setq ans
							(cond ( ans ) ( "Numbers" ))
							)
						">: "
						)
					)
				)
			( ans )
			)
		)
	)
)

(setq tab (vl-filename-base (getvar 'dwgname)))
(vlax-for lay (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
(if (not (eq "Model" (vla-get-name lay)))
	(setq lst (cons (cons (vla-get-taborder lay) lay) lst))
	)
)

; if the layout number = 1 simply rename it to the drawing name.
(if (= (length (layoutlist)) 1)
(foreach lay (vl-sort lst '(lambda ( a b ) (< (car a) (car b))))
	(vla-put-name (cdr lay) (strcat tab))
	(princ (strcat "Layout tab has been renamed: " tab))
	)
)

; if the layout number > 1 run the different choices.
(if (> (length (layoutlist)) 1)
(progn
	(cond
		((=  "Numbers" ans)
			(setq fun itoa cnt 0)
			(foreach lay (vl-sort lst '(lambda ( a b ) (< (car a) (car b))))
				(vla-put-name (cdr lay) (strcat tab "-" (fun (setq cnt (1+ cnt)))))
				(princ (strcat "All layouts tabs have been renamed: " tab " - 1, " tab " - 2 etc"))
				)
			)
		((= "Letters" ans)
			(setq fun chr cnt 64)
			(foreach lay (vl-sort lst '(lambda ( a b ) (< (car a) (car b))))
				(vla-put-name (cdr lay) (strcat tab "-" (fun (setq cnt (1+ cnt)))))
				(princ (strcat "All layouts tabs have been renamed: " tab " - A, " tab " - B etc"))
				)
			)
		)
	)
)

(princ)
)

Edited by 3dwannab
  • Replies 30
  • Created
  • Last Reply

Top Posters In This Topic

  • pBe

    7

  • BlackBox

    6

  • mdbdesign

    5

  • 3dwannab

    5

Posted

This may be helpful we number from D01 not D1

; if less than 10
   (if (< (car dwgnum) 10.0) 
     (setq newstr2 (strcat dwgname "-D0"  (rtos sheetnum 2 0)))
     (setq newstr2 (strcat dwgname "-D"  (rtos sheetnum 2 0)))
   )

 

Also if you want to use A B etc you can use the (chr x) to convert an ascii number code to a string.

Posted
This may be helpful we number from D01 not D1

; if less than 10
   (if (< (car dwgnum) 10.0) 
     (setq newstr2 (strcat dwgname "-D0"  (rtos sheetnum 2 0)))
     (setq newstr2 (strcat dwgname "-D"  (rtos sheetnum 2 0)))
   )

 

Also if you want to use A B etc you can use the (chr x) to convert an ascii number code to a string.

 

You've kind of lost me. How would that fit in the code that I posted.

 

Also, would (car dwgnum) not be replaced with (length (layoutlist))?

 

Thanks very much, but go easy. I'm a baby at LISP. ;)

Posted

Its part of a bigger program so if say you have layout 3 then it will check for less than 10 and make the string "03" It may be your cnt variable in your code that you may want to look at.

  • 2 weeks later...
Posted
Its part of a bigger program so if say you have layout 3 then it will check for less than 10 and make the string "03" It may be your cnt variable in your code that you may want to look at.

 

Just got round to checking this. Thanks. I've used LeeMac modified code that I posted here.

 

I've used instead.

(if (< (length (layoutlist)) 10.0)
(vla-put-name (cdr lay) (strcat tab "-D" (fun (setq cnt (1+ cnt)))))
(vla-put-name (cdr lay) (strcat tab "-D0" (fun (setq cnt (1+ cnt)))))
)

 

This does 01,02 etc on dwgs with layouts more than 10 instead.

 

FULL CODE:

; Credit to Lee Mac for the base code found here (http://www.cadtutor.net/forum/showthread.php?68439-Rename-layout-tabs-to-dwg-name-suffix-Help-with-codes&p=468523&viewfull=1#post468523)

; I've modified that to present an option for no prefix if only one layout is present in the drawing
; and Numbers and Letter as per the original code for more than one layout.

; Again, thanks to Lee Mac.

; Modified by 3dwannab on the 23/03/2018
; Modified by 3dwannab on the 07/04/2018 - Added zero padding to the numbered version of greater than 10.
; Commands 'LAYOUTS_RENAME_TO_DRAWING_NAME' or 'RENLAY' will fire up the lisp.

(defun c:RENLAY nil (c:LAYOUTS_RENAME_TO_DRAWING_NAME))
(defun c:LAYOUTS_RENAME_TO_DRAWING_NAME ( / ans cnt fun lst tab) (vl-load-com)

; if the layout number > 1 present this option
(if (> (length (layoutlist)) 1)
(progn
	(initget "Numbers Letters")
	(setq ans
		(cond
			(
				(getkword
					(strcat "\nChoose Layout naming (suffix type) : [Numbers/Letters] <"
						(setq ans
							(cond ( ans ) ( "Numbers" ))
							)
						">: "
						)
					)
				)
			( ans )
			)
		)
	)
)

(setq tab (vl-filename-base (getvar 'dwgname)))
(vlax-for lay (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
(if (not (eq "Model" (vla-get-name lay)))
	(setq lst (cons (cons (vla-get-taborder lay) lay) lst))
	)
)

; if the layout number = 1 simply rename it to the drawing name.
(if (= (length (layoutlist)) 1)
(foreach lay (vl-sort lst '(lambda ( a b ) (< (car a) (car b))))
	(vla-put-name (cdr lay) (strcat tab))
	(princ (strcat "Layout tab has been renamed: " tab))
	)
)

; if the layout number > 1 run the different choices.
(if (> (length (layoutlist)) 1)
(progn
	(cond
		((=  "Numbers" ans)
			(setq fun itoa cnt 0)
			(foreach lay (vl-sort lst '(lambda ( a b ) (< (car a) (car b))))
				; Zero padding to the numbered version of greater than 10.
				(if (< (length (layoutlist)) 10.0)
					(vla-put-name (cdr lay) (strcat tab "-D" (fun (setq cnt (1+ cnt)))))
					(vla-put-name (cdr lay) (strcat tab "-D0" (fun (setq cnt (1+ cnt)))))
					)
				(princ (strcat "All layouts tabs have been renamed: " tab " - 1, " tab " - 2 etc"))
				)
			)
		((= "Letters" ans)
			(setq fun chr cnt 64)
			(foreach lay (vl-sort lst '(lambda ( a b ) (< (car a) (car b))))
				(vla-put-name (cdr lay) (strcat tab "-" (fun (setq cnt (1+ cnt)))))
				(princ (strcat "All layouts tabs have been renamed: " tab " - A, " tab " - B etc"))
				)
			)
		)
	)
)

(princ)
)

Posted (edited)

3dwannab Sorry read 1st page only just ignore. It was about not asking for numbers or letters.

 

Very simple you have swapped the two lines making D as the is less than 10 if you look at my post they are the other way around.

 

(if (< (length (layoutlist)) 10.0)

(vla-put-name (cdr lay) (strcat tab "-D0" (fun (setq cnt (1+ cnt)))))
       [color="red"](vla-put-name (cdr lay) (strcat tab "-D" (fun (setq cnt (1+ cnt)))))[/color]
)

or 
(if ([color="red"]>[/color] but then its 9 else no 10

Edited by BIGAL
Posted
Why not a toolbar or a menu saves worrying about saving a enviroment variable. We have more menus and toolbars than c:defuns.

 

? I don't get it.

Posted

Hi to all I found this thread is very interesting and I'm about to post the same scenario of in layout tab..

 

I found the code of sir 3dwannab, The LSP is additional number or text...

 

 

What if you to change the entire name of Layout tab.. Let say For example in the first Layout tab original tab name Layout you going to change it into EE-LT-01(will depend on user what name he/she going to change the tab name)...

Posted

If you look at the code here and in the other posts they all use the "vla-put-name" for the particular layout concerned, you can imply basicly any name you want.

Posted
sir 3dwannab
No I cannot take any credit, it's Sir Lee Macs code. Credit to him.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...