danpp Posted April 19, 2016 Posted April 19, 2016 (edited) Well, I'm using AutoCAD Civil 3D 2015 and working on a project with several layouts. From time to time, I have to copy and paste multiple layouts throught projects, and they get messed up when it comes to their names. I was reading carefully to this thread (http://www.cadtutor.net/forum/showthread.php?27120-Batch-rename-of-layouts). However, that was only helpful to RENAME a single layout to another. (i.e. from "Layer-01" to "Layer (01)") Regarding my problem, I want something like this action Here is a quick function to do that: Code: (vl-load-com) (defun RenameLayouts ( kword / n) (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 (strcat kword (itoa n))) ) (setq n (1+ n)) ) ) Call it like this... Code: (renlay "PLOT") ...to have all the layouts renamed to PLOT1, PLOT2, PLOT3, etc. This code seems to be good, but it does not check for existent layout names and does not sort ascending. Well, I want something that can rename multiple layouts (already in the correct order) with a name of my desire. Ex: They are like this (PS 1 ; PS 3; PS 8; Layer 1) and I want it to become like this (PS-(1) ; PS-(2) ; PS-(3) ; PS-(4) ) I hope that I made myself clear. Cheers! Edited April 19, 2016 by SLW210 Changed the Quote Tags to Code Tags Quote
SLW210 Posted April 19, 2016 Posted April 19, 2016 I moved your thread to the AutoLISP, Visual LISP & DCL Forum, please post in the appropriate Forum. Please read Code posting guidelines and use Code Tags (not Quote Tags). I fixed your post. Quote
BIGAL Posted April 20, 2016 Posted April 20, 2016 Something like this (defun renumlayouts ( / alllayouts lay num newnum ss) (setq alllayouts (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))) (setq total (- (vla-get-count alllayouts) 1)) (vlax-for lay alllayouts (if (/= 0 (setq num (vla-get-taborder lay))) (progn (if ( > num 9) (setq newnum (strcat "D" (rtos num 2 0))) (setq newnum (strcat "D0" (rtos num 2 0))) ) ; if (vla-put-name lay newnum) ( setvar "ctab" newnum) ; ok ) ;progn ) ;if ) ; for ) ;defun (renumlayouts) Quote
danpp Posted April 20, 2016 Author Posted April 20, 2016 Something like this (defun renumlayouts ( / alllayouts lay num newnum ss) (setq alllayouts (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))) (setq total (- (vla-get-count alllayouts) 1)) (vlax-for lay alllayouts (if (/= 0 (setq num (vla-get-taborder lay))) (progn (if ( > num 9) (setq newnum (strcat "D" (rtos num 2 0))) (setq newnum (strcat "D0" (rtos num 2 0))) ) ; if (vla-put-name lay newnum) ( setvar "ctab" newnum) ; ok ) ;progn ) ;if ) ; for ) ;defun (renumlayouts) It seems perfect. How to add a a line to ask what kind of text would you like to add? Something more customizable, like enter code enter prefix code (like in the code "D0-X") Thanks in advance! Quote
Commandobill Posted April 20, 2016 Posted April 20, 2016 Something like this? (defun renumlayouts (prefix / alllayouts lay num newnum ss) (setq alllayouts (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))) (setq total (- (vla-get-count alllayouts) 1)) (vlax-for lay alllayouts (if (/= 0 (setq num (vla-get-taborder lay))) (progn (if ( > num 9) (setq newnum (strcat prefix (rtos num 2 0))) (setq newnum (strcat prefix "0" (rtos num 2 0))) ) ; if (vla-put-name lay newnum) ( setvar "ctab" newnum) ; ok ) ;progn ) ;if ) ; for ) ;defun (defun c:test ( / prefix ) (if (setq prefix (getstring "\nEnter prefix code: ")) (renumlayouts prefix))) Quote
zizzo86 Posted July 27, 2016 Posted July 27, 2016 Something like this? (defun renumlayouts (prefix / alllayouts lay num newnum ss) (setq alllayouts (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))) (setq total (- (vla-get-count alllayouts) 1)) (vlax-for lay alllayouts (if (/= 0 (setq num (vla-get-taborder lay))) (progn (if ( > num 9) (setq newnum (strcat prefix (rtos num 2 0))) (setq newnum (strcat prefix "0" (rtos num 2 0))) ) ; if (vla-put-name lay newnum) ( setvar "ctab" newnum) ; ok ) ;progn ) ;if ) ; for ) ;defun (defun c:test ( / prefix ) (if (setq prefix (getstring "\nEnter prefix code: ")) (renumlayouts prefix))) Hi commandobill, can it be modified to be used only on selected tabs? Quote
Lee Mac Posted July 27, 2016 Posted July 27, 2016 Hi commandobill, can it be modified to be used only on selected tabs? Try the following: (defun c:relays ( / idx lst lyc obj pre srt ) (vlax-for lay (setq lyc (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))) (if (= :vlax-false (vla-get-modeltype lay)) (setq lst (cons (vla-get-name lay) lst) srt (cons (vla-get-taborder lay) srt) obj (cons lay obj) ) ) ) (if (setq pre (getstring t "\nSpecify prefix <none>: ") srt (vl-sort-i srt '<) obj (mapcar '(lambda ( n ) (nth n obj)) srt) idx (LM:listbox "Select Layouts to Rename" (mapcar '(lambda ( n ) (nth n lst)) srt) 3) ) (progn ;; Temporary rename to free up keys held by other layouts in the selection (foreach n idx (vla-put-name (nth n obj) (vla-get-handle (nth n obj)))) (foreach n idx (vla-put-name (nth n obj) (getname lyc pre))) ) ) (princ) ) (defun getname ( lyc pre / int rtn ) (setq int 0) (while (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list lyc (setq int (1+ int) rtn (strcat pre (if (< 9 int) (itoa int) (strcat "0" (itoa int)))) ) ) ) ) ) ) rtn ) ;; List Box - Lee Mac ;; Displays a DCL list box allowing the user to make a selection from the supplied data. ;; msg - [str] Dialog label ;; lst - [lst] List of strings to display ;; bit - [int] 1=allow multiple; 2=return indexes ;; Returns: [lst] List of selected items/indexes, else nil (defun LM:listbox ( msg lst bit / dch des tmp rtn ) (cond ( (not (and (setq tmp (vl-filename-mktemp nil nil ".dcl")) (setq des (open tmp "w")) (write-line (strcat "listbox:dialog{label=\"" msg "\";spacer;:list_box{key=\"list\";multiple_select=" (if (= 1 (logand 1 bit)) "true" "false") ";width=50;height=15;}spacer;ok_cancel;}" ) des ) (not (close des)) (< 0 (setq dch (load_dialog tmp))) (new_dialog "listbox" dch) ) ) (prompt "\nError Loading List Box Dialog.") ) ( t (start_list "list") (foreach itm lst (add_list itm)) (end_list) (setq rtn (set_tile "list" "0")) (action_tile "list" "(setq rtn $value)") (setq rtn (if (= 1 (start_dialog)) (if (= 2 (logand 2 bit)) (read (strcat "(" rtn ")")) (mapcar '(lambda ( x ) (nth x lst)) (read (strcat "(" rtn ")"))) ) ) ) ) ) (if (< 0 dch) (unload_dialog dch) ) (if (and tmp (setq tmp (findfile tmp))) (vl-file-delete tmp) ) rtn ) (vl-load-com) (princ) The above uses my List Box function. Quote
zizzo86 Posted July 28, 2016 Posted July 28, 2016 that's awesome!! work's great!! thank you so much!!:D:D Quote
CADuser19 Posted August 2, 2019 Posted August 2, 2019 On 7/28/2016 at 3:35 AM, Lee Mac said: Try the following: (defun c:relays ( / idx lst lyc obj pre srt ) (vlax-for lay (setq lyc (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))) (if (= :vlax-false (vla-get-modeltype lay)) (setq lst (cons (vla-get-name lay) lst) srt (cons (vla-get-taborder lay) srt) obj (cons lay obj) ) ) ) (if (setq pre (getstring t "\nSpecify prefix <none>: ") srt (vl-sort-i srt '<) obj (mapcar '(lambda ( n ) (nth n obj)) srt) idx (LM:listbox "Select Layouts to Rename" (mapcar '(lambda ( n ) (nth n lst)) srt) 3) ) (progn ;; Temporary rename to free up keys held by other layouts in the selection (foreach n idx (vla-put-name (nth n obj) (vla-get-handle (nth n obj)))) (foreach n idx (vla-put-name (nth n obj) (getname lyc pre))) ) ) (princ) ) (defun getname ( lyc pre / int rtn ) (setq int 0) (while (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list lyc (setq int (1+ int) rtn (strcat pre (if (< 9 int) (itoa int) (strcat "0" (itoa int)))) ) ) ) ) ) ) rtn ) ;; List Box - Lee Mac ;; Displays a DCL list box allowing the user to make a selection from the supplied data. ;; msg - [str] Dialog label ;; lst - [lst] List of strings to display ;; bit - [int] 1=allow multiple; 2=return indexes ;; Returns: [lst] List of selected items/indexes, else nil (defun LM:listbox ( msg lst bit / dch des tmp rtn ) (cond ( (not (and (setq tmp (vl-filename-mktemp nil nil ".dcl")) (setq des (open tmp "w")) (write-line (strcat "listbox:dialog{label=\"" msg "\";spacer;:list_box{key=\"list\";multiple_select=" (if (= 1 (logand 1 bit)) "true" "false") ";width=50;height=15;}spacer;ok_cancel;}" ) des ) (not (close des)) (< 0 (setq dch (load_dialog tmp))) (new_dialog "listbox" dch) ) ) (prompt "\nError Loading List Box Dialog.") ) ( t (start_list "list") (foreach itm lst (add_list itm)) (end_list) (setq rtn (set_tile "list" "0")) (action_tile "list" "(setq rtn $value)") (setq rtn (if (= 1 (start_dialog)) (if (= 2 (logand 2 bit)) (read (strcat "(" rtn ")")) (mapcar '(lambda ( x ) (nth x lst)) (read (strcat "(" rtn ")"))) ) ) ) ) ) (if (< 0 dch) (unload_dialog dch) ) (if (and tmp (setq tmp (findfile tmp))) (vl-file-delete tmp) ) rtn ) (vl-load-com) (princ) The above uses my List Box function. This works really well...... I have 3 drawings with 10 layouts in each and i want to continue the number between the 3 drawings. Is there a way to add in a section where you type in a number and it will continue the labelling Chloe Quote
BIGAL Posted August 3, 2019 Posted August 3, 2019 Try (setq int 0) to (setq int (getint "Start layout number")) Quote
Lee Mac Posted August 3, 2019 Posted August 3, 2019 On 8/2/2019 at 3:28 AM, CADuser19 said: This works really well...... I have 3 drawings with 10 layouts in each and i want to continue the number between the 3 drawings. Is there a way to add in a section where you type in a number and it will continue the labelling Chloe Hi Chloe, The code I posted here is more aptly suited to your task, and may be modified in the following way to allow you to specify a starting number: ;; Renumber Layouts - Lee Mac ;; Sequentially numbers all Paperspace layouts, with an optional prefix & suffix. (defun c:rl ( / int lst lyn num ord pre sed suf ) ;; Obtain a valid (optional) prefix & suffix (setq pre (validstring "\nSpecify prefix <none>: ") suf (validstring "\nSpecify suffix <none>: ") num (cond ((getint "\nSpecify starting number <1>: ")) (1)) lyn (list (strcase pre)) ) ;; Obtain list of layout objects, current names, and sort index (vlax-for lyt (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (if (= :vlax-false (vla-get-modeltype lyt)) (setq lst (cons lyt lst) lyn (cons (strcase (vla-get-name lyt)) lyn) ord (cons (vla-get-taborder lyt) ord) ) ) ) ;; Construct a unique seed for temporary renaming (setq sed "%") (while (vl-some '(lambda ( x ) (wcmatch x (strcat "*" sed "*"))) lyn) (setq sed (strcat sed "%")) ) ;; Temporarily rename layouts to ensure no duplicate keys when renumbering (setq int 0) (foreach lyt lst (vla-put-name lyt (strcat sed (itoa (setq int (1+ int))))) ) ;; Rename layouts in tab order, with prefix & suffix (foreach idx (vl-sort-i ord '<) (vla-put-name (nth idx lst) (strcat pre (padzeros (itoa num) 2) suf)) (setq num (1+ num)) ) (princ) ) (defun padzeros ( str len ) (if (< (strlen str) len) (padzeros (strcat "0" str) len) str) ) (defun validstring ( msg / rtn ) (while (not (or (= "" (setq rtn (getstring t msg))) (snvalid rtn) ) ) (princ (strcat "\nThe name cannot contain the characters \\<>/?\":;*|,=`")) ) rtn ) (vl-load-com) (princ) Quote
SoloGM Posted September 16, 2019 Posted September 16, 2019 On 8/3/2019 at 2:53 PM, Lee Mac said: Hi Chloe, The code I posted here is more aptly suited to your task, and may be modified in the following way to allow you to specify a starting number: ;; Renumber Layouts - Lee Mac ;; Sequentially numbers all Paperspace layouts, with an optional prefix & suffix. (defun c:rl ( / int lst lyn num ord pre sed suf ) ;; Obtain a valid (optional) prefix & suffix (setq pre (validstring "\nSpecify prefix <none>: ") suf (validstring "\nSpecify suffix <none>: ") num (cond ((getint "\nSpecify starting number <1>: ")) (1)) lyn (list (strcase pre)) ) ;; Obtain list of layout objects, current names, and sort index (vlax-for lyt (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (if (= :vlax-false (vla-get-modeltype lyt)) (setq lst (cons lyt lst) lyn (cons (strcase (vla-get-name lyt)) lyn) ord (cons (vla-get-taborder lyt) ord) ) ) ) ;; Construct a unique seed for temporary renaming (setq sed "%") (while (vl-some '(lambda ( x ) (wcmatch x (strcat "*" sed "*"))) lyn) (setq sed (strcat sed "%")) ) ;; Temporarily rename layouts to ensure no duplicate keys when renumbering (setq int 0) (foreach lyt lst (vla-put-name lyt (strcat sed (itoa (setq int (1+ int))))) ) ;; Rename layouts in tab order, with prefix & suffix (foreach idx (vl-sort-i ord '<) (vla-put-name (nth idx lst) (strcat pre (padzeros (itoa num) 2) suf)) (setq num (1+ num)) ) (princ) ) (defun padzeros ( str len ) (if (< (strlen str) len) (padzeros (strcat "0" str) len) str) ) (defun validstring ( msg / rtn ) (while (not (or (= "" (setq rtn (getstring t msg))) (snvalid rtn) ) ) (princ (strcat "\nThe name cannot contain the characters \\<>/?\":;*|,=`")) ) rtn ) (vl-load-com) (princ) Wow! I found this topic on time. I was just looking for a program to rename sheets. And this one works just fine. Is it possible to change this program for sequential numbering in multiple drawing? Quote
eddieUSPP Posted September 25, 2020 Posted September 25, 2020 Hi everyone! It looks like there is alot of good discussion happening here. I am reading the code provided and I am not entirely sure how to take what is here and apply it to my own situation. I have over 200 autocad drawings with 1 layout per drawing that now need a slight to the layout name. The layout name for all of the drawings follows this format "01-1864_D-5-001-00". I need to a tool that I can run on all the drawings into one folder and delete off the last three characters of the layout name. So in the end I am left with "01-1864_D-5-001". Thank you so much in advance! Quote
marioo Posted October 11, 2022 Posted October 11, 2022 On 7/28/2016 at 12:35 AM, Lee Mac said: Try the following: (defun c:relays ( / idx lst lyc obj pre srt ) (vlax-for lay (setq lyc (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))) (if (= :vlax-false (vla-get-modeltype lay)) (setq lst (cons (vla-get-name lay) lst) srt (cons (vla-get-taborder lay) srt) obj (cons lay obj) ) ) ) (if (setq pre (getstring t "\nSpecify prefix <none>: ") srt (vl-sort-i srt '<) obj (mapcar '(lambda ( n ) (nth n obj)) srt) idx (LM:listbox "Select Layouts to Rename" (mapcar '(lambda ( n ) (nth n lst)) srt) 3) ) (progn ;; Temporary rename to free up keys held by other layouts in the selection (foreach n idx (vla-put-name (nth n obj) (vla-get-handle (nth n obj)))) (foreach n idx (vla-put-name (nth n obj) (getname lyc pre))) ) ) (princ) ) (defun getname ( lyc pre / int rtn ) (setq int 0) (while (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list lyc (setq int (1+ int) rtn (strcat pre (if (< 9 int) (itoa int) (strcat "0" (itoa int)))) ) ) ) ) ) ) rtn ) ;; List Box - Lee Mac ;; Displays a DCL list box allowing the user to make a selection from the supplied data. ;; msg - [str] Dialog label ;; lst - [lst] List of strings to display ;; bit - [int] 1=allow multiple; 2=return indexes ;; Returns: [lst] List of selected items/indexes, else nil (defun LM:listbox ( msg lst bit / dch des tmp rtn ) (cond ( (not (and (setq tmp (vl-filename-mktemp nil nil ".dcl")) (setq des (open tmp "w")) (write-line (strcat "listbox:dialog{label=\"" msg "\";spacer;:list_box{key=\"list\";multiple_select=" (if (= 1 (logand 1 bit)) "true" "false") ";width=50;height=15;}spacer;ok_cancel;}" ) des ) (not (close des)) (< 0 (setq dch (load_dialog tmp))) (new_dialog "listbox" dch) ) ) (prompt "\nError Loading List Box Dialog.") ) ( t (start_list "list") (foreach itm lst (add_list itm)) (end_list) (setq rtn (set_tile "list" "0")) (action_tile "list" "(setq rtn $value)") (setq rtn (if (= 1 (start_dialog)) (if (= 2 (logand 2 bit)) (read (strcat "(" rtn ")")) (mapcar '(lambda ( x ) (nth x lst)) (read (strcat "(" rtn ")"))) ) ) ) ) ) (if (< 0 dch) (unload_dialog dch) ) (if (and tmp (setq tmp (findfile tmp))) (vl-file-delete tmp) ) rtn ) (vl-load-com) (princ) The above uses my List Box function. there is possible sir if we numbering layout but remain the original name layout. so we just add numbering on prefix name of layout. Quote
Emmanuel Delay Posted October 11, 2022 Posted October 11, 2022 10 hours ago, marioo said: there is possible sir if we numbering layout but remain the original name layout. so we just add numbering on prefix name of layout. You just want a number, prefixed to the current Layout name? What I did: "Layout 1" becomes "1 - Layout 1" That's with this extra " - " (vla-put-name lyt (strcat (itoa lyt_ord) " - " lyt_name)) If you just want "1Layout 1", then remove the " - ": (vla-put-name lyt (strcat (itoa lyt_ord) lyt_name)) Or put whatever you want there. command LPN Is this what you want? (vl-load-com) ;; using some Lee Mac's code posted here above ;; LPN for Layout Prefix Number (defun c:lpn ( / lyt lyt_name lyt_ord) ;; Obtain list of layout objects, current names, and sort index (vlax-for lyt (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (if (= :vlax-false (vla-get-modeltype lyt)) (progn (setq lyt_name (vla-get-name lyt)) ;; current name (setq lyt_ord (vla-get-taborder lyt)) ;; order of the layout. 1, 2, 3... the loop doesn't nececarily go through the same order (vla-put-name lyt (strcat (itoa lyt_ord) " - " lyt_name)) ) ) ) ) 1 Quote
Steven P Posted October 11, 2022 Posted October 11, 2022 And Lee Mac has an offering to ( http://lee-mac.com/pslay.html ) which might do the same Quote
marioo Posted October 12, 2022 Posted October 12, 2022 16 hours ago, Emmanuel Delay said: You just want a number, prefixed to the current Layout name? What I did: "Layout 1" becomes "1 - Layout 1" That's with this extra " - " (vla-put-name lyt (strcat (itoa lyt_ord) " - " lyt_name)) If you just want "1Layout 1", then remove the " - ": (vla-put-name lyt (strcat (itoa lyt_ord) lyt_name)) Or put whatever you want there. command LPN Is this what you want? (vl-load-com) ;; using some Lee Mac's code posted here above ;; LPN for Layout Prefix Number (defun c:lpn ( / lyt lyt_name lyt_ord) ;; Obtain list of layout objects, current names, and sort index (vlax-for lyt (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (if (= :vlax-false (vla-get-modeltype lyt)) (progn (setq lyt_name (vla-get-name lyt)) ;; current name (setq lyt_ord (vla-get-taborder lyt)) ;; order of the layout. 1, 2, 3... the loop doesn't nececarily go through the same order (vla-put-name lyt (strcat (itoa lyt_ord) " - " lyt_name)) ) ) ) ) Yes sir, that is what i want. thank you I very beginning on custom Lisp. 1 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.