Looping collections through bpy.data.collections gives you classes of type Collection:
https://docs.blender.org/api/current/bpy.types.Collection.html#bpy.types.Collection
Looping collections through bpy.context.view_layer.layer_collection.children gives you classes of type LayerCollection:
https://docs.blender.org/api/current/bpy.types.LayerCollection.html#bpy.types.LayerCollection
The meaning of the property hide_viewport seems to be slightly different in these two class types.
- In type
Collection it means: "Globally disable in viewports"
- In type
LayerCollection it means: "Temporarily hide in viewport"
- Type
LayerCollection additionally exposes the property is_visible, which is True, when the collection is both enabled and visible
I guess LayerCollection.hide_viewport is what you were looking for.
Code example to see the differences in action:
print('Looping type "Collection", property "hide_viewport":')
for collection in bpy.data.collections:
print(collection.name, ' - Disabled in Viewport:', collection.hide_viewport)
print('Looping type "LayerCollection", property "hide_viewport":')
for layer_collection in bpy.context.view_layer.layer_collection.children:
print(layer_collection.name, ' - Hidden in Viewport: ', layer_collection.hide_viewport)
print('Looping type "LayerCollection", property "is_visible":')
for layer_collection in bpy.context.view_layer.layer_collection.children:
print(layer_collection.name, ' - Enabled and visible: ', layer_collection.is_visible)
hide_get()for object... – Simos Sigma Dec 29 '20 at 10:54bpy.types.LayerCollection(in link, the collections assoc with the view layer) ) andbpy.types.Collectionin question) See answer below. – batFINGER Dec 29 '20 at 13:23