How to get selection objects list in outliner?

Please I have the same problem like other users, can you please updat ethe code for Blender 2.9 + ?

Here is workaround script.
Toggle-hide between two objects.
Code can be saved in .py file and installed as usual addon
and then add keymap for outliner.toggle_hide operator

import bpy
from bpy.types import Operator

bl_info = {
    "name": "Toggle Hide",
    "description": "Toggle Hide",
    "author": "APEC, Oskar",
    "blender": (2, 90, 0)

class OUTLINER_OT_toggle_hide(Operator):
    """Toggle the viewport visibility between two initially visible and selected objects in the viewport"""
    bl_idname = "outliner.toggle_hide"
    bl_label = "Toggle Hide"
    #bl_options = {'REGISTER', 'UNDO'}

    def poll(cls, context):
        if (bpy.context.area.type == "VIEW_3D" or bpy.context.area.type == "OUTLINER"):
            return True
    def execute(self, context):
        # Get the current scene so we can store our selected objects in it.
        scene = bpy.context.scene
        selected_objects = context.selected_objects
        # This is our custom property where we will store the object names in.
        # Returns None if the property doesn't exists. To avoid try/except.
        prop = scene.get("hide_toggle_objs", None)
        if prop is not None and len(prop)>0 and len(selected_objects)==0:
            # Get the stored objects
            toggle_objs_list = scene["hide_toggle_objs"]
            # Reverse their visibility
            toggle_objs_list[0].hide_viewport = not toggle_objs_list[0].hide_viewport
            toggle_objs_list[1].hide_viewport = not toggle_objs_list[0].hide_viewport
        elif len(selected_objects)>0:
            # If we selected new objects, then store them in the scene
            bpy.context.scene["hide_toggle_objs"] = selected_objects
            # Hide the first selected and deselect the second
            selected_objects[0].hide_viewport = True
        return {'FINISHED'}
classes = (

register, unregister = bpy.utils.register_classes_factory(classes)

if __name__ == "__main__":

Thank you APEC, but this script Toggle the viewport visibility between two initially visible and selected objects in the viewport. It works, but I am looking for simple visibility toogle of anything selected in viewport or outliner - on and off, not switching between two objects… please don’t you have this kind of script as well?

Can you explain what exactly you need?
Select objects in Outliner and hide them? Like default “H” key?

Or hide also for rendering?

Simple toggling selected objects by default in Blender is “H” - hide and “Alt+H” - unhide. “Shift+H” - hide unselected.
Also here is “Local View Mode” that isolate selected object/s (key “Numpud /”) - very helpful in complex scenes.

I just need nothing more simple than this

Just toggle between visibility. Yes, also for rendering, everywhere.
Just get the list of the selected objects in outliner - go through it - if it’s hidden (disabled in viewport) make it unhidden, if it’s not hidden make it hidden. I am trying to solve such a simple thing all day long - please help me to go to sleep finally with peace… I know I am new to Blender and conding there - sorry fo that.

Got it,
default hotkeys won’t help in such task.
Yes, indeed, it need to write a script for this, will try to help you tomorrow, there was no need for such a task before.

Thank you very much - I truly appreciate you trying to help me. Looking forward for tomorrow
But keeping keeping watching tutorials anyway :slight_smile:

Hi, did you have time to make a script?

With my basic skills I tried here

But you cannot run the script in 3DView, until the developers make changes to the main code

Hi there,
After looking through basically every forum thread for a solution for accessing hidden selected objects from the outliner outside the outliner, I figured that it is not supported by the python API.
The bpy.context.selected_ids works great, but for now at least only in the context of the Outliner, which is for most of the intended use cases not a good/feasible solution.

Long story short, I updated the awesome script of @iceythe to work with blender 2.93LTS.
This said, it is by nature a very “hacky” and I just did a quick rework and could not really test it, but here you go:

The internal struct have changed slightly, such that a few classes of the original script must be adjusted.


class SpaceOutliner(ctypes.Structure):
    _fields_ = (
        ("next", ctypes.c_void_p),
        ("prev", ctypes.c_void_p),
        ("regionbase", ctypes.c_void_p * 2),
        ("spacetype", ctypes.c_char),
        ("link_flag", ctypes.c_char),
        ("pad0", ctypes.c_char * 6),
        ("v2d", ctypes.c_char * 160),       #changed in 2.93 -> 160 (unsure if it's actually 160 xD)
        ("tree", listbase(TreeElement29)))

TreeElement._fields_ = (
    ("next", ctypes.POINTER(TreeElement)),
    ("prev", ctypes.POINTER(TreeElement)),
    ("_parent", ctypes.POINTER(TreeElement)),
    ("type", ctypes.c_void_p),              #new field in 2.93
    ("subtree", listbase(TreeElement)),
    ("xys", ctypes.c_int * 2),
    ("_store_elem",  ctypes.POINTER(TreeStoreElem)),
    ("flag", ctypes.c_short),
    ("index", ctypes.c_short),
    ("idcode", ctypes.c_short),
    ("xend", ctypes.c_short),
    ("_name", ctypes.c_char_p),
    ("directdata", ctypes.c_void_p),
    ("rnaptr", ctypes.c_void_p * 3))            #unchanged

I’ve rewritten the toggle script and tried to make sure it works on all recent Blender versions. This includes the LTS (2.83.x), 2.93.x and 3.0 alpha.

If (when) a newer version breaks the script, it usually means the DNA side of Blender has changed (struct members added/removed). When that happens, let me know of the specific version.

(Same link as my other post)
Right-click > Save As.


Thank you a lot for the clean update!


This is so useful to me. Thank you thank you thank you!

it seems, with some changes in blender 3.2.0, script does not work now.
Can you check it?


It should now support Blender 3.2.
The download link is the same.

1 Like

I can’t get that working… key mapped to outliner.toggle_hide nothing happens

Something wrong in your setup. It works for me in 3.4.0

What you mean with setup. Installed the script and used the name for the hotkey… not sure what else to do,?

It works for me as expected (with J default keymap)

Thanks for that. Indeed it works in Outliner, but not in viewport when I’m in object mode. Tried different shortcuts. Nothing happens.
But I’m in 3.3 have to check 3.4 so.