import pymel.core as pm
import maya.cmds as cmds
#To toggle the grid display of the grid (in all views):
currState = pm.grid( toggle=True, q=True )
pm.grid( toggle=(currState == 0) )
# To reset the grid to default values:
pm.grid( reset=True )
# To change the grid spacing and subdivisions:
pm.grid( spacing=10, d=10 )
# To set the defaults for inches
pm.grid( default=True, spacing='1in', size='1ft', divisions=4 )
# To change the size of the grid to 20x20, extending 10 units
# in each direction:
pm.grid( spacing=10 )
# To query the current size of the grid:
# returns a size in the current linear unit.
pm.grid( query=True, size=True )
# Result: 12.0 #
# A typical grid would be a grid size of 20x20, with
# major grid lines every 5 units, with 5 divisions between
# major grid lines. This be done with the following command.
pm.grid( size='10cm', sp='5.0cm', d=5 )
# Turn on numeric grid labels.
#
pm.grid( displayPerspectiveLabels=True )
# Display grid labels along the axes.
#
pm.grid( perspectiveLabelPosition='axis' )