Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Zoom Extents For All Tabs

78 REPLIES 78
Reply
Message 1 of 79
sadkuh
16317 Views, 78 Replies

Zoom Extents For All Tabs

I was hoping somebody may have something that can help me out. I'm currently working in a drawing that has 148 layout tabs and I frequently work in drawings with more tabs than that. when I switch tabs, I like to see everything in the tab. Is there a lisp that will do a zoom extents in every tab so I don't have to manually do it all the time?
Thank you in advance!!
78 REPLIES 78
Message 2 of 79
_gile
in reply to: sadkuh

Hi,

Here's a quicky

{code}(defun c:ZEA (/ acad acdoc aclay)
(setq acad (vlax-get-acad-object)
acdoc (vla-get-ActiveDocument acad)
aclay (vla-get-ActiveLayout acdoc)
)
(vlax-for layout (vla-get-Layouts acdoc)
(vla-put-ActiveLayout acdoc layout)
(vla-ZoomExtents acad)
)
(vla-put-ActiveLayout acdoc aclay)
(princ)
){code}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 79
sadkuh
in reply to: sadkuh

Thank you for the code but can you please tell me how to use this? I'm familiar with making buttons and adding code into the macro section but that’s also similar to lisp and I’ve made lisps to load with AutoCAD but I'm not familiar how to use what you posted above. Thank you
Message 4 of 79
_gile
in reply to: sadkuh

Paste the code in windows notepad, save it with .lsp extension, load the LISP file in AutoCAD with APPLOAD command (you can add it to the startup), enter ZEA at command prompt or make a button (macro = ^C^Czea;).

I forgot to add (vl-load-com) in previous code, so copy the following one.

{code}(defun c:ZEA (/ acad acdoc aclay)
(vl-load-com)
(setq acad (vlax-get-acad-object)
acdoc (vla-get-ActiveDocument acad)
aclay (vla-get-ActiveLayout acdoc)
)
(vlax-for layout (vla-get-Layouts acdoc)
(vla-put-ActiveLayout acdoc layout)
(vla-ZoomExtents acad)
)
(vla-put-ActiveLayout acdoc aclay)
(princ)
){code}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 79
sadkuh
in reply to: sadkuh

life saver, thank you. Just saved me a good few hours.
Message 6 of 79
sadkuh
in reply to: sadkuh

I tested it on a smaller drawing and it worked fine but I'm having problems with the drawing it was intended for. The drawing has about 146 layout tabs. To give more detail.....

Tab 1 has 2 vports, each showing a different zoomed out profile.
Tabs 2 & 3 have 1 vport each, showing a zoom up of the profiles from Tab 1.
Tab 4 has 2 vports, each showing a different zoomed out profile.
Tabs 5 & 6 have 1 vport each, showing a zoom up of the profiles from Tab 4

It's the same pattern for the whole drawing. 97 sections show in 146 layout tabs. All layouts are locked. When I run that lisp, it does a zoom extents within the vports, not the whole layout tab. It happens with some of the vports, not all of them. The vports that had the zoom extents are locked again after the lisp is done. I have double checked and the vports that have changed were locked before running the lisp. any idea? The drawing is 9 megs unzipped and 7.8 zipped, not sure if it can be posted.

Any ideas?
Message 7 of 79
johnw
in reply to: sadkuh

I tried this routine and the same thing happened to me. I realized that whatever viewport is active (meaning your cross-hairs are in model space of that viewport) zooms extents. I think that is why certain viewports inside the layout are zooming out as you say. I hope this helps in "solving" this lisp routine issue. I need it for my DWF creation since whenever I create a DWF and view it, the sheets 'save' whatever zoom factor I was at in the drawing, rather than showing the entire sheet (like a PDF does).

 

John

Message 8 of 79
Kent1Cooper
in reply to: johnw


@Johnw wrote:

I tried this routine and the same thing happened to me. I realized that whatever viewport is active (meaning your cross-hairs are in model space of that viewport) zooms extents. I think that is why certain viewports inside the layout are zooming out as you say. I hope this helps in "solving" this lisp routine issue. I need it for my DWF creation since whenever I create a DWF and view it, the sheets 'save' whatever zoom factor I was at in the drawing, rather than showing the entire sheet (like a PDF does).

 

John


Here's what I use, which does the Limits rather than the Extents.  The Pspace command in it forces it out of any viewport you may be in, in a given layout.

 

;;  ZoomLimitsAllLayouts.lsp [command name: ZLAL]
;;  To get into all Layouts, go to Paper Space in and Zoom to the Limits for each,
;;  ending in Model Space and Zooming to the Limits there also.
;;  Kent Cooper, February 2011
(defun C:ZLAL ()
  (foreach lay (layoutlist)
    (setvar 'ctab lay)
    (command "_.pspace" "_.zoom" (getvar 'limmin) (getvar 'limmax))
  ); end foreach
  (setvar 'ctab "Model")
  (command "_.zoom" (getvar 'limmin) (getvar 'limmax))
); end defun

 

This should do the same for the Extents [untested]:

 

;;  ZoomExtentsAllLayouts.lsp [command name: ZEAL]
;;  To get into all Layouts, go to Paper Space in and Zoom to the Extents for each,
;;  ending in Model Space and Zooming to the Extents there also.
;;  Kent Cooper, November 2011
(defun C:ZEAL ()
  (foreach lay (layoutlist)
    (setvar 'ctab lay)
    (command "_.pspace" "_.zoom" "_extents")
  ); end foreach
  (setvar 'ctab "Model")
  (command "_.zoom" "_extents")
); end defun

Kent Cooper, AIA
Message 9 of 79
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:
....

Here's what I use, which does the Limits .... 

This should do the same for the Extents ....


I worked up more sophisticated versions of those ZLAL [Zoom-Limits-All-Layouts] and ZEAL [Zoom-Extents-All-Layouts] commands [two commands in one ZoomAllLayouts.lsp file].  They turn off command echoing, and suppress the "About to regenerate -- proceed?" message if needed.

Kent Cooper, AIA
Message 10 of 79
johnw
in reply to: Kent1Cooper

I found out through a collegue of mine that if you add the following line to the original routine, ZEA, it will put you in paperspace at each tab before zooming extents that way it won't effect the viewport zooming that was a problem in the original code.

 

(defun C:ZEA (/ acad acdoc aclay)  

(setq acad (vlax-get-acad-object)

      acdoc (vla-get-ActiveDocument acad)      

      aclay (vla-get-ActiveLayout acdoc)

 ); setq

;; Modified by Bob Shaw 10-Nov-2011 for John Wagner at Davis Bews Design Group

 (vlax-for layout (vla-get-Layouts acdoc)

  (vla-put-ActiveLayout acdoc layout)

   (if (/= "Model" (getvar "ctab"))

    (progn     

        (command "_pspace")     

        (princ)    

        (vla-ZoomExtents acad)    

    ); progn

   ); if

 ); vlax-for   

(vla-put-ActiveLayout acdoc aclay)   

(princ)

); function

Message 11 of 79
Lee_Mac
in reply to: johnw

Here's another way:

 

(defun c:zea ( / acapp acdoc aclay )
    (setq acapp (vlax-get-acad-object)
          acdoc (vla-get-activedocument acapp)
          aclay (vla-get-activelayout acdoc)
    )
    (vlax-for layout (vla-get-layouts acdoc)
        (vla-put-activelayout acdoc layout)
        (if (eq acpaperspace (vla-get-activespace acdoc))
            (vla-put-mspace acdoc :vlax-false)
        )
        (vla-zoomextents acapp)
    )
    (vla-put-activelayout acdoc aclay)
    (princ)
)
(vl-load-com) (princ)

 

Message 12 of 79
Kent1Cooper
in reply to: johnw


@Johnw wrote:

.... if you add the following line to the original routine, ZEA, it will put you in paperspace at each tab before zooming extents that way it won't effect the viewport zooming that was a problem in the original code.

....


Yes, that's what was different about my earlier post from the original: the inclusion of the Pspace command.

 

Since it appears you're not including Model Space, you can accomplish it with as little as this:
 

(defun C:ZEAL ()
  (foreach lay (layoutlist)
    (setvar 'ctab lay)
    (command "_.pspace" "_.zoom" "_extents")
  ); foreach

); defun

 

Or if you want to return to the initial Layout:

 

(defun C:ZEAL (/ lyt)

  (setq lyt (getvar 'ctab))
  (foreach lay (layoutlist)
    (setvar 'ctab lay)
    (command "_.pspace" "_.zoom" "_extents")
  ); foreach

  (setvar 'ctab lyt)

); defun

Kent Cooper, AIA
Message 13 of 79
msarqui
in reply to: Kent1Cooper

Hi, 

 

I tested all of these routines and they worked very well. The problem is that my computer took 5 or 6 minutes to complete each one in a drawing with 53 layout tabs. 

I wonder if there is a way to turn off REGENAUTO for the tabs, during the execution of the routine so that the execution could be faster? At the end we would need only to do REGENALL.

 

Thanks!

 

Message 14 of 79
Kent1Cooper
in reply to: msarqui


@msarqui wrote:

....

I tested all of these routines and they worked very well. The problem is that my computer took 5 or 6 minutes to complete each one in a drawing with 53 layout tabs. 

I wonder if there is a way to turn off REGENAUTO for the tabs, during the execution of the routine so that the execution could be faster? At the end we would need only to do REGENALL.

....


I can't find anything in Help to confirm it directly, but I believe that Zooming to the Extents always forces a regeneration, anyway.  [It does say that for Zoom All, and it lists both Zoom All and Zoom Extents as updating the EXTMIN & EXTMAX System Variables, which I believe REGEN also does.]  If that's correct, I don't think the REGENAUTO command or REGENMODE System Variable would help.  And it would argue for using the Zoom Limits version instead of the Zoom Extents version, if you can, because that won't cause a regeneration unless you're starting zoomed in very close.

Kent Cooper, AIA
Message 15 of 79
poulosekutty0
in reply to: _gile

hi i Run the LISP and is working fine to do ZoomExtends. But How do i make the lisp run evry time i open a document.? Is there a way?

Message 16 of 79
poulosekutty0
in reply to: _gile

HI I tried this code and is working. But I want to work on Model Space rather than paperspace. Can u give me code to do the above on theModel Space or switch to modelspace at the end
Message 17 of 79

I've been using this lisp for several years

 

(defun c:zea ( / acapp acdoc aclay )
    (setq acapp (vlax-get-acad-object)
          acdoc (vla-get-activedocument acapp)
          aclay (vla-get-activelayout acdoc)
    )
    (vlax-for layout (vla-get-layouts acdoc)
        (vla-put-activelayout acdoc layout)
        (if (eq acpaperspace (vla-get-activespace acdoc))
            (vla-put-mspace acdoc :vlax-false)
        )
        (vla-zoomextents acapp)
    )
    (vla-put-activelayout acdoc aclay)
    (princ)
)
(vl-load-com) (princ)

Jonathan Norton
Blog | Linkedin
Message 18 of 79
zph
Collaborator
in reply to: Lee_Mac

Is there a way to suppress the "Restoring cached viewports - Regenerating layout." from displaying in the command line?

 

I like to see my recent cmd line history.  Even in a smaller drawing files, this routine spams the cmd line.

 

EDIT:  I tried this, but was unsuccessful...

 

(defun *error* (msg)
 (if (member msg  '("Restoring cached viewports - Regenerating layout." ))
  (princ)
 ) ;if
) ;*error*

Message 19 of 79
danglar
in reply to: zph

probably if we set the variable maxactvp to 2 during execution of these routines we can avoid force regeneration in zoom extens procedure?

Message 20 of 79
zph
Collaborator
in reply to: danglar

Tried that, but didn't change the cmd line spam.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost