Jump to content
Shablab

Rename Layout Lisp

Recommended Posts

Shablab

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)
)

 

Share this post


Link to post
Share on other sites
Tharwat

This?

(if (< c 10) (strcat "0" (itoa c)) (itoa c))

 

Share this post


Link to post
Share on other sites
Lee Mac

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.

 

Share this post


Link to post
Share on other sites
BIGAL

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)
 

Share this post


Link to post
Share on other sites
Lee Mac
Posted (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 by Lee Mac

Share this post


Link to post
Share on other sites
BIGAL

Thanks lee.

Share this post


Link to post
Share on other sites
ILoveMadoka

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?

Share this post


Link to post
Share on other sites
ronjonp
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)

 

Share this post


Link to post
Share on other sites
Lee Mac

This question has been answered many times... here is a similar program.

Share this post


Link to post
Share on other sites
ILoveMadoka
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..

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...