1

I have a scene with multiple objects. Is there a way to automate rendering each object indiviual to separate files? I'm assuming that this would be achieved via scripting, which is fine.

p2or
  • 15,860
  • 10
  • 83
  • 143
honkskillet
  • 131
  • 5
  • 1
    related: http://blender.stackexchange.com/questions/42204/how-to-output-id-masks-as-seperate-files-for-compositing/42209#42209 – p2or Dec 07 '15 at 15:31
  • @poor Thank you for your comment. That is an interesting approach. I decided a pure scripting method would be easier in my use case. – honkskillet Dec 16 '15 at 15:29

3 Answers3

2

Wrote my first lines of Python to answer this.

It is pretty straight forward. The assumptions for this script to work is that 1) all you objects are on the first (0th) layer 2) you have selected the objects you want rendered.

import bpy

selected = bpy.context.selected_objects

for obj in selected:
    obj.layers[19]=True
    obj.layers[0]=False
index = 0
for obj2 in selected:
    obj2.layers[0]=True
    obj2.layers[19]=False
    print(index);
    bpy.data.scenes["Scene"].render.filepath = '/ur/path/here/render_%d.jpg' % index
    bpy.ops.render.render( write_still=True )
    obj2.layers[19]=True
    obj2.layers[0]=False
    index+=1
for obj in selected:
    obj.layers[0]=True
    obj.layers[19]=False

This code simply first moves all the selected objects from the first to the last layer. Then, one by one, moves each object back to first layer, renders it into a unique file, then moves back to last layer. Lastly, moves all objects back to the original layer.

Note: on OS X to render into your Documents folder the path would look something like '/Users/username/Documents/render_%d.jpg'.

honkskillet
  • 131
  • 5
2

Nicely done clean and simple...

note below for a bit more iterative setup (multiple scenes,objects,directories)

import bpy
import os

filepath = bpy.data.filepath
osdir = os.path.dirname(filepath)
osfile = os.path.basename(filepath.replace('.blend',''))

selected = bpy.context.selected_objects

list_of_all_scenes = bpy.data.scenes
scene = bpy.context.scene

if bpy.data.is_saved:
    for y in list_of_all_scenes:
        bpy.context.screen.scene = y
        selected = bpy.context.selected_objects
        for x in selected:
            if not os.path.isdir(os.path.join(osdir,osfile,y.name,x.name)):
                os.makedirs(os.path.join(osdir,osfile,y.name,x.name))
                x.hide_render=True
    for y in list_of_all_scenes:
        bpy.context.screen.scene = y
        selected = bpy.context.selected_objects
        for x in selected:
            x.hide_render=False
            bpy.context.screen.scene.render.filepath = os.path.join(osdir,osfile,y.name,x.name,x.name)
            bpy.ops.render.render( animation=False, write_still=True, use_viewport=False, layer="", scene="" )
            x.hide_render=True
    for y in list_of_all_scenes:
        bpy.context.screen.scene = y
        selected = bpy.context.selected_objects
        for x in selected:
            x.hide_render=False
Ratt
  • 2,126
  • 1
  • 10
  • 17
1

Another way is to iterate each object acting on the object only if a name condition is met.

import bpy

def hideRenderForAll():
    for obj in bpy.data.objects:
        if "x" in obj.name: # we know its a block as it has x in the name
            obj.hide_render = True

for obj in bpy.data.objects:
    if "x" in obj.name: # we know its a block as it has x in the name
        hideRenderForAll()        
        obj.hide_render = False        
        bpy.data.scenes["Scene"].render.filepath = 'S:\\TempRenders\\{0}.png'.format(obj.name)
        bpy.ops.render.render( write_still=True )
Doug
  • 153
  • 1
  • 5