3
$\begingroup$

Hello Im working on really big project and I need to exclude all collections from layerand reverse using script I tried this

import bpy

coll = bpy.data.collections
for c in coll:
   c.exclude = False

But it doesnt seem to work, any ideas where it went wrong or how to solve my problem? Any help is appreciated.

$\endgroup$

1 Answer 1

7
$\begingroup$

You need to use refence from view_layer.layer_collection:

import bpy
   
vl_colls = bpy.context.view_layer.layer_collection.children

# toggle
for coll in vl_colls:
    coll.exclude = not coll.exclude

Layer collection vs Collection:

reference

![](outliner.png)

Properties of LayerCollection(bpy_struct):

![](layercoll%20props.png)

  • Exclude: .exclude
  • Hide in Viewport: .hide_viewport
  • Holdout: .holdout
  • Indirect Only: .indirect_only

Accessed through bpy.context.view_layer.layer_collection.children

Properties of Collection(ID):

![](coll%20props.png)

  • Disable Selection: .hide_select
  • Disable in Viewport: .hide_viewport
  • Disable in Render: .hide_render

Accessed through bpy.data.collections

$\endgroup$
2
  • $\begingroup$ This won't work for more nested collections though. $\endgroup$ Aug 21, 2022 at 10:45
  • $\begingroup$ Yep it seems there's no way to find exclude for nested collections $\endgroup$ Mar 25 at 15:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .