I found this script that i wanna change because it does not work well when layouts are not "Layout 1", "Layout 2" , etc
even for example if i already have the layouts numbered but have to create another one or simply re-arrange them
well i try to run it in the order like you said and it gives me an ; error: bad argument type: streamp nil
Just a note: i do not have a title block so i only need to number / re-number layouts in the order they are when i run the lisp.
my lisp above do it but i do not know why it doesn't respect order unless they are labeled "Layout 1", "Layout 2", etc...
(defun vlax-collection->list (col / lst) (vlax-for item col (setq lst (cons item lst))) (reverse lst))(defun c:LayoutRenum (/ layouts n name digits) (vl-load-com) (setq n 0 digits 2 layouts (vl-remove-if '(lambda (lay) (= (vla-get-ModelType lay) :vlax-true)) (vlax-collection->list (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object)))))) (foreach lay layouts (vla-put-Name lay (vla-get-Handle lay))) (foreach lay (vl-sort layouts '(lambda (a b) (apply '< (mapcar 'vla-get-Taborder (list a b))))) (setq name (itoa (setq n (1+ n)))) (repeat (- digits (strlen name)) (setq name (strcat "0" name))) (vla-put-Name lay name)) (princ))
Edit: You need to sort the list because both vla-get-Layouts and layoutlist gets in creation order. If you rearranged the tabs after you created them, the taborder property is the only one which allows you to get to their "displayed order".
Notice also that I first name the tab to its Handle string, and then to its new number. This is to try an prevent a situation where a duplicate name happens - which would cause the routine to error and not rename correctly.
That looks like it will error as 'layouts' is a list, not a collection (I'm sure you knew this already). But I think the 'vlax-collection->list' and 'vl-remove-if' expressions are unnecessary loops:
(defun c:layoutrenum ( / l n ) (vlax-for x (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (if (= :vlax-false (vla-get-modeltype x)) (progn (vla-put-name x (vla-get-handle x)) (setq l (cons x l)) ) ) ) (foreach x l (setq n (itoa (vla-get-taborder x))) (repeat (- 2 (strlen n)) (setq n (strcat "0" n))) (vla-put-name x n) ) (princ))(vl-load-com) (princ)