0
$\begingroup$

I am trying to render objects from each collection by loop but it only renders one collection.

enter image description here

import bpy


# hide all the collections
for col in bpy.data.collections:
    col.hide_render = True


for col in bpy.data.collections:
    # unhide the collection
    col.hide_render = False

    bpy.ops.render.render(write_still=True) 

    # hide the collection
    col.hide_render = True


# unhide all the collections
for col in bpy.data.collections:
    col.hide_render = False
$\endgroup$
1
  • $\begingroup$ it is rendering all. you are just overwriting it with the same name. you have to specify the name using bpy.context.scene.render.filepath. see this answer for proper usage. $\endgroup$
    – Harry McKenzie
    Commented Aug 11, 2023 at 14:22

1 Answer 1

0
$\begingroup$

Your current code writes all the renders in the same file, you could solve that by using a different file or a time stamp.

import bpy
from datetime import datetime

for col in bpy.data.collections:
    col.hide_render = True
    
for col in bpy.data.collections:

    # get current time
    now = datetime.now()
    # creates timestamp like 2023-08-11_11h47m41s
    timestamp = now.strftime("%Y-%m-%d_%Hh%Mm%Ss")

    # set the file output to collectionName_timestamp.exr
    bpy.context.scene.render.filepath = f"/path/to/file/{col.name}_{timestamp}.exr"
    col.hide_render = False

    print(f"Rendering '{col.name}'")
    bpy.ops.render.render(write_still=True)

for col in bpy.data.collections:
    col.hide_render = False
$\endgroup$

You must log in to answer this question.

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