Python scripting in Blender: how can I save a sequence of rendered images? -
Python scripting in Blender: how can I save a sequence of rendered images? -
i'm new python scripting, i've been trying simple -- animation of bunch of cubes doing 3d random walk.
i've managed programme render every frame of process, have no thought how save each frame. can help?
here's code. i'm missing come in def render_and_save function.
cheers!
import bpy import random number_of_cubes = 10 animation_length = 10 def create_cubes(number_to_make): = 0 while < number_to_make: bpy.ops.mesh.primitive_cube_add(radius=1, view_align=false, enter_editmode=false, location=(0, 0, 0)) += 1 def move_cube(): bpy.ops.transform.translate(value=(random.randint(-1,1), random.randint(-1,1), random.randint(-1,1)), constraint_axis=(false, false, false), constraint_orientation='global', mirror=false, proportional='disabled', proportional_edit_falloff='smooth', proportional_size=1) def select_cube(cube_name): bpy.ops.object.select_all(action = "deselect") bpy.ops.object.select_pattern(pattern = cube_name) def move_all(): j = 0 while j < number_of_cubes: if j == 0: name_of_cube = "cube" print(name_of_cube) elif j < 10: name_of_cube = "cube.00" + str(j) print(name_of_cube) elif j < 100: name_of_cube = "cube.0" + str(j) print(name_of_cube) select_cube(name_of_cube) move_cube() j += 1 def render_and_save(moves): bpy.ops.render.render(use_viewport = true) filename = str(moves)+".png" #but should go here create save each image? create_cubes(number_of_cubes) moves = 0 while moves < animation_length: move_all() render_and_save(moves) moves += 1
by default bpy.ops.render.render()
not save single image renders. set write_still=true
enable it.
def render_and_save(moves): bpy.context.scene.render.filepath = "//renders/"+str(moves)+".png" bpy.ops.render.render(use_viewport = true, write_still=true)
the filepath setting same value available in output panel of render settings. putting "//render/" @ start of place images in folder called renders in same folder blend file - "//" short current blend file parent folder.
python blender
Comments
Post a Comment