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?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
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 = mat else: ob.data.materials.append(mat) bpy.app.handlers.frame_change_pre.append(my_handler)