Page MenuHome

DESELECT action python script does not work for outliner.
Closed, ArchivedPublic

Description

System Information
Operating system: Darwin-20.4.0-x86_64-i386-64bit 64 Bits
Graphics card: AMD Radeon Pro 5500M OpenGL Engine ATI Technologies Inc. 4.1 ATI-4.4.17

Blender Version
Broken: version: 2.92.0, branch: master, commit date: 2021-02-24 16:25, hash: rB02948a2cab44
Worked: (newest version of Blender that worked as expected)

Short description of error
DESELECT etc. python script does not work for outliner. (deselecting elements and objects are not working with the python code)

also check this out: https://stackoverflow.com/questions/66985178/blender-2-92-python-element-selected-in-outline-i-dont-want-it-to-be

Exact steps for others to reproduce the error

>>> bpy.ops.outliner.select_all(action='SELECT')
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "/Applications/Blender.app/Contents/Resources/2.92/scripts/modules/bpy/ops.py", line 132, in __call__
    ret = _op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.outliner.select_all.poll() failed, context is incorrect
>>> bpy.ops.outliner.select_all(action='DESELECT')
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "/Applications/Blender.app/Contents/Resources/2.92/scripts/modules/bpy/ops.py", line 132, in __call__
    ret = _op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.outliner.select_all.poll() failed, context is incorrect

Event Timeline

When running the command in the console, the context will be the console.

>>> C.area.type
'CONSOLE'

But because the operator is expected to run in the outliner, you need to override the context.
E.g. with a script like so:

import bpy

for window in bpy.context.window_manager.windows:
    screen = window.screen
    for area in screen.areas:
        if area.type == 'OUTLINER':
            override = {'window': window, 'screen': screen, 'area': area}
            bpy.ops.outliner.select_all(override, action="SELECT")
            break

When the script is executed, this will look through all the areas, find the outliner and run the command in it (select all).

Closing as this is not a bug.