How can I exclude a collection from rendering with Python? 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.
Use the View Layer



From the context view layer

&gt;&gt;&gt; C.view_layer.active_layer_collection
bpy.data.scenes['Scene']...LayerCollection

&gt;&gt;&gt; C.view_layer.active_layer_collection.name
'My Leaf 0.0'

&gt;&gt;&gt; C.view_layer.active_layer_collection.exclude
False


Alternatively from scene

&gt;&gt;&gt; C.scene.view_layers['RenderLayer'].active_layer_collection
bpy.data.scenes['Scene']...LayerCollection

&gt;&gt;&gt; C.scene.view_layers['RenderLayer'].active_layer_collection.name
'My Leaf 0.0'


Related 

Change active collection