250+ layouts

250+ layouts

kenhuse
Contributor Contributor
1,304 Views
8 Replies
Message 1 of 9

250+ layouts

kenhuse
Contributor
Contributor

I have 2 drawings with 250+ layouts. I'm using AutoCAD 2015.

Unfortunately for me, the higher-ups have decided on one of the drawings to reverse the layout tab order.

I'm trying different things but they are very time consuming and laborious.

For example:

I go to the last layout, select it, then move it to the front.

Then I have to go to the right of the layout tabs to select the arrow to scroll through the list of layout tabs to go the last layout, select it, move it to just behind the one I previously moved, then do the scroll thing again, etc.

I also tried using AutoCAD Design Center to drag and drop the layouts from a previous drawing base, but the layout tabs  in ADC aren't in the order used in the drawing so there's too much room for mistakes for which I have a peculiar talent.

Does anybody out there have any idea how reversing the layout tab order might be accomplished in an efficient manner? Thanks, Ken

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

Ranjit_Singh
Advisor
Advisor

Try below code. Minimal testing.

(defun c:somefunc  (/ adoc lst nam nam2 pos)
 (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
 (vlax-for i  (vla-get-layouts adoc)
  (setq pos (cons (vla-get-taborder i) pos)
        nam (cons (vla-get-name i) nam)))
 (setq lst (mapcar 'cons (cdr nam) (reverse (cdr pos))))
 (vlax-for i  (vla-get-layouts adoc)
  (and (/= "Model" (setq nam2 (vla-get-name i))) (vla-put-taborder i (cdr (assoc nam2 lst)))))
 (princ))

rev_tab_order.gif

 

Message 3 of 9

kenhuse
Contributor
Contributor
Thanks Ranjit. I gave somefunc a try and got a little action but not quite
enough. Thanks for your suggestion, Ken
0 Likes
Message 4 of 9

ВeekeeCZ
Consultant
Consultant

Try and see...

 

(vl-load-com)

(defun c:LayoutReverse (/ i :Layorder)  ;sort layout order
  
  ; pbejse https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/layout-order/td-p/3749964
  (defun :Layorder (/ order)
    (vlax-for lay (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
      (setq order (cons (list (vla-get-name lay)
                              (vla-get-taborder lay))
                        order)))
    (mapcar 'car (Cdr (vl-sort order '(lambda (j k) (< (cadr j) (cadr k)))))))

  (setq i 0)
  (foreach x (reverse (:Layorder))
    (vla-put-taborder
      (vla-item	(vla-get-layouts
                  (vla-get-activedocument (vlax-get-acad-object)))
                x)
      (setq i (1+ i))))
  (princ)
)
Message 5 of 9

kenhuse
Contributor
Contributor
BeekeeCZ, Thanks for your hard work. I get "unknown command" when I key in
layoutreverse. I double checked to be sure that I saved layoutreverse on my
acaddoc before opening the drawing. Thanks again, Ken
0 Likes
Message 6 of 9

Ranjit_Singh
Advisor
Advisor
Accepted solution

@kenhuse wrote:
Thanks Ranjit. I gave somefunc a try and got a little action but not quite
enough. Thanks for your suggestion, Ken

I should had tested with a bigger dataset. Thanks @ВeekeeCZ. His post pointed out where I screwed up. Try now.
(defun c:somefunc  (/ adoc ctr lays lst)
 (setq ctr  (1+ (length (layoutlist)))
       adoc (vla-get-activedocument (vlax-get-acad-object))
       lst  (cdr (vl-sort (vlax-for i  (setq lays (vla-get-layouts adoc))
                           (setq lst (cons (cons (vla-get-taborder i) (vla-get-name i)) lst)))
                          '(lambda (x y) (< (car x) (car y))))))
 (while lst
  (vla-put-taborder (vla-item lays (cdar lst))
                    (setq lst (cdr lst)
                          ctr (1- ctr)))))

rev_tab_order_fixed.gif 

Message 7 of 9

kenhuse
Contributor
Contributor
Ranjit, Thanks. Right now I'm in the midst of something else and have a
slew of drawings open so I'm unable to give it the full test. I tried it
out and my computer froze and I hit escape. Tomorrow morning 1st thing
Alaska time I'll give it another go.
Before I hit escape I saw my 1st layout at the end of the layouts so I'm
hopeful! You're tenacious! Great work and Thanks again, Ken
0 Likes
Message 8 of 9

kenhuse
Contributor
Contributor

Ranjit! You are awesome! Amazing. You've saved me an incredible amount of work! Thanks so much. I will sing praise for you Ranjit!

0 Likes
Message 9 of 9

Ranjit_Singh
Advisor
Advisor

I am glad it's working for you Smiley Happy

0 Likes