SetView Method (ActiveX)

Sets the view in a viewport to a saved view in the Views collection object.

Supported platforms: Windows only

Signature

VBA:

object.SetView View
object

Type: Viewport

The object this method applies to.

View

Access: Input-only

Type: View

The view to set.

Return Value (RetVal)

No return value.

Remarks

No additional remarks.

Examples

VBA:

Sub Example_SetView()
    ' This example creates a new view.
    ' It then changes the active viewport to
    ' the newly created view.
    
    ' Create a new view
    Dim viewObj As AcadView
    Set viewObj = ThisDrawing.Views.Add("TESTVIEW")
    
    ' Set the view characteristics
    viewObj.center(0) = 374: viewObj.center(1) = 313
    viewObj.Width = 450
    viewObj.Height = 354
    
    ' Get the current active viewport
    Dim viewportObj As AcadViewport
    Set viewportObj = ThisDrawing.ActiveViewport
    MsgBox "Change to the saved view.", , "SetView Example"
       
    ' Set the view in the viewport
    viewportObj.SetView viewObj
    ThisDrawing.ActiveViewport = viewportObj
        
    ThisDrawing.Regen True
    
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_SetView()
    ;; This example creates a new view.
    ;; It then changes the active viewport to
    ;; the newly created view.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))

    ;; Create a new view
    (setq viewObj (vla-Add (vla-get-Views doc) "TESTVIEW"))
    
    ;; Set the view characteristics
    (setq centerPoint (vlax-make-safearray vlax-vbDouble '(0 . 1)))
    (vlax-safearray-fill centerPoint '(374 313))
    (vla-put-Center viewObj centerPoint)
    (vla-put-Width viewObj 450)
    (vla-put-height viewObj 354)
    
    ; Get the current active viewport
    (setq viewportObj (vla-get-ActiveViewport doc))
    (alert "Change to the saved view.")
       
    ;; Set the view in the viewport
    (vla-SetView viewportObj viewObj)
    (vla-put-ActiveViewport doc viewportObj)
        
    (vla-Regen doc :vlax-true)
)