ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / GridOptions Class / SetGridSpacing Method
The spacing is assumed to be in 'spacing units'
The spacing units
Example

In This Topic
    SetGridSpacing Method
    In This Topic
    Sets the grid spacing and grid spacing units
    Syntax
    Public Sub SetGridSpacing( _
       ByVal spacing As Double, _
       ByVal spacingUnit As LinearUnit _
    ) 
    public void SetGridSpacing( 
       double spacing,
       LinearUnit spacingUnit
    )

    Parameters

    spacing
    The spacing is assumed to be in 'spacing units'
    spacingUnit
    The spacing units
    Exceptions
    ExceptionDescription
    The unit is is not a supported unit for use with spacing
    Remarks
    Spacing is assumed to be in the units specified by spacingUnit. GetGridSpacing will return the spacing value in the specified units. This also controls the units for how the spacing value is displayed on the grid settings UI. The input spacingUnit must be one of the Project distance units (specified in the Pro backstage options settings)
    Example
    Set Various Grid Option parameters for GridOptions for a Map
    {
        var center_pt = MapView.Active.Extent.Center;
        var width = MapView.Active.Extent.Width;
        var height = MapView.Active.Extent.Height;
        var qtr_width = width * 0.25;
        var qtr_ht = height * 0.25;
    
        QueuedTask.Run(() =>
        {
            //use defaults
            var gridOptions = GridOptionsEnvironment.Instance.DefaultGridOptions;
    
            //customize the options as needed
            gridOptions.RotateWithMap = !gridOptions.RotateWithMap;
            gridOptions.GridLineColor = ColorFactory.Instance.RedRGB;
    
            var gs_rotation = gridOptions.GetGridRotation();
            gridOptions.SetGridRotation(gs_rotation * 1.5);
    
            var gs_meters = gridOptions.GetGridSpacingMeters();
            var gs_in_spacing_units = gridOptions.GetGridSpacing();
            var gs_units = gridOptions.GridSpacingUnits;
    
            //meters assumed
            gridOptions.SetGridSpacingInMeters(gs_meters + 10);
            //specify units explicitly
            gridOptions.SetGridSpacing(1000, LinearUnit.Feet);//internally will be converted to meters
    
            gridOptions.IsGridLines = true;//use lines (default)
    
            var grid_interval = gridOptions.GridMajorInterval;
    
            gridOptions.SnapToGridEnabled = true;
    
            var x1 = center_pt.X - qtr_width;
            var y1 = center_pt.Y + qtr_ht;
            gridOptions.SetGridOrigin(new Coordinate2D(x1, y1));
            //To apply changes, the gridoptions must be set back on the map
            GridOptionsEnvironment.Instance.SetGridOptions(map, gridOptions);
        });
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.7 or higher.
    See Also