How to get the grid size in a Python script? I'm trying to find a way to get the grid size so I can align some vertices to it in a script.  Frustratingly, bpy.context.space_data.overlay.grid_scale allows you to set the grid size but not get it.  The overlays tooltip suggests using bpy.data.screens[&quot;Scripting&quot;].overlay.grid_scale, but this causes an error:
&gt;&gt;&gt; bpy.data.screens[&quot;Scripting&quot;].overlay.grid_scale
Traceback (most recent call last):
  File &quot;&lt;blender_console&gt;&quot;, line 1, in &lt;module&gt;
AttributeError: 'Screen' object has no attribute 'overlay'

What's a good way to try to get the grid size for my script?
Overlays are set per view.
You need to find the (or a) 3d view area.
import bpy

def get_areas_by_type(context, type):
    return [a for a in context.screen.areas if a.type == type]

# Get view3d areas
view3d_areas = get_areas_by_type(bpy.context, 'VIEW_3D')

# Assuming there is one (if not test it in your code)
view3d_area = view3d_areas[0]

# The view space
view_space = view3d_area.spaces[0]

# It has overlay
view_space.overlay.grid_scale = 4.0

Or if you know that your context is the 3d view, you can use:
context.space_data.overlay.grid_scale