Bpy.ops.Outliner.show_active() from view3d context?

Hi, I have a question about calling function for outliner from view3d . There are several tricks with context changing but it is not exactly what I need. Because I want evaluate this (boy.ops.outliner.show_active())function for existing outliner. Please help!

You need to supply ‘area’ and ‘region’ context keys to override the operator from a different area.

import bpy
context = bpy.context


def show_active(context):
    override = None

    for area in context.screen.areas:
        if 'OUTLINER' in area.type:
            for region in area.regions:
                if 'WINDOW' in region.type:
                    override = {'area': area, 'region': region}
                    break
            break
    if override is not None:
        bpy.ops.outliner.show_active(override)


if '__main__' in __name__:
    show_active(context)

You can turn this into a hotkey by saving to a py file and adding it using the blender operator script.python_file_run in the hotkey editor.

1 Like

Hi @iceythe !!! Super cool solution and thank you very much!!! It’s good to learn new things. Thank you very much!