TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: cmwade77 on December 15, 2014, 07:42:38 PM

Title: Move Active Layout Tab to End
Post by: cmwade77 on December 15, 2014, 07:42:38 PM
I have found a lot of very complicated code for moving layout tabs, but I can't seem to find anything simple that shows me how to move the currently active layout tab to the end of the layout tabs. Can anyone help me out here? At least point me in the right direction with some simple code examples?
Title: Re: Move Active Layout Tab to End
Post by: ymg on December 15, 2014, 09:47:15 PM
cmwade77,

How about copy current layout, followed by a delete
then a set and finally a rename.

All this with the layout command,

ymg
Title: Re: Move Active Layout Tab to End
Post by: Rod on December 15, 2014, 10:54:01 PM
This seems to work. You will need to add in error checking to make sure the user is not in model space
Code - Auto/Visual Lisp: [Select]
  1. (defun C:putmelast ()
  2.   (setq acadObj (vlax-get-acad-object))
  3.   (setq doc (vla-get-ActiveDocument acadObj))
  4.   (setq layouts (vla-get-Layouts doc))
  5.   (setq ActiveLayout (vla-item layouts (getvar "CTAB")))
  6.   (vla-put-taborder activelayout (1- (vla-get-count layouts)))
  7. )
Title: Re: Move Active Layout Tab to End
Post by: ymg on December 16, 2014, 12:36:05 AM
I came up with this, but Ausrod solution is cleaner.

Code - Auto/Visual Lisp: [Select]
  1. (defun movctab ( )
  2.    
  3.    (setq    ctab (getvar "ctab")
  4.             layl (append (vl-remove ctab (layoutlist)) (list ctab))
  5.    )
  6.    (vlax-for tab layouts
  7.      (if (/= (setq name (vla-get-name tab)) "Model")
  8.         (vla-put-taborder tab (+ (vl-position (vla-get-name tab) layl) 1))
  9.      )
  10.    )  
  11. )
  12.  
  13.  

Ausrod's solution is essentially two lines:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:putmelast ( / layouts)  
  2.    (vla-put-taborder (vla-item layouts (getvar "CTAB")) (1- (vla-get-count layouts)))
  3. )
  4.  
Title: Re: Move Active Layout Tab to End
Post by: Tharwat on December 16, 2014, 12:36:33 AM
Try this .

Code - Auto/Visual Lisp: [Select]
  1. (defun c:GoLast (/ l)
  2.   ;;    Tharwat 16.Dec.2014     ;;
  3.   (if (and (< 2
  4.               (vla-get-count
  5.                 (setq l (vla-get-Layouts
  6.                           (vla-get-ActiveDocument (vlax-get-acad-object))
  7.                         )
  8.                 )
  9.               )
  10.            )
  11.            (eq 0 (getvar 'TILEMODE))
  12.       )
  13.       (vla-item l (getvar 'CTAB))
  14.       (1- (vla-get-count l))
  15.     )
  16.     (princ "\n ** Commnad is not allowed in Model Space **")
  17.   )
  18.   (princ)
  19.  
Title: Re: Move Active Layout Tab to End
Post by: Patrick_35 on December 16, 2014, 02:22:57 AM
Hi

And my example
Code: [Select]
(defun c:test(/ doc)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark doc)
  (vl-catch-all-apply 'vla-put-taborder (list (vla-get-activelayout doc) (1- (vla-get-count (vla-get-layouts doc)))))
  (vla-endundomark doc)
  (princ)
)

@+
Title: Re: Move Active Layout Tab to End
Post by: Tharwat on December 16, 2014, 02:26:19 AM
@ Patrick
Try your codes while you are in Model space . :wink:
Title: Re: Move Active Layout Tab to End
Post by: Patrick_35 on December 16, 2014, 03:16:18 AM
@ Patrick
Try your codes while you are in Model space . :wink:
Oh yes, but as we asked for the active layout
The code is modified according to your point