https://www.cadtutor.net/forum/topic/76216-create-layout-from-a-grid-in-model-space/#findComment-666...
This is the best programming in relation to placing each rectangle in layout and numbering each layout
But it still cannot rotate the sheets in the model to be parallel to the viewport, and adjust to the scale of the project, but it is still the best programming 50% of the heavy work done successfully!!!
;;;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/copy-first-layout-multiple-times-and...;;;
(defun c:vpfrectngl-multi (/ trap1 olderr baselay tablist layname cnt entrec objrec a b nn adoc curpos curtab lytname lytcnt i n)
(defun trap1 (errmsg)
(setq *error* olderr); restore *error* symbol
(princ)
)
(setq olderr *error*); assign current function defintion held by the *error* symbol to a local variable - olderr
(setq *error* trap1); pointing the *error* symbol to new function definition - trap1
(if (= (getvar "tilemode") 0);if1 in layout
(progn;progn-1
(setq baselay (getvar 'ctab));;store base layout
(setvar "tilemode" 1);;move to mode space
(if (setq ssrect (ssget '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&=") (70 . 1))));;;;;;;;;;if2
(progn ;progn-2
(setq n (sslength ssrect))
(setvar 'ctab baselay);;back to base layout
(and (= 0 (getvar 'tilemode))
(setq i (getint "\nEnter begining integer for suffix: "))
(setq curtab (getvar 'ctab))
(repeat n
(setq lytcnt 1)
(setq lytname (strcat curtab "." (itoa (+ (1- n) i))))
(while (member lytname (layoutlist));while-1 if layout tab name exist add 1 to suffix until it is a new name
(setq lytname (strcat curtab "." (itoa (+ (1- n) (+ i lytcnt)))))
(setq lytcnt (1+ lytcnt))
);while-1
(command "._layout" "_copy" "" lytname) ;(strcat curtab "." (itoa (+ (1- n) i))));;create new layout tab
(setq tablist (cons lytname tablist)) ;(strcat curtab "." (itoa (+ (1- n) i)))
(setvar 'ctab (strcat curtab "." (itoa (+ (1- n) i)))) ;(strcat curtab "." (itoa (+ (1- n) i))));move to new layout tab
(setq i (1- i))
);repeat
);and
);end progn-2
);;;;;;;;;;end if-2
(setq nn (sslength ssrect))
(setq cnt (- (sslength ssrect) 1))
(repeat nn
(setq layname (nth cnt tablist))
(setvar 'ctab layname)
;;;;;;;;;;;;;;;;by Steven P https://www.cadtutor.net/forum/topic/76216-create-layout-from-a-grid-in-model-space/;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;create viewport from rectangle in current layout;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (setq entrec (ssname ssrect cnt));get rectangle ename
(progn
(setq objrec (vlax-ename->vla-object entrec));Transforms entrec to a VLA-object
(vlax-invoke-method objrec 'GetBoundingBox 'a 'b); get max and min points of the rectangle as safe array
(setq a (vlax-safearray->list a));convert a from safe array to list
(setq b (vlax-safearray->list b));convert b from safe array to list
(command "mspace")
(vl-cmdf "_.zoom" a b)
(command "pspace")
);progn
(alert "no ent")
);if
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq cnt (1- cnt))
(setvar "tilemode" 0)
);repeat
);end progn-1
(alert "NOT IN PAPER SPACE")
);end if1
;(princ tablist)
(TabSort)
(setq *error* olderr); restore *error* symbol
(princ)
);defun
;;;;https://www.cadtutor.net/forum/topic/10087-re-ordering-layout-tabs/;;;;;
;; ---------------------------------------------------------------------------
;; Function: tabsort
;; Purpose : sort Tabs by the prefix then the first numbers found
;; AUTHOR Charles Alan Butler @ TheSwamp.org
;; ---------------------------------------------------------------------------
;; Last Update 03/01/2006 CAB
(defun TabSort (/ cnt doc lay)
(vl-load-com)
;; ---------------------------------------------------------------------------
;; Function: Num_sort
;; Purpose : sort list of strings by the prefix then the first numbers found
;; AUTHOR Charles Alan Butler @ TheSwamp.org
;; Params : tablst: list of strings to sort
;; Returns : sorted list
;; ---------------------------------------------------------------------------
(defun Num_Sort (tablst / tab ptr len loop tmp tmp2 sub lst)
(defun vl-sort-it (lst func)
(mapcar '(lambda (x) (nth x lst)) (vl-sort-i lst func))
)
(defun sort2 (tmp2 sub)
(setq tmp2 (append
(vl-sort-it sub '(lambda (e1 e2) (< (cadr e1) (cadr e2))))
tmp2
)
)
)
;; convert to a list (string) -> (prefix num string)
(foreach tab tablst
(setq ptr 1
len (strlen tab)
loop t
)
(while loop
(cond
((wcmatch "0123456789" (strcat "*" (substr tab ptr 1) "*"))
(setq tmp (cons (list (substr tab 1 (1- ptr))
(atof (substr tab ptr))
tab
)
tmp
)
loop nil
)
)
((> (setq ptr (1+ ptr)) len)
;; no number in string
(setq tmp (cons (list tab nil tab) tmp)
loop nil
)
)
) ; end cond stmt
)
)
;; sort on the prefix
(setq tmp (vl-sort-it tmp '(lambda (e1 e2) (< (car e1) (car e2)))))
;; Do a number sort on each group of matching prefex
(setq idx (length tmp))
(while (> (setq idx (1- idx)) -1)
(cond
((not sub)
(setq sub (List (nth idx tmp))
str (car (nth idx tmp))
)
)
((= (car (nth idx tmp)) str) ; still in the group
(setq sub (cons (nth idx tmp) sub))
)
) ; end cond stmt
(if (= idx 0) ; fim da lista
(progn
(setq tmp2 (sort2 tmp2 sub))
(if (/= (car (enésimo idx tmp)) str)
(setq tmp2 (append (lista (enésimo idx tmp)) tmp2))
)(
setq str (car (nth idx tmp)))
)
)
(if (/= (car (enésimo idx tmp)) str)
;; próximo grupo, então ordene o grupo
anterior(setq tmp2 (sort2 tmp2 sub)
sub (list (enésimo idx tmp))
str (carro (enésimo idx tmp))
))
) ; end while
(setq lst (mapcar 'caddr tmp2))(
princ)
lst
) ; terminar defun
;;==========================================================================
(setq cnt 1
doc (vla-get-activedocument (vlax-get-acad-object))
)
(foreach lay (num_sort (vl-remove "Model" (layoutlist)))(
vla-put-taborder (vla-item (vla-get-layouts doc) lay) cnt)
(setq cnt (1+ cnt))
)(
princ)
) ; fim da defunção
;; (prompt "\nTabSort carregado, digite TabSort para executar.")
(princípio)