Automatic number of layout tabs

Automatic number of layout tabs

Anonymous
Not applicable
5,092 Views
8 Replies
Message 1 of 9

Automatic number of layout tabs

Anonymous
Not applicable

Hello Everyone,

 

I have been searching for a LISP routine that will allow me to automatically number mulple layout tabs. I have searched here alot and cannot find a code that suits.

This is a typical drawing setup for where I work:

1) We work in AutoCAD 2011.

2) We start a project with one drawing and use multiple layout tabs. (No template)

3) Our first layout tab would typically be named "P1234-01" through maybe "P1234-50"

4) We create the first layout tab and rename it to P1234-01.

5) We copy "P1234-01" as many times needed for the amount of drawings we have.

6) We end up with these series of numbers: "P1234-01", "P1234-01 (2)", P1234-01 (3)", "P1234-01 (4)" etc.

7) We then rename each layout tab to look like this: "P1234-01", "P1234-02", "P1234-03", "P1234-04"

 

As I mentioned above, we may have to do this up to 50 times.

Is there a routine out there that would automatically number in the order we need?

Any advice is much appreciated.

 

Thanks

knj777

0 Likes
Accepted solutions (1)
5,093 Views
8 Replies
Replies (8)
Message 2 of 9

patrick_35
Collaborator
Collaborator

Hi

 

Try this

(defun c:ron(/ deb doc express lay lst n i s txt *errron*)

  (defun *errron* (msg)
    (or (member (strcase msg) '("FUNCTION CANCELLED" ""QUIT / EXIT ABORT"" "FONCTION ANNULEE" "QUITTER / SORTIR ABANDON"))
      (princ (strcat "\nErreur : " msg))
    )
    (vla-endundomark doc)
    (setq *error* s)
    (princ)
  )

  (setq doc (vla-get-activedocument (vlax-get-acad-object))
	n 1
	i 1
	s *error*
	*error* *errron*
  )
  (vla-startundomark doc)
  (if (eval 'acet-ui-progress-done)
    (progn
      (acet-ui-progress-init "" (1- (vla-get-count (vla-get-layouts doc))))
      (setq express T)
    )
    (progn
      (princ "\nWork in progress...")
      (princ)
    )
  )
  (vlax-for lay (vla-get-layouts doc)
    (setq lst (cons (list (vla-get-taborder lay) lay) lst))
  )
  (setq lay (vla-get-name (cadr (assoc 1 lst)))
	deb (substr lay 1 (- (strlen lay) 2))
  )
  (while (setq lay (assoc i lst))
    (setq txt (itoa n))
    (while (< (strlen txt) 2)
      (setq txt (strcat "0" txt))
    )
    (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-name (list (cadr lay) (strcat deb txt))))
      (progn
	(vla-put-name (vla-item (vla-get-layouts doc) txt) (strcat "Temporaire_Patrick_35___" txt))
	(vla-put-name (cadr lay) (strcat deb txt))
      )
    )
    (and express (acet-ui-progress-safe i))
    (setq n (1+ n)
	  i (1+ i)
    )
  )
  (and express (acet-ui-progress-done))
  (princ (strcat "\nDialing " (itoa (1- n)) " layout(s)."))
  (vla-endundomark doc)
  (setq *error* s)
  (princ)
)

@+

0 Likes
Message 3 of 9

Anonymous
Not applicable

Hi P

0 Likes
Message 4 of 9

Anonymous
Not applicable

Hi Patrick,

 

I tried the lisp (Thanks BTW) and all it did was rename the layout tab from "Layout" to "Layou01"

I wasnt sure exactly how to do it. Also, at the command propt it said "Dialing 1 layout(s)"

 

See attached.

 

 

0 Likes
Message 5 of 9

patrick_35
Collaborator
Collaborator

Hi

I am left with your example ("P1234-01", "P1234-01 (2)" P1234-01 (3) "," P1234-01 (4) "etc.) by adapting a lisp that I had.
The lisp takes the name of the first layout (eg "P1234-01"), removes the last 2 digits then increments the other layouts.

 

@+

0 Likes
Message 6 of 9

Anonymous
Not applicable
Accepted solution

Try this solution using vl-cmdf:

 

 

(defun C:PNUM-LYTS ()
;OEM062016-001
(vl-load-com) (defun tablyts (/ numoflyts index layouts initlyt lytprefix) (setq numoflyts (getint "\nNumber of layouts desired: ")) (setq lyts numoflyts) (setq index 1 layouts lyts tens "0" initlyt "P1234-" lytprefix "P1234-")
(repeat layouts (vl-cmdf "_.layout" "_C" initlyt (if (<= index 9) (strcat lytprefix tens (itoa index)) (strcat lytprefix (itoa index)))) (setq index (1+ index)) ) ) ;Used CABs TabSort Solution (defun tabsort (/ tab layouts layNames idx) (vl-load-com) (setq layouts (vla-get-Layouts (vla-get-Activedocument (vlax-get-acad-object))) layNames (vl-sort (layoutlist) '<) idx 0 ) (while (setq tab (car layNames)) (setq layNames (cdr layNames)) (vla-put-taborder (vla-item layouts tab) (setq idx (1+ idx))) ) (princ) ) (tablyts) (tabsort) )

 

1. Must have an initial Layout named "P1234-"

2. Must enter integer value when prompted "Number of layouts desired:"

3. Used CAB's sorting routine see forum post

 

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vla-put-taborder/td-p/2646932/page/2

 

Will sort properly up to 99 Layouts - Little bit of tweaking needs to be done to go beyond 99.

 

-Enjoy

 

- OEM - 

 

 

 

 

 

 

Message 7 of 9

Anonymous
Not applicable

Works great! Thank you so muchSmiley Very Happy

0 Likes
Message 8 of 9

Anonymous
Not applicable

knj777 - You are welcome!

 

-OEM-

0 Likes
Message 9 of 9

Anonymous
Not applicable

this one worked great for me. thanks.

0 Likes