rename selected layouts with lisp

jtm2020hyo
Collaborator
Collaborator

rename selected layouts with lisp

jtm2020hyo
Collaborator
Collaborator

I attached a lisp that renames all layouts.

 

I need a hero to modify the lisp of rename all layouts, to just rename selected layouts.

 

imagen.png

0 Likes
Reply
Accepted solutions (2)
5,588 Views
10 Replies
Replies (10)

Ajilal.Vijayan
Advisor
Advisor
Accepted solution

try the below code.

[Modified the code from here]

(defun c:relays ( / idx lst lyc obj pre srt suf num )
   (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>: ")
			suf (getstring T "\nSpecify suffix <None>: ")
			num (1- (cond ((getint "\nSpecify starting number <1>: "))(1)))
			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 suf num)))
       )
   )
   (princ)
)
(defun getname ( lyc pre suf int / int rtn )
   (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)))suf)
                       )
                   )
               )
           )
       )
   )
   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)

jtm2020hyo
Collaborator
Collaborator

the first lisp attached has more functions, prefix, suffix, the same number of digits, just want to add an option like TabIncAll (for rename all layouts) and TabIncSelected (for selected layouts).

 

edit: too this lisp can start since any number. this lisp it's awesome

 

"TabInc" it's another LEE MAC lisp, but modified. It's possible to add that features to the new lisp?

0 Likes

Ajilal.Vijayan
Advisor
Advisor

Sorry, didn't understand your reply.
It's possible to add that features to the new lisp?

Which features are you mentioning here ?

jtm2020hyo
Collaborator
Collaborator

Like the lisp attached, prefix, suffix, same number of digits, start any number.

 The attached lisp just need an option for choice between rename all layouts or rename selected layouts.

 

I might try modify the lisp que are you sharing, but I need all that features of my old lisp attached.

0 Likes

Ajilal.Vijayan
Advisor
Advisor

Did you try the 'relays' command lisp, which is posted in my first reply.

I think it has the same features as the one you attached to your post.

After entering the inputs, select the sheets from the listbox to apply the renumbering.

To my knowledge, with LISP it is not possible to get the selected layouts from autocad.

So you have to select the layouts from a dialog box to apply the renumbering.

jtm2020hyo
Collaborator
Collaborator

nice lisp

... can you add an option to this lisp, I need all layouts to have same numbers of digits, I mean if I need number since 1 until 100 the first number should start since "001" (3 digits all numbers) , if I need to renumber since 10 to 10000, the first should have "00010" (5 digits all numbers).

0 Likes

Ajilal.Vijayan
Advisor
Advisor
Accepted solution

check the updated code:

Now you can enter the number of digits required.

If you do not want to enter the value, hit enter and then it will use the number of digits of total layout count

ie: 3 for 100+ layouts.

(defun c:relays ( / idx lst lyc obj pre srt suf num digits laylen )
   (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
	laylen (strlen (itoa (length (layoutlist))))
	pre (getstring t "\nSpecify prefix <none>: ")
	suf (getstring T "\nSpecify suffix <None>: ")
	digits (cond ((getint (strcat "\nSpecify number of digits <" (itoa laylen) ">: ")))(laylen))
	num (1- (cond ((getint "\nSpecify starting number <1>: "))(1)))
	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 suf num digits)))
       )
   )
   (princ)
)
(defun getname ( lyc pre suf int digits / int rtn )

(defun pad (m / padded) ; fill out with preceding 0's as appropriate
	(setq padded (itoa m))
	(while (< (strlen padded) digits)
		(setq padded (strcat "0" padded))
	); while
	padded ; return to main routine
); defun -- pad

   (while
       (not
           (vl-catch-all-error-p
               (vl-catch-all-apply 'vla-item
                   (list lyc
                       (setq int (1+ int)
                             rtn (strcat pre (pad int)suf)
                       )
                   )
               )
           )
       )
   )
   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)

jtm2020hyo
Collaborator
Collaborator

awesome.

thanks for your help.

I wish you a good day.
0 Likes

Ajilal.Vijayan
Advisor
Advisor

You're welcome,

Glad I could help

j_winkleman
Enthusiast
Enthusiast
Exactly what I was looking for! Thanks