GridOn Property (ActiveX)

Specifies the status of the viewport grid.

Supported platforms: Windows only

Signature

VBA:

object.GridOn
object

Type: PViewport, Viewport

The objects this property applies to.

Property Value

Read-only: No

Type: Boolean

Remarks

The grid is used only for visual reference. It is not plotted, nor is it considered part of the drawing. The grid origin is set by the SnapBasePoint method.

When the grid is turned on, it is set to the current grid spacing. To change the grid spacing, use the SetGridSpacing method.

When you turn the grid on or off on a viewport, the visibility of the grid will not change until the viewport is made active. If you toggle the grid of the active viewport, the visibility of the grid will not change until the viewport is reset as the active viewport. To set or reset the viewport as the active viewport, use the ActiveViewport property with the updated viewport object.

Note: The value of this property is stored in the GRIDMODE system variable. When using the SetVariable method to update the grid mode of the active viewport, you do not have to reset the viewport as the active viewport to see the change.

Examples

VBA:

Sub Example_GridOn()
    ' This example toggles the setting of GridOn.
    
    Dim viewportObj As AcadViewport
    
    ' Set the viewportObj variable to the activeviewport
    Set viewportObj = ThisDrawing.ActiveViewport

TOGGLEGRID:
    If MsgBox("Toggle the grid?", vbOKCancel, "GridOn Example") = vbOK Then
        viewportObj.GridOn = Not (viewportObj.GridOn)
    Else
        Exit Sub
    End If
    
    ' Reset the active viewport to see the change
    ThisDrawing.ActiveViewport = viewportObj
    
    GoTo TOGGLEGRID
    
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_GridOn()
    ;; This example toggles the setting of GridOn.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))    
    
    ;; Set the viewportObj variable to the activeviewport
    (setq viewportObj (vla-get-ActiveViewport doc))

    (vla-put-GridOn viewportObj (if (= (vla-get-GridOn viewportObj) :vlax-true) :vlax-false :vlax-true))

    ;; Reset the active viewport to see the change
    (vla-put-ActiveViewport doc viewportObj)
    (vla-Regen doc acAllViewports)
  
    (alert "Toggled the display of the grid.")  
)