I have the following code to render child collections within a collection:

sideplates = bpy.data.collections["RACK 1 - 1 RACK FRAME"].children

for s in sideplates:
    n = s.name
    # render 800 x 600 
        scene.render.resolution_x = render1xresolution
        scene.render.resolution_y = render1yresolution            
        bpy.data.scenes["CONFIGURATOR 800 x 600"].render.filepath = '/BlenderPythonTest'
        bpy.ops.render.render(write_still = 1)

The collection structure looks like this:

enter image description here

I have tried to untick the box, excluding the child collections from the parent collection. Running the script will still render the "Nuage" collection et al, when what I would like from the picture above is just to render "Sable", "Souquillou" and "Cab".

Is this possible and if so, how?


2 Answers 2


I did this recently, you have to access your collection through specific view layer. You should try :

my_view_layer = bpy.context.view_layer #up to you

#append to sideplates only checked collection
sideplates = []
for collection in my_view_layer.layer_collection.children["RACK 1 - 1 RACK FRAME"].children :
    if collection.exclude == False :

##render individually checked collections
for s in sideplates:
    #exclude every other collection
    for sp in sideplates:
        if sp != s :
            sp.exclude = True
    ## RENDER STUFF ##
    #restore exclude attribute
    for sp in sideplates:
            sp.exclude = False
  • $\begingroup$ Tried but am not allowed to use the hide_render or exclude attribute. Should also mention that I only have one view layer. Explicitly referenced the view layer as you mentioned anyway (y = bpy.data.scenes["CONFIGURATOR 800 x 600"].view_layers["ALL"]) but it's not working. Will have a check/ play and come back shortly. Sure it's something my end so many thanks! $\endgroup$ Commented Dec 17, 2020 at 15:03
  • $\begingroup$ as i said if you look in the console at bpy.data.collections['my_collection'] there is no exclude attribute. but you can find it if you call bpy.data.scenes['Scene'].view_layers['View Layer'].layer_collection.children['my_collection'] you can now edit exclude attribute $\endgroup$
    – Tomreggae
    Commented Dec 17, 2020 at 15:16
  • $\begingroup$ OK got it working per your answer. My bad, can now see the exclude attribute, sry. I think our wires are crossed tho, I need a way of excluding a collection on the fly. In the example pic above the code will iterate through the 8 collections and render them all individually. That's great, but let's say three collection's textures do not come out as planned and I go back and change them, I don't want to render all 8 again & waste time. I was hoping that unticking the box & thus excluding it from the view layer would stop the code from picking that collection up and rendering it. It doesn't. $\endgroup$ Commented Dec 17, 2020 at 15:41
  • $\begingroup$ Ok i updated my answer, this should work, let me know ! $\endgroup$
    – Tomreggae
    Commented Dec 17, 2020 at 16:18
  • $\begingroup$ That's great @Tomreggae, I actually changed it a smidge to fit the fact that my collection was actually nested within a collection, nested in a collection and so on. I have added the final code, but full credit goes to you obviously, really put me on the right track using bpy.context.view_layer not bpy.data.collections which allowed the if statement to work with the exclude attribute...so thanks a million. $\endgroup$ Commented Dec 17, 2020 at 23:05

As per Tomreggaes suggestion in this post, final code looked like this:

my_view_layer = bpy.context.view_layer

sideplates = my_view_layer.layer_collection.children["ONE RACK UNIT - INC BASES AND TOPS"].children["RACK 1 (COLUMN 1)"].children["UNIT 1 - 1"].children["UNIT 1 - 1 RACK UNIT"].children["RACK 1 - 1 RACK FRAME"].children

for s in sideplates:
    if s.exclude == False :
        s.collection.hide_render = False
        s.collection.hide_viewport = False
    ## render 800 x 600 
        if rendersideplates == True:
            n = s.name 
            ##raise Exception()
            scene.render.resolution_x = render1xresolution
            scene.render.resolution_y = render1yresolution            
            bpy.data.scenes["CONFIGURATOR 800 x 600"].render.filepath = '/BlenderPythonTest/Configurator/Single Rack/Rack Frame/%(2)s/800x600/%(1)s 800x600 %(2)s.%(3)s'  % {"1" : n, "2" : camname, "3" : picformat}
            bpy.ops.render.render(write_still = 1)
        s.collection.hide_render = True
        s.collection.hide_viewport = True
  • 2
    $\begingroup$ Please help us making this site a real knowledge base and add some explanation to your answer in order to help future visitors having the same issue, Thanks. See: blender.stackexchange.com/help/how-to-answer $\endgroup$
    – brockmann
    Commented Dec 18, 2020 at 12:18
  • $\begingroup$ The explanation was in my last comment in the first answer by Tomreggae. I added the code that I actually used just in case anyone wondered how it worked with nested collections. But I'll read the help guide. $\endgroup$ Commented Dec 19, 2020 at 21:09

You must log in to answer this question.

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