0
$\begingroup$

Can anybody help me write a script that excludes certain collections (for rendering)?

In the outliner the tooltip says: Layer.Collection.exclude and bpy.data.scenes["Scene"].exclude, so I've tried things like:

bpy.ops.outliner.LayerCollection('Structure').exclude
bpy.data.scenes["Scene"].LayerCollection('Structure').exclude

The online Python link is here: https://docs.blender.org/api/master/bpy.types.LayerCollection.html#bpy.types.LayerCollection.exclude but I don't know what to do with that information.

enter image description here

$\endgroup$
  • $\begingroup$ @RayMairlot perhaps "How to set LayerCollection.exclude?", apart from first sentence, it is the main gist of question. $\endgroup$ – batFINGER Jun 4 at 12:46
2
$\begingroup$

Use the View Layer

enter image description here

From the context view layer

>>> C.view_layer.active_layer_collection
bpy.data.scenes['Scene']...LayerCollection

>>> C.view_layer.active_layer_collection.name
'My Leaf 0.0'

>>> C.view_layer.active_layer_collection.exclude
False

Alternatively from scene

>>> C.scene.view_layers['RenderLayer'].active_layer_collection
bpy.data.scenes['Scene']...LayerCollection

>>> C.scene.view_layers['RenderLayer'].active_layer_collection.name
'My Leaf 0.0'

Related

Change active collection

$\endgroup$
1
$\begingroup$

Great, thanks. My script now looks like this and works well:

def CollControlAll (context, CollList, CollLen):
    layer_collection = bpy.context.view_layer.layer_collection

    for lay in range(0,CollLen):
        layerColl = recurLayerCollection(layer_collection, CollList[lay])
        bpy.context.view_layer.active_layer_collection = layerColl
        layerColl.exclude = False
        layerColl.hide_viewport = False
$\endgroup$
  • 2
    $\begingroup$ Cool. Couple of slight things, you pass context yet use bpy.context. Also recommend sticking to a naming convention eg class names in CamelCase, variables in lower eg coll_list $\endgroup$ – batFINGER Jun 5 at 5:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.