3
$\begingroup$

I am trying to disable all collections in the render with python in Blender 2.8

It works on top-level collections with the code below, but ignores nested collections.

import bpy
coll = bpy.context.view_layer.layer_collection
for x in bpy.context.view_layer.layer_collection.collection.children:
        x.hide_render = True

Is there a way to get all collections, regardless of hierarchy?

$\endgroup$
  • $\begingroup$ Welcome to Blender.se. Thank you for your question, be aware, that the 2.8 api is still under development, although I'd think, that collection access won't change anytime soon. $\endgroup$ – Leander Apr 23 at 14:28
1
$\begingroup$

Access to Blender's internal data is achieved through bpy.data. This is usually also easier to maintain, since context access (bpy.context) is context-dependent.

Access all collections through:

bpy.data.collections

Render-restricting all collections:

import bpy

coll = bpy.data.collections

for c in coll:
    c.hide_render=True
$\endgroup$
  • 1
    $\begingroup$ Ah! That was easy. Thanks Leander. This works: import bpy coll = bpy.data.collections for c in coll: c.hide_render=True $\endgroup$ – cookiemonsterandthegirls Apr 23 at 14:39
  • 1
    $\begingroup$ Forgot to include the final code, added your example, glad it worked. For future reference, if any answer is missing a piece of information (like your code example) feel free to suggest an edit yourself. Comments are only temporary and may get removed. $\endgroup$ – Leander Apr 23 at 14:43
1
$\begingroup$

With recursion

As well as setting attributes on all collections in bpy.data.collections can recursively walk the children.

This will only set the property on descendants of the collection. In this case bpy.context.view_layer.layer_collection.collection

import bpy

def traverse_tree(t):
    yield t
    for child in t.children:
        yield from traverse_tree(child)

coll = bpy.context.view_layer.layer_collection.collection

for c in traverse_tree(coll):
    c.hide_render = True 
$\endgroup$

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.