2
$\begingroup$

I have a blender object, and a large number of materials that I need to apply to the object.

Can you please share a python script that applies various materials to an object in a loop and saves output images to a given location?

$\endgroup$

1 Answer 1

2
$\begingroup$

This code will animate (cycle) through all materials based on current frame value. Run this in Text editor, select some object (it works on active object), set frame range from 0 to number_of_materials-1 and render the animation as images.

import bpy

def my_handler(scene):
    if bpy.data.materials:
        ob = bpy.context.active_object
        mat = bpy.data.materials[min(len(bpy.data.materials)-1, scene.frame_current)]
        if len(ob.data.materials):
            ob.data.materials[0] = mat
        else:
            ob.data.materials.append(mat)

bpy.app.handlers.frame_change_pre.append(my_handler)
$\endgroup$

You must log in to answer this question.

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