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?


1 Answer 1


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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.