context.selected_objects
and context.selectable_objects
return only objects that are visible in viewport because an invisible object is no longer valid as selected in the data, even if it´s marked darker in the Outliner.
When a selected object is made invisible (hidden or disabled) and switched visible again, it seems to be selected in Outliner but the yellow (selection) border in the 3DView is missing. The object can´t be modified (e.g. hold, rotate, scale) until it has been reselected.
In Outliner there are two ways to make an object invisible:
Hide in Viewport
(Symbol Eye) and
Disable in Viewports
(Symbol Monitor - filter disabled by default)
Note that 'Hide in Viewport' (Eye) is an attribute of LayerCollection
and 'Disable in Viewports' (Monitor) an attribute of (Data)Collection
.
See the first two entries here: link
There are different ways to get invisible, hidden or disabled objects, depending on what is desired:
import bpy
# get invisible objs (hidden or disabled) by different of context.visible_objects
invisible_objs = [o for o in bpy.data.objects if not o in bpy.context.visible_objects]
print("invisible (eye or monitor):", invisible_objs)
# get hidden objs by viewlayer.objects
hidden_objs = [o for o in bpy.context.view_layer.objects if o.hide_get() is True]
print("hidden (eye):", hidden_objs)
# get disabled objs by data.objects
disabled_objs = [o for o in bpy.data.objects if o.hide_viewport == True]
print("disabled (monitor):", disabled_objs)