Jump to content

Save and restore current view


ziele_o2k

Recommended Posts

Hi all,

 

Maybe someone know better lisp (without command) that will save current view and restore it.

 

(defun c:foo 
    (   / 
        pz:SaveView pz:RestoreView
        *pz:Model-p
        old_cmd
    )
    
    (setq old_cmd (getvar 'cmdecho))
    (setvar 'cmdecho 0)
    
    (defun pz:SaveView nil
        (if (= (getvar 'ctab) "Model")
            (setq *pz:Model-p T)
        )
        (command "_view" "_save" "TMP_VIEW_PZ")
    )
    (defun pz:RestoreView nil
        (if *pz:Model-p (setvar 'ctab "Model"))
        (command "_view" "_restore" "TMP_VIEW_PZ")
        (command "_view" "_delete" "TMP_VIEW_PZ")
    )
    
    ;save current view
    (pz:SaveView)
    
    ;; do something
    (if (= (getvar 'ctab) "Model")
        (setvar 'ctab (car (layoutlist)))
        (setvar 'ctab "Model")
    )
    (alert "Current tab switched")
    
    ;restore current view
    (pz:RestoreView)
    (alert "Current tab and view restored to previous")
    (setvar 'cmdecho old_cmd)
    (princ)
)

 

Edited by ziele_o2k
Link to comment
Share on other sites

First check if CVPORT=2 (Model space or Model space window active in Paper space). Try this:

(setq ACDC    	(vla-get-activedocument (vlax-get-acad-object))
;;Save View
		ViewObj  (vla-add (vla-get-views ACDC) (itoa (getvar "MILLISECS")))
;;Save VPort
		AcVp     (vla-get-activeviewport ACDC)
;;Save VPort characteristics
		OldCen   (vla-get-center AcVp)
		OldDir   (vla-get-direction AcVp)
		OldHgt   (vla-get-height AcVp)
		OldWid   (vla-get-width AcVp)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
YOUR CODE HERE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Restore View
(vla-put-direction ViewObj OldDir)
(vla-put-center ViewObj OldCen)
(vla-put-height ViewObj OldHgt)
(vla-put-width ViewObj OldWid)
(vla-setview AcVp ViewObj)
(vla-put-activeviewport ACDC AcVp)
;;Delete View
(vla-delete ViewObj)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...