Page MenuHome

bpy.context.scene.collection.children -- hide_viewport property -- not working from script
Closed, ArchivedPublic


System Information
Operating system: Ubuntu

Blender Version
Broken: (example: 2.80, master, 2019-03-22

I'm attaching a blend file with a 2 lines script.

When you try to unhide collections in the viewport with:

for coll in bpy.context.scene.collection.children:

coll.hide_viewport = False

This seems not to work with collections that have been hidden manually by pressing the "eye" icon in the outliner. Those manually hidden collections don't unhide with this command, whereas a collection that has been hidden with "coll.hide_viewport = True" does unhide with the False command.



Event Timeline

To hide and unhide collections you have to change the layer collections, like this:

for coll in bpy.context.view_layer.layer_collection.children:
    coll.hide_viewport = False

What you are doing is hiding the collection for all views (right click on collection > visibility > disable in view ports), so if your collection was hidden before and you execute your code then you are hiding what was hidden before, and then when you unhide with your code it returns to the initial hidden state.

I think there's no bug here, but I think keeping both attributes with the same name is misleading for collections and layer_collections

Brecht Van Lommel (brecht) closed this task as Archived.
Brecht Van Lommel (brecht) claimed this task.

The API could be improved here and we are rethinking the visibility controls in general, but no bug here.