3dwannab Posted March 23, 2018 Posted March 23, 2018 (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 March 23, 2018 by 3dwannab Quote
BIGAL Posted March 25, 2018 Posted March 25, 2018 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. Quote
3dwannab Posted March 25, 2018 Posted March 25, 2018 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. Quote
BIGAL Posted March 26, 2018 Posted March 26, 2018 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. Quote
3dwannab Posted April 7, 2018 Posted April 7, 2018 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) ) Quote
BIGAL Posted April 7, 2018 Posted April 7, 2018 (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 April 7, 2018 by BIGAL Quote
3dwannab Posted April 7, 2018 Posted April 7, 2018 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. Quote
Mystogan Posted April 9, 2018 Posted April 9, 2018 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)... Quote
BIGAL Posted April 10, 2018 Posted April 10, 2018 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. Quote
3dwannab Posted April 10, 2018 Posted April 10, 2018 sir 3dwannabNo I cannot take any credit, it's Sir Lee Macs code. Credit to him. Quote
Recommended Posts
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.