Modify LSP to start the count from 1 to 1, 01, 001, 0001...

Modify LSP to start the count from 1 to 1, 01, 001, 0001...

jtm2020hyo
Collaborator Collaborator
2,548 Views
13 Replies
Message 1 of 14

Modify LSP to start the count from 1 to 1, 01, 001, 0001...

jtm2020hyo
Collaborator
Collaborator

  this rename layout from "1" to any number. adding prefix and suffix.

I need an option to start the count from  1 or  01 or  001 or 0001...

 

 

 

(defun c:TabInc (/ pre suf num)
 ;; Tab Increment
 ;; Rename layout tabs with number, based on location
 ;; Prefix and Suffix optional
 ;; Alan J. Thompson, 02.25.09 / 04.08.10 / 12.16.10
 (setq pre (getstring T "\nSpecify prefix <None>: "))
 (setq suf (getstring T "\nSpecify suffix <None>: "))
 (initget 6)
 (setq num (1- (cond ((getint "\nSpecify starting number <1>: "))
                     (1)
               )
           )
 )
 (vlax-for x (vla-get-layouts
               (cond (*AcadDoc*)
                     ((setq *AcadDoc* (vla-get-activedocument
                                        (vlax-get-acad-object)
                                      )
                      )
                     )
               )
             )
   (vl-catch-all-apply
     (function vla-put-name)
     (list x (strcat (rtos (getvar 'date) 2 16) "-" (itoa (vla-get-taborder x))))
   )
 )
 (vlax-for x (vla-get-layouts *AcadDoc*)
   (vl-catch-all-apply
     (function vla-put-name)
     (list x (strcat pre (itoa (+ num (vla-get-taborder x))) suf))
   )
 )
 (princ)
)

 

 

0 Likes
Accepted solutions (2)
2,549 Views
13 Replies
Replies (13)
Message 2 of 14

Moshe-A
Mentor
Mentor

@jtm2020hyo hi,

 

if you reply to  Specify prefix with  "1 or  01 or  001 or 0001..."

and just hit ENTER to  Specify suffix , it does want you want - no?

 

 moshe

 

0 Likes
Message 3 of 14

dbhunia
Advisor
Advisor

@jtm2020hyo wrote:

  this rename layout from "1" to any number. adding prefix and suffix.

I need an option to start the count from  1 or  01 or  001 or 0001... 


 

Do you want this....

 

(defun c:TabInc (/ pre suf num)
 ;; Tab Increment
 ;; Add layout tabs number, based on location
 ;; Prefix and Suffix optional
 ;; Alan J. Thompson, 02.25.09 / 04.08.10 / 12.16.10
 (setq pre (getstring T "\nSpecify prefix <None>: "))
 (setq suf (getstring T "\nSpecify suffix <None>: "))
 (initget 6)
 (setq num (1- (cond ((getint "\nSpecify starting number <1>: "))
                     (1)
               )
           )
 )
 (vlax-for x (vla-get-layouts
               (cond (*AcadDoc*)
                     ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
               )
             )
   (vl-catch-all-apply
     (function vla-put-name)
     (list x (strcat pre (itoa (+ num (vla-get-taborder x))) (vla-get-Name x) suf))
   )
 )
(princ)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 4 of 14

jtm2020hyo
Collaborator
Collaborator

@dbhunia wrote:

@jtm2020hyo wrote:

  this rename layout from "1" to any number. adding prefix and suffix.

I need an option to start the count from  1 or  01 or  001 or 0001... 


 

Do you want this....

 

(defun c:TabInc (/ pre suf num)
 ;; Tab Increment
 ;; Add layout tabs number, based on location
 ;; Prefix and Suffix optional
 ;; Alan J. Thompson, 02.25.09 / 04.08.10 / 12.16.10
 (setq pre (getstring T "\nSpecify prefix <None>: "))
 (setq suf (getstring T "\nSpecify suffix <None>: "))
 (initget 6)
 (setq num (1- (cond ((getint "\nSpecify starting number <1>: "))
                     (1)
               )
           )
 )
 (vlax-for x (vla-get-layouts
               (cond (*AcadDoc*)
                     ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
               )
             )
   (vl-catch-all-apply
     (function vla-put-name)
     (list x (strcat pre (itoa (+ num (vla-get-taborder x))) (vla-get-Name x) suf))
   )
 )
(princ)
)

Thanks for your reply.

I tried to use the code but your lisp delete all my tabs  except 2

 

 

image.png

 

 

image.png

 

 

 
I need to generate 0 automatically, something like this:

 

1,2,3,4,5,6,7 ...until 9 (lisp does not should generate a "0")


01,02,03,04,05,06,07,08,09,10,11,12 ...until 99 (lisp should generate a "0")

 

001,002,003,004,005,006,007,008, 009, 010, 011, 012 , 013 ...until 999 (lisp should generate two "0")

 

(numbers "0" for each quantity) = (numbers of digits of the final tab_number) - (numbers digits current tab_umber)

 

example:

for a count from 1 to 999, then:

all tab-numbers with one digit should have two "0" (since 1 until 9)

all tab-numbers with two digits should have one "0" (since 10 until 99)
all tab-numbers with three digits should have zero "0" (since 100 until 999)

0 Likes
Message 5 of 14

dbhunia
Advisor
Advisor

@jtm2020hyo wrote:

.........................


I tried to use the code but your lisp delete all my tabs  except 2

 

 

image.png

 

 

image.png

 

 

 
I need to generate 0 automatically, something like this:

 

1,2,3,4,5,6,7 ...until 9 (lisp does not should generate a "0")


01,02,03,04,05,06,07,08,09,10,11,12 ...until 99 (lisp should generate a "0")

 

001,002,003,004,005,006,007,008, 009, 010, 011, 012 , 013 ...until 999 (lisp should generate two "0")

 

(numbers "0" for each quantity) = (numbers of digits of the final tab_number) - (numbers digits current tab_umber)

 

example:

for a count from 1 to 999, then:

all tab-numbers with one digit should have two "0" (since 1 until 9)

all tab-numbers with two digits should have one "0" (since 10 until 99)
all tab-numbers with three digits should have zero "0" (since 100 until 999)


 

For Red mark post sample drawing (Autocad 2007 format)......


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 6 of 14

dbhunia
Advisor
Advisor

Try this ....... (lightly tested in AutoCAD 2007).....

 

For.....


@jtm2020hyo wrote:

........................................

example:

for a count from 1 to 999, then:

all tab-numbers with one digit should have two "0" (since 1 until 9)

all tab-numbers with two digits should have one "0" (since 10 until 99)
all tab-numbers with three digits should have zero "0" (since 100 until 999)


 

 

(defun c:lay_num (/ lay_lst lay_lst layoutname count n)
(vl-load-com)
(setvar 'cmdecho 0)
(vlax-for layt (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
	(if (> (vla-get-TabOrder layt) 0)
	    (setq lay_lst (cons (cons (vla-get-TabOrder layt) (vla-get-Name layt)) lay_lst))
	)
)
(setq lay_lst (vl-sort lay_lst '(lambda (x y) (< (car x) (car y)))))
(foreach layt lay_lst
   (setq layoutname (cons (cdr layt) layoutname))
)
(setq layoutname (reverse layoutname))
(setq count -1)
(repeat (setq n (length layoutname))
	(setvar 'ctab (nth (setq count (+ 1 count)) layoutname))
	(if (= (- (strlen (rtos n 2 0)) (strlen (rtos (+ 1 count) 2 0))) 2)
	   (command "layout" "R" "" (strcat "00" (rtos (+ 1 count) 2 0) (nth count layoutname)))
	)
	(if (= (- (strlen (rtos n 2 0)) (strlen (rtos (+ 1 count) 2 0))) 1)
	   (command "layout" "R" "" (strcat "0" (rtos (+ 1 count) 2 0) (nth count layoutname)))
	)
	(if (= (- (strlen (rtos n 2 0)) (strlen (rtos (+ 1 count) 2 0))) 0)
	   (command "layout" "R" "" (strcat (rtos (+ 1 count) 2 0) (nth count layoutname)))
	)
)
(setvar 'cmdecho 1)
(princ)
)

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 7 of 14

jtm2020hyo
Collaborator
Collaborator



your lisp code do the work but digits are adding like a prefix.

 

image.png

 

 

checking images we can see that code work. but I need the same options like tabinc.lsp (attached the first post)

 

 

image.png

 

 

I need rename completely and add prefix-suffix each time that code is used like lisp attached in the first post.

all non-prefix and non-suffix digits (center digits) should have the same number of digits like the highest number (the lastest). this just can be done if we add "0" to all others digits.

 

 

 PD: code is very slow because need checks each layout. I need to work like the first lisp if possible.

0 Likes
Message 8 of 14

dbhunia
Advisor
Advisor

For the Red marked......

 


@jtm2020hyo wrote:



your lisp code do the work but digits are adding like a prefix.

 

image.png

 

 

checking images we can see that code work. but I need the same options like tabinc.lsp (attached the first post)

 

 

image.png

 

 

I need rename completely and add prefix-suffix each time that code is used like lisp attached in the first post.

all non-prefix and non-suffix digits (center digits) should have the same number of digits like the highest number (the lastest). this just can be done if we add "0" to all others digits.

 

 

 PD: code is very slow because need checks each layout. I need to work like the first lisp if possible.


 

Try this......(Roughly tested in AutoCAD 2017 & 2018)

 

(defun c:TabInc (/ pre suf num len)
(setq pre (getstring T "\nSpecify prefix <None>: "))
(setq suf (getstring T "\nSpecify suffix <None>: "))
(initget 6)
(setq num (1- (cond ((getint "\nSpecify starting number <1>: "))
                    (1)
              )
          )
)
(setq len (strlen (itoa (length (layoutlist)))))
(vlax-for x (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
  (if (= (- len (strlen (itoa (vla-get-taborder x)))) 0) (setq pre_f pre))
  (if (= (- len (strlen (itoa (vla-get-taborder x)))) 1) (setq pre_f (strcat pre "0")))
  (if (= (- len (strlen (itoa (vla-get-taborder x)))) 2) (setq pre_f (strcat pre "00")))
  (vl-catch-all-apply
    (function vla-put-name)
    (list x (strcat pre_f (itoa (+ num (vla-get-taborder x))) suf ))
    ;(list x (strcat pre_f (itoa (+ num (vla-get-taborder x))) (vla-get-Name x) suf ))
  )
)
(princ)
)

 

I did not get the Blue marked points.......Hopefully you can manage the rest......

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 9 of 14

Kent1Cooper
Consultant
Consultant
Accepted solution

Does this do what you want?  It assumes you always want to start at 1 or 01 or 001 [etc.], so it doesn't include the asking for a starting number, but that could be added back in with some other alterations.  If you want the hyphens shown in your image in Message 4, as written you will need to include them in your prefix and suffix entries, but they could be built into the code instead.  Lightly tested, but at least up into 3-digit number of Layouts.

(defun c:TabIncPad (/ pad pre suf digits num)
 ;; Tab Increment, Padded
 ;; Rename layout tabs with number, based on location, padded with
 ;;   prefixed 0's so that all order components have same number of digits
 ;; Prefix and Suffix optional
 ;; Altered/expanded by Kent Cooper from code by Alan J. Thompson
  (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
  (setq
    pre (getstring T "\nSpecify prefix <None>: ")
    suf (getstring T "\nSpecify suffix <None>: ")
    digits (strlen (itoa (length (layoutlist))))
      ; how many digits in quantity of Paper-Space Layouts?
  ); setq
  (vlax-for x
    (vla-get-layouts
      (cond
        (*AcadDoc*)
        ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
      )
    )
    (vl-catch-all-apply
      (function vla-put-name)
      (list x (strcat pre (pad (vla-get-taborder x)) suf))
    )
  )
  (princ)
)

 

Kent Cooper, AIA
Message 10 of 14

jtm2020hyo
Collaborator
Collaborator

@dbhunia

 

you are the best in whole forums.autodesk.com

I want to be like you a day.

0 Likes
Message 11 of 14

jtm2020hyo
Collaborator
Collaborator

@Kent1Cooper
thanks for your code. help me a lot.

0 Likes
Message 12 of 14

jtm2020hyo
Collaborator
Collaborator

hello.

please, add an option to start numbering since a selected number.

like first attached LISP. I need it. please. thanks

0 Likes
Message 13 of 14

dbhunia
Advisor
Advisor
Accepted solution

I think the little modification(Blue) on @Kent1Cooper code will fulfill your requirements.......try this....

 

(defun c:TabIncPad (/ pad pre suf digits num)
 ;; Tab Increment, Padded
 ;; Rename layout tabs with number, based on location, padded with
 ;;   prefixed 0's so that all order components have same number of digits
 ;; Prefix and Suffix optional
 ;; Altered/expanded by Kent Cooper from code by Alan J. Thompson
  (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
  (setq
    pre (getstring T "\nSpecify prefix <None>: ")
    suf (getstring T "\nSpecify suffix <None>: ")
    digits (strlen (itoa (length (layoutlist))))
    ; how many digits in quantity of Paper-Space Layouts?
    num (1- (cond ((getint "\nSpecify starting number <1>: "))
                  (1)
             )
        )

  ); setq
  (vlax-for x
    (vla-get-layouts
      (cond
        (*AcadDoc*)
        ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
      )
    )
    (vl-catch-all-apply
      (function vla-put-name)
      (list x (strcat pre (pad (+ num (vla-get-taborder x))) suf))
    )
  )
  (princ)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 14 of 14

jtm2020hyo
Collaborator
Collaborator

@dbhunia wrote:

I think the little modification(Blue) on @Kent1Cooper code will fulfill your requirements.......try this....

 

(defun c:TabIncPad (/ pad pre suf digits num)
 ;; Tab Increment, Padded
 ;; Rename layout tabs with number, based on location, padded with
 ;;   prefixed 0's so that all order components have same number of digits
 ;; Prefix and Suffix optional
 ;; Altered/expanded by Kent Cooper from code by Alan J. Thompson
  (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
  (setq
    pre (getstring T "\nSpecify prefix <None>: ")
    suf (getstring T "\nSpecify suffix <None>: ")
    digits (strlen (itoa (length (layoutlist))))
    ; how many digits in quantity of Paper-Space Layouts?
    num (1- (cond ((getint "\nSpecify starting number <1>: "))
                  (1)
             )
        )

  ); setq
  (vlax-for x
    (vla-get-layouts
      (cond
        (*AcadDoc*)
        ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
      )
    )
    (vl-catch-all-apply
      (function vla-put-name)
      (list x (strcat pre (pad (+ num (vla-get-taborder x))) suf))
    )
  )
  (princ)
)

 

this code is simply perfect.

thanks a lot. @dbhunia @Kent1Cooper @Moshe-A

0 Likes