ActiveViewport Property (ActiveX)

Specifies the active viewport for the drawing.

Supported platforms: Windows only

Signature

VBA:

object.ActiveViewport
object

Type: Document

The object this property applies to.

Property Value

Read-only: No

Type: Viewport

The active viewport for the drawing.

Remarks

Changes made to the current active viewport will become visible only after you reset the viewport as the active viewport. To reset the active viewport, simply call this property with the updated viewport object.

Use the StatusID property to determine if a viewport is currently active.

You can iterate through existing viewports to find a particular viewport. To do this, first identify the name of the viewport configuration on which the desired viewport resides using the Name property. Additionally, if the viewport configuration has been split, each individual viewport on the configuration can be identified through the LowerLeftCorner and UpperRightCorner properties.

The LowerLeftCorner and UpperRightCorner properties represent the graphic placement of the viewport on the display. These properties are defined as follows (using a four-way split as an example):



Viewport 1—LowerLeftCorner = (0, .5), UpperRightCorner = (.5, 1)

Viewport 2—LowerLeftCorner = (.5, .5), UpperRightCorner = (1, 1)

Viewport 3—LowerLeftCorner = (0, 0), UpperRightCorner = (.5, .5)

Viewport 4—LowerLeftCorner = (.5, 0), UpperRightCorner = (1, .5)

Examples

VBA:

Sub Example_ActiveViewport()
    ' This example returns the current viewport.
    ' It creates a new viewport and makes it active, and
    ' Then it splits the viewport into four windows.
    ' It then takes one of the four windows, and splits that
    ' window horizontally into half.
    Dim currViewport As AcadViewport
    Dim newViewport As AcadViewport
    
    ' Returns current viewport of active document
    Set currViewport = ThisDrawing.ActiveViewport
    MsgBox "The current viewport is " & currViewport.name, vbInformation, "ActiveViewport Example"
    
    ' Create a new viewport and make it active
    Set newViewport = ThisDrawing.Viewports.Add("TESTVIEWPORT")
    ThisDrawing.ActiveViewport = newViewport
    MsgBox "The new active viewport is " & newViewport.name, vbInformation, "ActiveViewport Example"
    
    ' Split the viewport in four windows
    newViewport.Split acViewport4
    
    ' Make the newly split viewport active
    ThisDrawing.ActiveViewport = newViewport
    
    ' Note that current drawing layout will show four windows.
    ' However, only one of the windows will be active.
    ' The following code sets the lower-left corner window
    ' to be the active window and then splits that
    ' window into two horizontal windows.
    Dim entry
    For Each entry In ThisDrawing.Viewports
        If entry.name = "TESTVIEWPORT" Then
            Dim lowerLeft
            lowerLeft = entry.LowerLeftCorner
            If lowerLeft(0) = 0 And lowerLeft(1) = 0 Then
                Set newViewport = entry
                Exit For
            End If
        End If
    Next

    newViewport.Split acViewport2Horizontal
    ThisDrawing.ActiveViewport = newViewport
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_ActiveViewport()
    ;; This example returns the current viewport.
    ;; It creates a new viewport and makes it active, and
    ;; Then it splits the viewport into four windows.
    ;; It then takes one of the four windows, and splits that
    ;; window horizontally into half.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    
    ;; Returns current viewport of active document
    (setq currViewport (vla-get-ActiveViewport doc))
    (alert (strcat "The current viewport is " (vla-get-Name currViewport)))
    
    ;; Create a new viewport and make it active
    (setq viewports (vla-get-Viewports doc))
    (setq newViewport (vla-Add viewports "TESTVIEWPORT"))
    (vla-put-ActiveViewport doc newViewport)
    (alert (strcat "The new active viewport is " (vla-get-Name newViewport)))
    
    ;; Split the viewport in four windows
    (vla-Split newViewport acViewport4)
    
    ;; Make the newly split viewport active
    (vla-put-ActiveViewport doc newViewport)
    
    ;; Note that current drawing layout will show four windows.
    ;; However, only one of the windows will be active.
    ;; The following code sets the lower-left corner window
    ;; to be the active window and then splits that
    ;; window into two horizontal windows.
    (vlax-for each-viewport viewports
        (if (= (vla-get-Name each-viewport) "TESTVIEWPORT")
            (progn
                (setq lowerLeft (vla-get-LowerLeftCorner each-viewport))

                (if (and (= (vlax-safearray-get-element (vlax-variant-value lowerLeft) 0) 0)
                         (= (vlax-safearray-get-element (vlax-variant-value lowerLeft) 1) 0)
                    )
                    (setq newViewport each-viewport)
                )
            )
        )
    )
    (vla-Split newViewport acViewport2Horizontal)
    (vla-put-ActiveViewport doc newViewport)
)