ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.CIM Namespace / CIMMapGrid Class
Members Example

In This Topic
    CIMMapGrid Class
    In This Topic
    Represents a grid object for a map frame.
    Object Model
    CIMMapGrid ClassCIMSymbolReference Class
    Syntax
    Example
    Apply a style to Grid and Graticules
    //Run within QueuedTask context.
    //Get the Style project items in the project
    var styleProjectItems = Project.Current?.GetItems<StyleProjectItem>();
    //Get the ArcGIS 2D Style Project Item
    var styleProjectItem = 
    styleProjectItems.OfType<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 2D");
    if (styleProjectItem == null) return;
    //Get the grid style item you need
    var gridStyleItem = 
    styleProjectItem.SearchSymbols(StyleItemType.Grid, "Blue Vertical Label Graticule").FirstOrDefault();
    if (gridStyleItem == null) return;
    var symbolItemName = gridStyleItem.Name;
    var girdGraticuleObject = gridStyleItem.GetObject() as CIMMapGrid;
    
    var mapFrame = layout.GetElements().OfType<MapFrame>().FirstOrDefault();
    var cmf = mapFrame.GetDefinition() as CIMMapFrame;
    //note, if page units are _not_ inches then grid's gridline
    //lengths and offsets would need to be converted to the page units
    var mapGrids = new List<CIMMapGrid>();
    if (cmf.Grids != null)
      mapGrids.AddRange(cmf.Grids);
    
    //var cimMapGrid = SymbolStyleItem.GetObject() as CIMMapGrid;
    
    switch (girdGraticuleObject)
    {
      case CIMGraticule:
        var gridGraticule = girdGraticuleObject as CIMGraticule;
        gridGraticule.Name = symbolItemName;
        gridGraticule.SetGeographicCoordinateSystem(mapFrame.Map.SpatialReference);
        //assign grid to the frame             
        mapGrids.Add(gridGraticule);
    
        break;
      case CIMMeasuredGrid:
        var gridMeasure = girdGraticuleObject as CIMMeasuredGrid;
        gridMeasure.Name = symbolItemName;
        gridMeasure.SetProjectedCoordinateSystem(mapFrame.Map.SpatialReference);
        //assign grid to the frame
        mapGrids.Add(gridMeasure);
    
        break;
      case CIMReferenceGrid:
        var gridReference = girdGraticuleObject as CIMReferenceGrid;
        gridReference.Name = symbolItemName;
        //assign grid to the frame
        mapGrids.Add(gridReference);
        break;
    }
    
    cmf.Grids = mapGrids.ToArray();
    mapFrame.SetDefinition(cmf);
    Apply a style to Grid and Graticules
    //Run within QueuedTask context.
    //Get the Style project items in the project
    var styleProjectItems = Project.Current?.GetItems<StyleProjectItem>();
    //Get the ArcGIS 2D Style Project Item
    var styleProjectItem = 
    styleProjectItems.OfType<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 2D");
    if (styleProjectItem == null) return;
    //Get the grid style item you need
    var gridStyleItem = 
    styleProjectItem.SearchSymbols(StyleItemType.Grid, "Blue Vertical Label Graticule").FirstOrDefault();
    if (gridStyleItem == null) return;
    var symbolItemName = gridStyleItem.Name;
    var girdGraticuleObject = gridStyleItem.GetObject() as CIMMapGrid;
    
    var mapFrame = layout.GetElements().OfType<MapFrame>().FirstOrDefault();
    var cmf = mapFrame.GetDefinition() as CIMMapFrame;
    //note, if page units are _not_ inches then grid's gridline
    //lengths and offsets would need to be converted to the page units
    var mapGrids = new List<CIMMapGrid>();
    if (cmf.Grids != null)
      mapGrids.AddRange(cmf.Grids);
    
    //var cimMapGrid = SymbolStyleItem.GetObject() as CIMMapGrid;
    
    switch (girdGraticuleObject)
    {
      case CIMGraticule:
        var gridGraticule = girdGraticuleObject as CIMGraticule;
        gridGraticule.Name = symbolItemName;
        gridGraticule.SetGeographicCoordinateSystem(mapFrame.Map.SpatialReference);
        //assign grid to the frame             
        mapGrids.Add(gridGraticule);
    
        break;
      case CIMMeasuredGrid:
        var gridMeasure = girdGraticuleObject as CIMMeasuredGrid;
        gridMeasure.Name = symbolItemName;
        gridMeasure.SetProjectedCoordinateSystem(mapFrame.Map.SpatialReference);
        //assign grid to the frame
        mapGrids.Add(gridMeasure);
    
        break;
      case CIMReferenceGrid:
        var gridReference = girdGraticuleObject as CIMReferenceGrid;
        gridReference.Name = symbolItemName;
        //assign grid to the frame
        mapGrids.Add(gridReference);
        break;
    }
    
    cmf.Grids = mapGrids.ToArray();
    mapFrame.SetDefinition(cmf);
    Inheritance Hierarchy

    System.Object
       ArcGIS.Core.CIM.CIMObject
          ArcGIS.Core.CIM.CIMMapGrid
             ArcGIS.Core.CIM.CIMCustomGrid
             ArcGIS.Core.CIM.CIMGraticule
             ArcGIS.Core.CIM.CIMMeasuredGrid
             ArcGIS.Core.CIM.CIMReferenceGrid

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also