Digest this:
;;;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)
)