Next/Previous layout then Zoom all Lisp

Next/Previous layout then Zoom all Lisp

Vuxvix
Advocate Advocate
1,116 Views
10 Replies
Message 1 of 11

Next/Previous layout then Zoom all Lisp

Vuxvix
Advocate
Advocate

Hi!
I have this lisp to next or previous layout.

I want to add the command “zoom all”. Can someone help!?

Thanks

(defun c:++ ( / l n )
   (setq l (getorderedlayouts)
         n (length l)
   )
   (setvar 'ctab (nth (rem (1+ (vl-position (getvar 'ctab) l)) n) l))
   (princ)
)

(defun c:-- (/ l n )
   (setq l (getorderedlayouts)
         n (length l)
   )
   (setvar 'ctab (nth (rem (+ n -1 (vl-position (getvar 'ctab) l)) n) l))
   (princ)
)

(defun getorderedlayouts (/ l )
   (vlax-for x (aclayouts)
       (setq l (cons (list (vla-get-taborder x) (vla-get-name x)) l))
   )
   (mapcar 'cadr (vl-sort l '(lambda ( a b ) (< (car a) (car b)))))
)

(defun aclayouts nil
   (eval
       (list 'defun 'aclayouts 'nil
           (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
       )
   )
   (aclayouts)
)

(vl-load-com) (princ)


 

0 Likes
Accepted solutions (1)
1,117 Views
10 Replies
Replies (10)
Message 2 of 11

Sea-Haven
Mentor
Mentor

Goto as name implies.

 

; GOTO layout just like other goto a page
; By Alan H 2013
; menu command [GOTO]^c^C^p(load "goto")
; enter a big number like 99 to jump to last if 100+ layouts then 123 etc
; Model space is 0 zero GOTO 0

(defun C:goto ( / x alllayouts laynum num)
 (if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq num (atoi (nth 0  (AH:getvalsm (list "Go To A Layout" "Enter layout number" 5 4 "1")))))
(setq alllayouts (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))))
(SETQ LAYNUM 0)
(vlax-for x alllayouts
(Setq laynum (+ 1 laynum))
) ;total number of layouts
(if (> num laynum)
(setq num (- laynum 1))
)
(vlax-for lay alllayouts
(if (= num (vla-get-taborder lay))
(setvar "ctab" (vla-get-name lay))
)
)
)

; I often type it wrong so added this one also
(defun C:goot ()
(c:goto)
) ; defun
Message 3 of 11

Vuxvix
Advocate
Advocate

Hi!

lisp you provided is the adv version. But what I'm looking for in this thread is: after moving to the next layout, the lisp can zoom-all. Thanks

0 Likes
Message 4 of 11

Kent1Cooper
Consultant
Consultant
Accepted solution

@Vuxvix wrote:

....

I want to add the command “zoom all”. Can someone help!?

.... 


In both the C:++ and C:-- definitions, add a line:

....

  (setvar 'ctab (nth (rem (1+ (vl-position (getvar 'ctab) l)) n) l))

  (command "_.zoom" "_all")
  (princ)

....

Kent Cooper, AIA
Message 5 of 11

Vuxvix
Advocate
Advocate

Thank you very much.

0 Likes
Message 6 of 11

Sea-Haven
Mentor
Mentor

Whilst Kent has given you the answer, should you use "Extents" rather than "All" if you have preset window ie ALL then you will not see junk that is outside the all window settings. Know from experience.

Message 7 of 11

Vuxvix
Advocate
Advocate

Hi! At first I chose all to make sure I didn't leave out any junk objects in the layout. I don't see any difference between extend and all in this case. Also, in the case when the previous session in a layout. you are into a viewport and that viewport is not locked. Then this lisp will zoom all in the viewport . Is there any way to fix this. Thanks

0 Likes
Message 8 of 11

Kent1Cooper
Consultant
Consultant

@Vuxvix wrote:

.... in the case when the previous session in a layout. you are into a viewport and that viewport is not locked. Then this lisp will zoom all in the viewport . Is there any way to fix this. ....


Add a PSPACE command before the ZOOM command.

Kent Cooper, AIA
Message 9 of 11

Vuxvix
Advocate
Advocate
I tried writing the first command line in my life. Luckily it works. I do not understand "." What does before the command (pspace, zoom...) mean?

(setvar 'ctab (nth (rem (+ n -1 (vl-position (getvar 'ctab) l)) n) l))
(command "_.PSPACE")
(command "_.zoom" "_all")
(princ)
0 Likes
Message 10 of 11

Kent1Cooper
Consultant
Consultant

The period prefix forces it to use the native AutoCAD command, in case the command has been undefined/redefined.  The underscore prefix makes the English command name work in AutoCAD for any language.

 

By the way, you can put more than one command into the same (command) function:

(command "_.PSPACE" "_.zoom" "_all")

Kent Cooper, AIA
Message 11 of 11

Vuxvix
Advocate
Advocate

This is very helpful to me. I can manually add a few commands to my lisp. Thank you so much

0 Likes