View layer API access wishlist: collection.expand_set()

Wishlist:

What was obj.hide in Blender 2.79 is now obj.hide_viewport in 2.80.

This is different from the visibility on view layers, which describes visibility on different viewlayers, and is what the default show/hide ops manipulate and what the eye icons in the outliner represent.

Using obj.visible_get() you can return the the visibility state on the active view layer.

There is no visible_set() method however, as far as I can tell. So how can you set the visibility on the active or other view layers?

An object hidden via the obj.hide_viewport prop, can not be unhidden by the user using ALT + H for example.

Expanding on this, it would be extremely useful to to access the collection expand behavior, just like it can be done for modifiers.

Currently collections are always expanded when created, with no way to collapse them as far as I can tell.

1 Like

Hello MACHIN3

I absolutely agree, it would be nice to have a mean in Python to expand/collapse these collections.
So, what is the state, is there still no way?

Not possible right now.

Basically what would be great to have is a collection.expand_set(state, view_layer=None) function, where you can optionally pass a view layer.
Very similar to the new hide_set() for objects. And btw, the collections could need the hide_set() as well.

@dfelinto :slight_smile:

1 Like

Similarly, I’d find it helpful if object expand behavior would be accessible as well. Objects seem to default to a collapsed state when created, and there is no way to expand them, except from the outliner.

Unfortunately, outliner ops - run with context overrides from the 3d view - won’t do anything either.

If the outliner could be come less of a black box in terms of API access, that would be great.

Another year is gone and 3.2 is now in Beta… any chance for that collapse/expand by name function?
Appending nested collections in an Add-on makes the Outliner so messy. Is it really so hard to achieve such a selective collapse/expand function? Even if it would only work on the active collection, it would still help a lot…

Just to add to the pile, object instances do not have visible_get method, which makes it impossible to know if they are visible while iterating through depsgraph.

Usually hidden objects do not appear in depsgraph, unless they are hidden by collection, in which case they are hidden in viewport, but still appear in depsgraph.object_instances.

It has been a known issue for two years.

Noticed that if you hide object with obj.hide_viewport = True then it will be hidden completely - no matter if eye icon is on or off. Is it part of the same problem?

Though hiding object with obj.hide_set(True) and checking it’s status with obj.hide_get() helps.

And there is still some incostistency between hiding objects and collections:

  • to hide object globally you do obj.hide_viewport = True
  • to hide object in current view layer you do obj.hide_set(True)
  • to hide collection globally you do bpy.data.collections['Collection'].hide_viewport = False
  • to hide collection in current view layer you do bpy.context.view_layer.layer_collection.children['Collection'].hide_viewport = True