I upgraded blender to version 4.0, but I can't use the code bpy.context.selected_ids in version 4.0. The console gives an error AttributeError: 'Context' object has no attribute 'selected_ids'.

Please help me, thank you guys.

import bpy

def ADD_HT_outliner(self, context):

def register():
  • $\begingroup$ it must be in the outliner context to work. If not this attribute is not defined/associated to the context. $\endgroup$
    – lemon
    Nov 29, 2023 at 11:14
  • $\begingroup$ It should work. How exactly does the error happen ? BTW you can use the passed context with print(context.selected_ids) $\endgroup$
    – Gorgious
    Nov 29, 2023 at 11:57
  • $\begingroup$ Thank you for your answer, but even using print(context.selected_ids), the same error will still occur $\endgroup$
    – levosaber
    Nov 29, 2023 at 17:02
  • $\begingroup$ I just want to get the id of the selected object in the UI. Isn't your code supposed to report an error? $\endgroup$
    – levosaber
    Nov 30, 2023 at 3:52

1 Answer 1


This worked for me in blender 4.0

import bpy

scr = bpy.context.screen
areas = [area for area in scr.areas if area.type == 'OUTLINER']
regions = [region for region in areas[0].regions if region.type == 'WINDOW']

with bpy.context.temp_override(area=areas[0], region=regions[0], screen=scr):
    for obj in bpy.context.selected_ids:
        print(f"Selected: {obj.name} - {type(obj)}")

You must log in to answer this question.

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