Grid (arcpyproduction.mapping)
This topic applies to ArcGIS for Desktop Standard and ArcGIS for Desktop Advanced only.
Summary
The Grid object provides access to grid properties for a grids and graticules layer. A reference to the Grid object is often used as an argument for functions to access grid properties.
Discussion
The Grid object provides access to important properties of a grid, which is created using the Make Grids And Graticules Layer geoprocessing tool or the Grids and Graticules Designer. The ListGrids function can be used to return a list of the Grid objects in a feature dataset.
Properties
Property | Explanation | Data Type |
layer (Read Only) |
Returns the group layer that is created from the Grid object. The group layer contains all grid subcomponents as sublayers. This is the same as the output group layer from the Make Grids And Graticules Layer geoprocessing tool. | Layer |
name (Read Only) | Returns the name of the Grid object. The name for the cartographic grid may not be the name of the layer. The name allows for distinction between grids that are stored in the same feature dataset and set of feature classes. | String |
type (Read Only) | Returns the type associated with the Grid object. All grids of the same type will have the same appearance. Type defines a style of grid, map product, or series. It is the string value set in the grid template file when it is designed. | String |
Method Overview
Method | Explanation |
updateDataFrameProperties (data_frame) |
Updates the coordinate system, rotation, scale, data frame size, and shape based on the properties and values stored in the Grid object. |
Methods
Parameter | Explanation | Data Type |
data_frame |
A reference to a DataFrame object within a map document. | DataFrame |
This method provides functionality that is equivalent to the Grid Layout tool. It is used to ensure that the key cartographic data frame properties match the grid, thus enforcing the map display to show shapes, sizes, and measurements as intended based on the grid design.

To run this function, the .mxd must be in layout view and the data frame must be projected.

This method changes the data frame properties. To preserve the changes, the .mxd must be saved or copied.
The following example updates the .mxd file's data frame properties based on those in the RotationScaleGCS grid object.
import arcpy
import arcpyproduction
# Check out Production Mapping extension
arcpy.CheckOutExtension("Foundation")
# Set the grid workspace and name
gridWorkspace = r'C:\Project\Grids\GridsUpdateDF.gdb\WGS84'
gridName = "RotationScaleGCS"
# Define the map document, data frame, and layout view
mxd = arcpy.mapping.MapDocument(r"C:\Project\Grids\GridsUpdateDFTest.mxd")
active_df = mxd.activeDataFrame
mxd.activeView = "PAGE_LAYOUT"
# Update data frame using the properties of the RotationScaleGCS grid
# and save results in a new .mxd
Rotationgrid = arcpyproduction.mapping.ListGrids(gridWorkspace, gridName)
if Rotationgrid[0].name == gridName:
Rotationgrid[0].updateDataFrameProperties(active_df)
mxd.saveACopy(r"C:\Project\Grids\UpdateResults.mxd")
else:
print "Error Obtaining Grid "+ gridName
# Check in extension
arcpy.CheckInExtension("Foundation")
Code Sample
The following script will read the name and type properties of grids in an existing workspace and delete the grids from the workspace using the properties as parameters in the Delete Grids and Graticules geoprocessing tool.
import arcpy
import arcpyproduction
# Check out Production Mapping extension
arcpy.CheckOutExtension('foundation')
# Set the grid workspace
grid_dataset = r"C:\Project\Grids.gdb\WGS84"
# Get the list of grids in the workspace
lstGrids = arcpyproduction.mapping.ListGrids(grid_dataset)
# Loop through the list of grids and delete each grid
# Delete Grids And Graticules accepts grid name and type as a second parameter
# The second parameter format is <grid name> (<grid type>)
for grid in lstGrids:
grid_name = grid.name
grid_type = grid.type
arcpy.DeleteGridsAndGraticules_cartography(grid_dataset, grid_name + ' (' + grid.type + ')')
# Check in extension
arcpy.CheckInExtension('foundation')