Author Topic: Zoom All layouts  (Read 9643 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Zoom All layouts
« on: March 11, 2004, 11:10:35 PM »
I have seen this discussed somewhere and can not find it.

What I want to do is zoom extents in all layouts.
Here is my incomplete vlisp version and an attempt in plain lisp.
The plain version does zoom but does not inactivate the view ports.

Can someone fill in the blanks or show me where i went wrong?

Code: [Select]
(defun c:zat (/ lay);Zoom All Tabs
  (vl-load-com)
  (vlax-for lay
(vla-get-layouts
 (vla-get-activedocument
   (vlax-get-acad-object)
 )
)

    (if (eq :vlax-false (vla-get-modeltype lay))
      (princ); turn vp off here
    )
    (vla-zoomextents (vlax-get-acad-object))

  )
)

(defun c:ZAL (/ lay); Zoom All Layouts
  (setq count 0)
  (foreach lay (layoutlist)
    (setvar "ctab" lay)
    (if (and (= 1 (getvar "Tilemode")); in paper space
             (/= 1 (getvar "cvport")); vp is active
)
      (setvar "cvport" 1); inactivate the vp
    )
    (command ".zoom" "E")
  )
(princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
Zoom All layouts
« Reply #1 on: March 12, 2004, 07:34:26 AM »
Digest this:
Code: [Select]
;;;all these zooms can be invoked transparently.
;;;---------------------------------------------------------------------;
;;;GET-ACAD-OBJECT ;
;;; ;
;;;Description: This function will test if the global variable ;
;;; *current-acad-Object* is set. If it is, the current ;
;;; value is returned. Otherwise the value of the global ;
;;; variable *current-acad-object* is created. ;
;;; ;
;;;Arguments: (none) ;
;;; ;
;;;Returned Value: A vla acad object is returned, such as: ;
;;; #<VLA-OBJECT IAcadApplication 00ac9920> ;
;;; ;
;;;Usage (get-acad-object) ;
;;;_____________________________________________________________________;
(defun get-acad-object (/tmp)
     (cond (*current-acad-object* *current-acad-object*)
  ((and (setq tmp (vlax-get-acad-object))
   )
   (setq *current-acad-object* tmp)
  )
  (t nil)
     )
)
;;;---------------------------------------------------------------------;
;;;GET-ACTIVE-DOCUMENT ;
;;; ;
;;;Description: This function will test if the global variable ;
;;; *current-active-document* is set. If it is, the current ;
;;; value is returned. Otherwise the value of the global ;
;;; variable *current-active-document* is created. ;
;;; ;
;;;Arguments: (none) ;
;;; ;
;;;Returned Value: A vla acad object is returned, such as: ;
;;; #<VLA-OBJECT IAcadDocument 01514cf4> ;
;;; ;
;;;Usage (get-acad-object) ;
;;;_____________________________________________________________________;
(defun get-active-document (/ tmp)
     (cond (*current-active-document* *current-active-document*)
  ((and (setq tmp (vlax-get-acad-object))
(setq tmp (vla-get-activedocument tmp))
   )
   (setq *current-active-document* tmp)
  )
  (t nil)
     )
)
;;;---------------------------------------------------------------------;
;;;GET-MODEL-SPACE ;
;;; ;
;;;Description: This function will test if the global variable ;
;;; *current-model-space* is set. If it is, the current ;
;;; value is returned. Otherwise the value of the global ;
;;; variable *current-model-space* is created. ;
;;; ;
;;;Arguments: (none) ;
;;; ;
;;;Returned Value: A vla model space object is returned, such as: ;
;;; #<VLA-OBJECT IAcadModelSpace 027a34c0> ;
;;; ;
;;;Usage (get-model-space) ;
;;;_____________________________________________________________________;
(defun get-model-space (/ tmp)
     (cond (*current-model-space* *current-model-space*)
  ((and (setq tmp (vlax-get-acad-object))
(setq tmp (vla-get-activedocument tmp))
(setq tmp (vla-get-modelspace tmp))
   )
   (setq *current-model-space* tmp)
  )
  (t nil)
     )
)
;;;===================================================================;
;;; Force->ModelSpace                                                 ;
;;;-------------------------------------------------------------------;
;;; This will force the user back to Model Space if in Paper Space.   ;
;;;                                                                   ;
;;; Author: John Kaul                                                 ;
;;;                                                                   ;
;;; Usage: (Force->ModelSpace)                                        ;
;;;===================================================================;
(defun Force->ModelSpace ()
     (if (= 0
   (vla-get-Activespace
(vla-get-activedocument (vlax-get-acad-object))
   )
)
 (vla-put-ActiveSpace
      (vla-get-activedocument (vlax-get-acad-object))
      1
 )
     )
     (princ)
)
;;;---------------------------------------------------------------------;
;;;GET-PAPER-SPACE ;
;;; ;
;;;Description: This function will test if the global variable ;
;;; *current-paper-space* is set. If it is, the current ;
;;; value is returned. Otherwise the value of the global ;
;;; variable *current-paper-space* is created. ;
;;; ;
;;;Arguments: (none) ;
;;; ;
;;;Returned Value: A vla paper space object is returned, such as: ;
;;; #<VLA-OBJECT IAcadPaperSpace 027a34c0> ;
;;; ;
;;;Usage (get-paper-space) ;
;;;_____________________________________________________________________;
(defun get-paper-space (/ tmp)
     (cond (*current-paper-space* *current-paper-space*)
  ((and (setq tmp (vlax-get-acad-object))
(setq tmp (vla-get-activedocument tmp))
(setq tmp (vla-get-paperspace tmp))
   )
   (setq *current-paper-space* tmp)
  )
  (t nil)
     )
)
;;;===================================================================;
;;; Force->PaperSpace                                                 ;
;;;-------------------------------------------------------------------;
;;; This will force the user back to paperspace if in Model space.    ;
;;;                                                                   ;
;;; Author: John Kaul                                                 ;
;;;                                                                   ;
;;; Usage: (Force->PaperSpace)                                        ;
;;;===================================================================;
(defun Force->PaperSpace ()
     (if (= 1
   (vla-get-ActiveSpace
(vla-get-activedocument (vlax-get-acad-object))
   )
)
 (vla-put-ActiveSpace
      (vla-get-activedocument (vlax-get-acad-object))
      0
 )
     )
     (princ)
)
(defun *error* (msg)
     (if (not (member msg
     '("console break" "Function cancelled" "quit / exit abort")
     )
)
 (progn
      (princ (strcat "\nError: " msg))
 )
     )
     (princ "\nError: Function Cancelled. ")
     (princ)
)
(defun Utility ()
     (setq Utility (vla-get-utility
(vla-get-activedocument
    (vlax-get-acad-object)
    )
)
  )
     )
(vl-load-com)
(defun c:ze ()
(defun ZoomExtents ()
     (vla-ZoomExtents (vlax-get-acad-object))
)
     (if (= (vla-get-ActiveSpace (get-active-document)) 0) ; If in paperspace
 (cond
      ((and (= (vla-get-MSpace (get-active-document)) :vlax-True)
 ; in mspace viewport
    (= (vla-get-DisplayLocked
    (vla-Get-ActivePViewport (get-active-document))
)
:vlax-True
    ) ; Mspace viewport is locked
)
(vla-put-MSpace (get-active-document) :vlax-False)
(ZoomExtents)
(vla-put-MSpace (get-active-document) :vlax-True)
      )
      ((and (= (vla-get-MSpace (get-active-document)) :vlax-True)
 ; in mspace viewport
    (= (vla-get-DisplayLocked
    (vla-Get-ActivePViewport (get-active-document))
)
:vlax-False
    ) ; Mspace viewport is not locked
)
(ZoomExtents)
      )
      ((= (vla-get-MSpace (get-active-document)) :vlax-False)
(ZoomExtents)
      )
 )
 (ZoomExtents)
     )
     (princ)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Zoom All layouts
« Reply #2 on: March 12, 2004, 07:57:20 AM »
Thanks Daron,

I'll look this over as soon as i wake up :)

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Zoom All layouts
« Reply #3 on: March 12, 2004, 09:28:54 AM »
OK, Daron
Thanks for the help.. :)
See if this will do?
Anything jump out as incorrect?

Code: [Select]
(defun Zoom_All_Layouts (/ lay *doc*)
  (vl-load-com)
  (setq *doc* (vla-get-activedocument(vlax-get-acad-object)))
  (vlax-for lay (vla-get-layouts *doc*)        ; step through layouts
    (vla-put-activelayout *doc* lay)           ; activate layout
    (if (= (vla-get-activespace *doc*) 0)      ; If in paperspace
      (if (= (vla-get-mspace *doc*) :vlax-true); in mspace viewport
        (vla-put-mspace *doc* :vlax-false)     ; inactivate vp
      ); endif
    );endif
    (vla-zoomextents (vlax-get-acad-object))
  )
)
(defun c:zal ()
  (Zoom_All_Layouts)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
Zoom All layouts
« Reply #4 on: March 12, 2004, 09:49:57 AM »
I reworked it a little. No real changes. Just some things that Stig made me realize about having objects in a saved state as opposed to having to retrieve it each time. He used a metaphor of salt. Something along the lines of how long would it take to go to the store each time you need to use it as opposed to having it on hand and just using it. The only thing that stands out would be if you had a layout with an active modelspace viewport, you might want to reset it after zooming the viewport.
Code: [Select]
(defun zoom_all_layouts (/ lay *doc*)
     (vl-load-com)
     (setq *acad* (vlax-get-acad-object)
  *doc* (vla-get-activedocument *acad*)
  layouts (vla-get-layouts *doc*)
  )
     (vlax-for lay layouts ; step through layouts
 (vla-put-activelayout *doc* lay) ; activate layout
 (if (= (vla-get-activespace *doc*) 0) ; If in paperspace
      (if (= (vla-get-mspace *doc*) :vlax-true)
 ; in mspace viewport
   (vla-put-mspace *doc* :vlax-false) ; inactivate vp
      ) ; endif
 ) ;endif
 (vla-zoomextents *acad*)
     )
)
(defun c:zal ()
     (zoom_all_layouts)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Zoom All layouts
« Reply #5 on: March 12, 2004, 10:16:49 AM »
Hey, thanks for the clean up and the help.

CAB
« Last Edit: November 03, 2005, 03:35:02 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Zoom All layouts
« Reply #6 on: February 22, 2006, 04:50:46 PM »
FWIW,

I added

(defun c:zal (/ *acad* *doc* layouts ct lay)
  (vl-load-com)
  (setq   *acad*   (vlax-get-acad-object)
   *doc*   (vla-get-activedocument *acad*)
   layouts   (vla-get-layouts *doc*)
  )
  (setq ct (vla-get-activelayout *doc*))
  (vlax-for lay   layouts         ; step through layouts
    (vla-put-activelayout *doc* lay)   ; activate layout
    (if   (= (vla-get-activespace *doc*) 0) ; If in paperspace
      (if (= (vla-get-mspace *doc*) :vlax-true)
               ; in mspace viewport
   (vla-put-mspace *doc* :vlax-false) ; inactivate vp
      )               ; endif
    )               ;endif
    (vla-zoomextents *acad*)
  )
  (vla-put-activelayout *doc* ct)
)

so it returns back to the tab you started on.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Joe Burke

  • Guest
Re: Zoom All layouts
« Reply #7 on: February 23, 2006, 10:04:30 AM »
I reworked it a little. No real changes. Just some things that Stig made me realize about having objects in a saved state as opposed to having to retrieve it each time. He used a metaphor of salt. Something along the lines of how long would it take to go to the store each time you need to use it as opposed to having it on hand and just using it. The only thing that stands out would be if you had a layout with an active modelspace viewport, you might want to reset it after zooming the viewport.
Code: [Select]
(defun zoom_all_layouts (/ lay *doc*)
     (vl-load-com)
     (setq *acad* (vlax-get-acad-object)
  *doc* (vla-get-activedocument *acad*)
  layouts (vla-get-layouts *doc*)
  )
     (vlax-for lay layouts ; step through layouts
 (vla-put-activelayout *doc* lay) ; activate layout
 (if (= (vla-get-activespace *doc*) 0) ; If in paperspace
      (if (= (vla-get-mspace *doc*) :vlax-true)
 ; in mspace viewport
   (vla-put-mspace *doc* :vlax-false) ; inactivate vp
      ) ; endif
 ) ;endif
 (vla-zoomextents *acad*)
     )
)
(defun c:zal ()
     (zoom_all_layouts)
)

Daron,

Just curious. Are you saying this (vlax-for lay layouts... is more efficient
than this (vlax-for lay (vla-get-layouts *doc*)? If so, I disagree.

I think you add a variable which serves no purpose, and forgot to declare it
local to boot.

whdjr

  • Guest
Re: Zoom All layouts
« Reply #8 on: February 23, 2006, 10:54:49 AM »
Joe,

The reason Daron is saying (vlax-for lay layouts... is more efficient than (vlax-for lay (vla-get-layouts *doc*) is because the first example reads from a list a set variable 'layouts' whereas the second example is issueing a call to get the layouts from the *doc* variable each time which is more work than just calling and storing it once.

As far as not localizing 'layouts' I'm sure it was an oversight on Darons part.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Zoom All layouts
« Reply #9 on: February 23, 2006, 11:14:09 AM »
I haven't checked the vlax-for but the foreach function grabs the item to be processed at first pass
then does not go back to check them again. Test something like this
Code: [Select]
(setq lst '(1 2 3 4 5))
(foreach itm lst
  (setq lst nil)
  (print itm)
)
(1 2 3 4 5)

1
2
3
4
5 5
_$
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Zoom All layouts
« Reply #10 on: February 23, 2006, 12:38:38 PM »
Daron and Will,
Sorry,
CAB's original version was fine.

.. in fact Darons mods have made it less efficient by adding the saved variables.

The initialisation process in a for loop is processed ONCE only.

This can be demonstrated 2 ways

either as demonstrated by CAD above < nilling the variable > or by stepping through the code in the VLIDE debugger.

Try loading this with the debugger set to StopOnce and BreakOnError. When you enter TEST at the command line you will be able to StepInto using () on the toolbar or F8.
Code: [Select]
(defun c:test ()
  (setq *AcadLayers
         (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
  )
  (vlax-for item *AcadLayers
    (setq *AcadLayers nil)
    (princ (vla-get-name item))
    (terpri)
  )
)


added:
If the variables *acad* or *layouts* were used several times throughout the routine they WOULD be worthwhile saves as local variables. .. BUT not just because of their use in a FOR loop.
« Last Edit: February 23, 2006, 12:43:50 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

whdjr

  • Guest
Re: Zoom All layouts
« Reply #11 on: February 23, 2006, 02:34:24 PM »
So you are saying in a for loop it only accesses the collection once so

doing it this way
Code: [Select]
(defun c:test ()
  (vlax-for item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (princ (vla-get-name item))
    (terpri)
  )
)

is actually better than this way?
Code: [Select]
(defun c:test ()
  (setq *AcadLayers
         (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
  )
  (vlax-for item *AcadLayers
    (setq *AcadLayers nil)
    (princ (vla-get-name item))
    (terpri)
  )
)

I always thought it looked at the collection each time... :-(

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Zoom All layouts
« Reply #12 on: February 23, 2006, 02:49:26 PM »
Quote
So you are saying in a for loop it only accesses the collection once so ....


Yes,
The initialiser and the indexer < the symbol 'item' in this case> are both forced internally local to the For loop block.
.. trying to access the variable 'item' after the loop is run will demonstrate this.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Serge J. Gianolla

  • Guest
Re: Zoom All layouts
« Reply #13 on: February 23, 2006, 02:52:42 PM »
Do you ever sleep, Kerry? :-o

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Zoom All layouts
« Reply #14 on: February 23, 2006, 02:55:16 PM »
Yep, It's light outside . The day is wasting away ...    :lol:
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Zoom All layouts
« Reply #15 on: February 23, 2006, 02:59:39 PM »
It's daylight in Sydney too, yes ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Serge J. Gianolla

  • Guest
Re: Zoom All layouts
« Reply #16 on: February 23, 2006, 03:11:02 PM »
No, no finito in Sydney. Almost a year now that I live in same city as yours!
I am an early riser, but you are crazier than I am, well if that is ever possible. :laugh:

Joe Burke

  • Guest
Re: Zoom All layouts
« Reply #17 on: February 24, 2006, 09:35:59 AM »

added:
If the variables *acad* or *layouts* were used several times throughout the routine they WOULD be worthwhile saves as local variables. .. BUT not just because of their use in a FOR loop.


Kerry,

Well actually Daron is correct setting the *acad* variable.
(vla-zoomextents *acad*)

Compared to this which gets the acad object on each pass of the vlax-for loop.
(vla-zoomextents (vlax-get-acad-object))

While I'm nit-picking... this also indicates a misunderstanding of what's going on
in a vlax-for or foreach loop.

(defun zoom_all_layouts (/ lay *doc*)
  ...
  (vlax-for lay layouts...
 
The lay symbol is local to the vlax-for call. Declaring it local to the program is not needed.

I trust ya'll know it's not my intention to offend anyone. I just think when someone says,
"here's a cleand-up version of your code", it implies a lesson to be learned. If it fails
to do that, someone should say so. Otherwise misconceptions are handed down to others who may
take it as gospel.

Regards

whdjr

  • Guest
Re: Zoom All layouts
« Reply #18 on: February 24, 2006, 11:31:58 AM »
Thanks for the discussion here Joe.  I did learn some things I was not aware of.

Thanks,  :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Zoom All layouts
« Reply #19 on: February 24, 2006, 02:35:42 PM »
>>>
Well actually Daron is correct setting the *acad* variable.
(vla-zoomextents *acad*)
>>>.

Yes Joe, you're correct, I overlooked that somehow .  I got tied up with the FOR LOOP thingie I guess ...

>>>  Otherwise misconceptions are handed down to others who may
take it as gospel.

Regards

I agree.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.