Hello, thanks for bumping the thread. I had progressed my research and created something with it. I don’t know if anyone is interested. But I would let you know about the results. https://drive.google.com/file/d/0B0YtvOk65FM1SGZ6eUN1MFhJVjQ/edit?usp=sharing
For the sake of the example, when you try to render the scene, a random cube will appear, at a random location, with random rotation.
import bpy
import random
anim_interval = 0
cube_list = []
cube_curr = 0
cube_total = 50
def my_handler(scene):
global cube_list, cube_curr
global anim_interval
if scene.frame_current % anim_interval == 0:
# Grab the current object (shortcut)
obj = cube_list[cube_curr]
# Bring the current cube index in rendered layer (1)
bpy.data.objects[obj].layers = (
True, False, False, False, False,
False, False, False, False, False,
False, False, False, False, False,
False, False, False, False, False
)
# Update it's position random
r = 30
x = (random.random()*r) - (r/2)
y = (random.random()*r) - (r/2)
scene.objects[obj].location = (x, y, 0)
# Update it's rotation random
bpy.data.objects[obj].rotation_euler = (
random.random()*360,
random.random()*360,
random.random()*360
)
# Increment the current cube index
cube_curr = cube_curr + 1
# Bonus: Loop through all of the previously create cubes
# and rotate them to maximize the pleasure
for i in range(cube_curr):
bpy.data.objects[cube_list[i]].rotation_euler[2] += 0.25
def construct_scene():
# Delete all cubes
bpy.ops.object.select_all(action='DESELECT')
cubes = [i.name for i in bpy.data.objects if i.name.find("Cube") > -1]
for i in cubes:
bpy.data.objects[i].select = True
bpy.ops.object.delete()
# Create cubes in layer 11
global cube_total
for i in range(cube_total):
bpy.ops.mesh.primitive_cube_add(
location = (0, 0, 0),
layers = (
False, False, False, False, False,
False, False, False, False, False,
True, False, False, False, False,
False, False, False, False, False
)
)
# Get new cubes
global cube_list
cube_list = [i.name for i in bpy.data.objects if i.name.find("Cube") > -1]
# Calculate animation interval
global anim_interval
anim_interval = bpy.context.scene.frame_end / cube_total
def register_handler():
handlers = bpy.app.handlers.render_pre
if len(handlers) > 0:
for i in range(len(handlers)):
if handlers[i].__name__ == my_handler.__name__:
handlers.pop(i)
handlers.append(my_handler)
construct_scene()
register_handler()