# DopeSheet/GraphEditor : How to detect/change, with API, displayed frame range

Is there a way to detect (and change) displayed frame range in dopesheet and grapheditor using python API ?

I am not talking about frame start/ frame end or restricted frame range, but what is the lowest and highest frame visible on screen (that can be changed with scrolling for example)

I can't find data for now on API documentation.

Thanks !

• Yes, I want to access this data by python API – Julien Jun 8 '16 at 9:44
• You need to access the View2D of the region you want (so dope sheet for example). Then you need to change the context to this region and run these operators: blender.org/api/blender_python_api_2_77_0/bpy.ops.view2d.html. You can also change the view2d direcly – Jaroslav Jerryno Novotny Jun 8 '16 at 10:24
• Ok, I will check that. That answers "how to change" data, but it's only based on x/y delta, or zoom factor, but not on frame displayed – Julien Jun 8 '16 at 10:31
• Yes, you cannot change that based on frames that fit into the window. You would have to calculate that from zoom factor, size of the region, and the xy delta. – Jaroslav Jerryno Novotny Jun 8 '16 at 13:04
• Have a look at blender.stackexchange.com/questions/38939/… I found that having envelope modifiers on the fcurve didn't give me the focus I wanted on graph editor (using bpy.ops.graph.view*) to display soundbar BGL vis below and resorted to making a dummy 3 point action with the desired frame, value range and callingbpy.ops.graph.view_all(c) had the desired result. You may find some of the other bpy.ops.graph.view* operators give you the focus you want. – batFINGER Jun 8 '16 at 15:40

The frame, value from the region coords can be obtained from view2d.region_to_view

import bpy
from mathutils import Vector
context = bpy.context
c = context.copy()
for i, area in enumerate(context.screen.areas):
if area.type != 'GRAPH_EDITOR':
continue
region = area.regions[-1]
print("SCREEN:", context.screen.name , "[", i, "]")
c["space_data"] = area.spaces.active
c["area"] = area
c["region"] = region

# region size
h = region.height # screen
w = region.width  #
bl = region.view2d.region_to_view(0, 0)
tr = region.view2d.region_to_view(w, h)
print("region bottom left (frame, value)", bl)
print("region top right (frame, value)", tr)

range = Vector(tr) - Vector(bl)


Note from Getting area (region.view2d) pixel coordinates of 2D views (VSE, NLA) how to get the scrollbar width.

As for setting the region to a desired frame value range, I have found using bpy.ops.view2d.anything an absolute nightmare, of finding rhyme or reason, and instead have used the methods outlined here Focusing the graph editor area to a custom [frame, keyframe_value] range using bpy.ops.graph.view* operators in the graph editor, and I expect would work similarly in dope sheet for bpy.ops.action.view*.