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

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