4
$\begingroup$

I'm writing to Space types with draw callbacks bgl & blf. The area region.type == 'WINDOW' gives me the height and width correctly re 'UI', 'TOOLS' and 'CHANNELS' regions, but also includes the scrollbars. Writing a 100% width box overwrites the scrollbars that determine what frame and value ranges are displayed.

Is there an API method available to focus in on a custom range, hopefully without needing to use the border select operator:

graph_area = context.screen.areas[4] # area.type = 'GRAPH_EDITOR'
graph_window_region = graph_area.regions[-1] # region.type = 'WINDOW'

c = context.copy()  # copy the context
c['area'] = graph_area
c['region'] = graph_window_region

# call ops with over-ridden context

bpy.ops.graph.view_all(c)
bpy.ops.graph.select_border(c, gesture_mode=3, xmax=lf, ymax=action_max)
bpy.ops.graph.view_selected(c)

The ops above focus the view to varying degrees of success, less so if there are envelope modifiers on the fcurves.

Here is an example of what I want to get to.

SoundVis in Graph Editor

ie having the full frame range and the value range in the top half of the region, my soundvis in the lower half.

EDIT

Ok I can fudge the value axis of the preview range by adding a dummy property and keying in bottom left and top right coords, selecting and calling bpy.ops.graph.view_selected(c) as shown below. The issue now is the frames, and looking at the image it occurs to me the preview range is including the handles. More to come.

Value Preview Range

PS: @CoDEmanX, thanks re scrollbars. apologies for the late edit, happier with the title now, the previous was a bit of a late night afterthought on this. I'm afraid tho you are quite right and there is no way to do this.

$\endgroup$
  • $\begingroup$ please edit your question to make the last sentence a complete thought. $\endgroup$ – David Sep 22 '15 at 15:35
3
$\begingroup$

Scrollbars aren't exposed to Python, you can't check or change their scroll position in a script.

$\endgroup$
  • $\begingroup$ Was just about to edit this and change the title. The scrollbars I was referring to are those on the graph editor that change the range (frame, value). of the preview, hence the select all and view_selected "zoom" in on the values. What do you think, should I trash this question and rephrase a new one or edit? $\endgroup$ – batFINGER Sep 22 '15 at 20:53
1
$\begingroup$

Ok got this via a workaround

Added a dummy action with 3 keyframes, bottom left, bottom centre, and top right.

def get_view_action(bl, tr):
    '''
    focus the graph editor to the sound fcurves
    bl bottom left (frame, value) 2d coord
    tr top right
    '''
    view_action = bpy.data.actions.get("view_action")

    if view_action is None:
        dp = '["view"]'
        obj["view"] = 0.0
        # create one
        view_action = bpy.data.actions.new("view_action")
        fc = view_action.fcurves.new(dp)
        # add 3 keyframe points
        fc.keyframe_points.add(3)
    else:
        fc = view_action.fcurves[0]

    (a, b, c) = fc.keyframe_points

    a.co = bl
    b.co = (bl[0] + tr[0] / 2.0, bl[1]) 
    c.co = tr

    return view_action

And when needed find your 'GRAPH_EDITOR' area(s)

# obj with action we want to focus in on in graph ed.
action = obj.animation_data.action
dummyaction  = get_view_action((frame_start, min_val), (frame_end, max_val))
# swap in the dummy
obj.animation_data.action = dummyaction
# context override , area is an area of type 'GRAPH_EDITOR'
c = context.copy()
region = area.regions[-1]

c["space_data"] = area.spaces.active
c["area"] = area
c["region"] = region
#bpy.ops.graph.view_selected(c, include_handles=False)
bpy.ops.graph.view_all(c)
# revert the action.
obj.animation_data.action = action

The visualiser height in the view can be determined using

v = graph_editor_window_region.view2d
(m, n) = Vector(v.region_to_view(1,1)) - Vector(v.region_to_view(0,0))
# m is how many pixels wide a frame is in view
# visualiser height from view pixels to keyframe value
kfh = vis_height * n

The dummy action can then be removed. Image below shows the dummy used to focus graph before being removed.

Dummy action to view range in graph editor

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.