Shablab Posted March 12, 2019 Posted March 12, 2019 I have the following Lisp routine below. My problem is that for sheets after 10 the layout that would be named 'SH 02' gets put behind 'SH 10' instead of the initial "SH 01". I'm wondering what I can change to stop this from happening. I know it's the way autocad/ most programs reads numbers. (defun c:renamelayouts (/ laylist c) (setq laylist (vl-sort (layoutlist) '<) c 1) (foreach x laylist (command "layout" "R" x (strcat "SH " (if (< (strlen (itoa c)) 2) (strcat "0" (itoa c)) (itoa c)) ""));pad layout names (setq c (1+ c)) ) (princ) ) Quote
Tharwat Posted March 12, 2019 Posted March 12, 2019 This? (if (< c 10) (strcat "0" (itoa c)) (itoa c)) Quote
Lee Mac Posted March 12, 2019 Posted March 12, 2019 The issue is caused by your initial sort: (vl-sort (layoutlist) '<) Since your layout names are not prefixed with leading zeroes at this stage, the layouts are sorted alphabetically, causing the issue you have described. Quote
BIGAL Posted March 14, 2019 Posted March 14, 2019 A hint to add 0 at front (if ( > num 9) (setq newnum (strcat "D" (rtos num 2 0))) (setq newnum (strcat "D0" (rtos num 2 0))) ) (vla-put-name lay newnum) Quote
Lee Mac Posted March 14, 2019 Posted March 14, 2019 (edited) 11 hours ago, BIGAL said: A hint to add 0 at front (if ( > num 9) (setq newnum (strcat "D" (rtos num 2 0))) (setq newnum (strcat "D0" (rtos num 2 0))) ) (vla-put-name lay newnum) The code is already doing this as part of the rename operation - the issue occurs due to the sort performed before renaming. Edited March 14, 2019 by Lee Mac Quote
ILoveMadoka Posted March 26, 2019 Posted March 26, 2019 After all these observations and comments could someone please post what the final code should look like? I thought that I could cob the code pieces together but I was wrong... Please? Quote
ronjonp Posted March 26, 2019 Posted March 26, 2019 1 hour ago, ILoveMadoka said: After all these observations and comments could someone please post what the final code should look like? I thought that I could cob the code pieces together but I was wrong... Please? Here is a quick example with some comments. Perhaps you can learn from it (defun c:foo (/ a i l p x) ;; Get layouts (vlax-for x (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (setq l (cons x l))) ;; Sort by taborder and remove model tab (setq l (cdr (vl-sort l '(lambda (a b) (< (vla-get-taborder a) (vla-get-taborder b)))))) ;; Set counter (setq i 0) ;; Temporarily number them so we don't get duplicates (foreach x l (setq i (1+ i)) (vla-put-name x (strcat "FooTempBazoom_" (itoa i)))) ;; Set counter (setq i 0) ;; Get the layout count string length so we can add 0's if needed (setq a (strlen (itoa (length l)))) (foreach x l ;; Increment counter (setq i (1+ i)) ;; Reset prefix (setq p "") ;; Add zeroes to prefix if any (repeat (- a (strlen (itoa i))) (setq p (strcat p "0"))) ;; Change the tab name (vla-put-name x (strcat p (itoa i))) ) (princ) ) (vl-load-com) Quote
Lee Mac Posted March 26, 2019 Posted March 26, 2019 This question has been answered many times... here is a similar program. Quote
ILoveMadoka Posted April 3, 2019 Posted April 3, 2019 On 3/26/2019 at 9:04 AM, ronjonp said: Here is a quick example with some comments. Perhaps you can learn from it Just seeing this... Thank you Sir.. and to you Lee as well.. 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.