Linking material to Object from Python?

(paulmelis) #1

Is there a way to add an object-level material slot from Python? I don’t mean adding a material to a mesh, but adding it to an Object, like you can do in the material editor with setting the Link selector to Object, followed by assigning a material. [1] seems to suggest you can at least update an exisiting slot, but I don’t see methods to create one. E.g. Object.material_slots doesn’t have an append() method.

I’m doing flipbook animation by updating a placeholder object’s mesh depending on the frame number in a frame_change_pre handler. However, updating the mesh seems to remove the material linked to the object that I have set manually. I don’t want to link the material to the meshes in the animation as I them from individual blender files (one per timestep). I’d like to avoid yet another level of indirection of having to link from the timestep files to a file containing only a material. The material needs to be editable, hence my desire so simply set it on the placeholder object.