2
$\begingroup$

I'm rotating an object in Object Mode using a script and I'd like to capture a snapshot after each rotation. I'm currently trying to do it with Viewport Render Image but the write_still set to True overwrites the same file, which makes sense. I'm unable to figure out how to increment through the filenames that should be assigned to different snapshots. Does anyone have any idea on how to achieve this?

Thank you in advance.

$\endgroup$

1 Answer 1

2
$\begingroup$

One way is to not set write_still to True. Rather, use the fact that bpy.ops.render.opengl creates an image named 'Render Result' and save that image. Here's code to do that:

import bpy
from pathlib import Path

p = Path('PATH_TO_OUTPUT_FOLDER')

for seq in range(0,MAX_FRAMES):
    # Your code to rotate the object goes here
    bpy.ops.render.opengl()
    image = bpy.data.images['Render Result']
    image_name = 'PREFIX_STRING' + format(seq, '03d') + '.png'
    filename = str(p / image_name)
    image.save_render(filename)

where obviously you have to replace PATH_TO_OUTPUT_FOLDER, MAX_FRAMES, and PREFIX_STRING appropriately.

Not so obviously, you do have to replace '.png' with the correct extension for the file format you've set in output and you have to insert your code to rotate the object.

$\endgroup$

You must log in to answer this question.

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