5

Here are a few objects that I have hidden:

I am using the script below to make them visible:

bpy.ops.object.hide_view_clear()

but it does not help.

So what is the perfect script to make them visible?

Martynas Žiemys
  • 24,274
  • 2
  • 34
  • 77
Avi Aninda
  • 81
  • 2
  • 6

2 Answers2

11

As of Blender 2.81, Object.hide_set() is working properly and seems to be the equivalent of Object.hide property in 2.7x versions.

Proof using the console:

>>> bpy.context.object.hide_set(False)

To unhide multiple objects you can run over objects in the scene and call the setter per object:

for o in ("Cube", "Camera", "Light"):
   obj = bpy.context.scene.objects.get(o)
   #if obj: obj.hide_viewport = False
   if obj: obj.hide_set(False)

You can also iterate through any given collection:

col = bpy.data.collections.get("Collection")
if col:
   for obj in col.objects:
       obj.hide_set(False)

Whatever you like...

brockmann
  • 12,613
  • 4
  • 50
  • 93
  • Is it possible to simulate the Shift+Mouse_Click for hiding an object with its children. Now I am iterating over the children objects and hide_set(True) them individually. My guess is that under the hood is the same procedure that is happening but I was wondering if someone can just call the build in functon instead of re-implementing it. – ttsesm Oct 08 '20 at 12:21
  • Hi! Shift+LMB is reserved for multi-selection in the outliner. I recommend ask a new detailed question referring to this one @ttsesm – brockmann Oct 08 '20 at 12:49
  • I see, thanks. I will open a new thread. – ttsesm Oct 08 '20 at 12:53
1

You need a way to specify which objects to unhide. Hidden objects cannot be selected, so you cannot just use bpy.context.selected_objects, you can use their names to identify them or whatever other attribute. You will need to loop through the objects from which you wish to pick the ones to unhide, you could use bpy.data.objects to do that for all scenes, but bpy.context.scene.objects are all the objects in the current scene that you are more likely to wish to work with. The script picking them by name could be something like this:

import bpy

for o in bpy.context.scene.objects:
    if 'Cube' in o.name:
        o.hide_viewport = o.hide_render = False

Note that there are a few ways to hide objects. object.hide_viewport or object.hide_render or object.hide_select

You can find out stuff like that using autocomplete functionality of the Python console (ctrl+space while hovering mouse over Python console panel with some text you started typing):

enter image description here

C is short for bpy.context in the console. C.object is the active object.

Martynas Žiemys
  • 24,274
  • 2
  • 34
  • 77
  • Also working somehow but the icon in the outliner doesn't change... I think it is still unfinished or they forgot to remove the properies, I don't get it. – brockmann Sep 09 '19 at 18:39
  • If I am not mistaken in some development builds it was removed and now it is back. I assumed this is in order to be more compatible with older scripts. There is nothing about it in the documentation, it's just there so I assume it is fine to use this as we always did. Maybe the new way is more efficient... – Martynas Žiemys Sep 09 '19 at 19:19