0
$\begingroup$

When you run the following code from the script editor when having a cube selected:

import bpy

for x in bpy.context.selected_objects:
    x.keyframe_insert(data_path = 'location', index = 1)

#Updates the Transform UI panel when run as an addon
for region in bpy.context.area.regions:
    if region.type == 'UI':
        region.tag_redraw()

You set a keyframe on the Y axis and the UI panel would be refreshed when the script is an addon, but the dopesheet does not refresh(see attached screenshot). enter image description here

How do I safely refresh the dopesheet?

$\endgroup$

1 Answer 1

1
$\begingroup$

I suggest to include the areas while looping to the regions. Note the region.type in dopesheet is Window.

import bpy

for x in bpy.context.selected_objects:
    x.keyframe_insert(data_path = 'location', index = 1)

#Updates all animation related UI
for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        for region in area.regions:
            if region.type == 'UI':
                region.tag_redraw()
    elif area.type == 'DOPESHEET_EDITOR':
        for region in area.regions:
            if region.type == 'WINDOW':
                region.tag_redraw()
            if region.type == 'CHANNELS':
                region.tag_redraw()
    elif area.type == 'GRAPH_EDITOR':
        for region in area.regions:
            if region.type == 'WINDOW':
                region.tag_redraw()
            if region.type == 'CHANNELS':
                region.tag_redraw()
    elif area.type == 'NLA_EDITOR':
        for region in area.regions:
            if region.type == 'WINDOW':
                region.tag_redraw()
            if region.type == 'CHANNELS':
                region.tag_redraw()
    elif area.type == 'OUTLINER':
        for region in area.regions:
            if region.type == 'WINDOW':
                region.tag_redraw()
    elif area.type == 'PROPERTIES':
        for region in area.regions:
            if region.type == 'WINDOW':
                region.tag_redraw()
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .