I'm working on an add-on that performs some operations on items in Outliner (actually it enables me to batch rename collections, a feature missing from Blender). The addon works fine if I assign a keyboard shortcut to it, click Outliner and hit the key. However it does not work if I launch it from another window, or from the Edit menu. In these cases I receive the 'Context' object has no attribute 'selected_ids' error.
I tried a few things found on the net, which were usually trying to get the outliner window and override the context. One is this:
for area in bpy.context.screen.areas:
if area.type == 'OUTLINER':
override = bpy.context.copy()
override['area'] = area
I thought I can just call override.selected_ids
instead of bpy.context.selected_ids
, but I cannot for an 'dict' object has no attribute 'selected_ids' error.
Have any of you managed to find a way to switch context to Outliner?
I need a solution for Blender 2.92+
selected_ids
attribute come from? Also I'd suggest take the tour to learn about how this site works. $\endgroup$space_data and region
also. 99% of qs re context override would be an example. $\endgroup$selected_ids
forbpy.context
only exists if the Outliner was the active area at the moment of starting the script. I want to be able to use it from other areas as well, and I think I first somehow need to switch to Outliner, so that I can get the result ofbpy.context.selected_ids
and process it. Let me know if I still miss something from my description. $\endgroup$selected_ids
, see the search results of the api docs: docs.blender.org/api/current/… . Anyway, to avoid confusion I recommend just tell us what you'd like to do because you do not have to "switch" to the outliner in order to rename the selected objects... and again overriding the context and switching the ouliner is a different thing. $\endgroup$bpy.context.selected_ids
works properly if the active area is the Outliner, and I can get the list of selected collections and objects, but if the active area is different at the moment of launching the script,bpy.context
returns a different object, which actually does not have this property defined, and calls to it therefore cause an exception. So to be able to get the list, it seems that I have to switch to the proper context. $\endgroup$