# How can we render an object including his material name?

I need to render an object in a different material, @FFeller, helped me with the index material geometry node, which allowed me to automate the rendering. But, in the naming the rendered images, didn’t include the material names. Knowing that I had almost 50 different materials, that I already properly named in a slot material, you can imagine what time-consuming renaming all the images….

And I’m not familiar with python, so is there any help…. Thankx

PS: screenshot to illustrate my question

@Marty Fouts,

• blender.stackexchange.com/questions/248940/… Apr 19 at 15:22
• do you want to rename all the render result?
– X Y
Apr 19 at 15:25
• Yes Instead of having the image name : 0001.png, having the material name : RED_MATERIAL.png thanks Apr 19 at 16:19
• thanks , but would you mind show me how I can invoke Python code? please I'm really not familiar with Python in blender. I have some notions but I haven't coded before. Apr 19 at 16:27
• MATERIAL_NNNN is the material in slot nnnn (- 1?) Yes in the slot material I named them and identified them by index So 0001- is the first material indexed 1 in the -set material index- wish named RED_MATERIAL And so on…. Hope I’m made it clear 😊 thanks again @Marty Fouts Apr 19 at 16:40

If you changed material slots on every frame, this code should solve your problem.

EDIT: If you started on frame 1 with the material in slot zero you'll need to change the line that sets src_string by changing index to index + 1.

import bpy
from pathlib import Path

scene = bpy.context.scene
path = Path(scene.render.filepath)
suffix = ".png"

object = bpy.context.active_object
for index in range(len(object.material_slots)):
src_string = format(index, "04d") + suffix
src = path / src_string
dst_string = object.material_slots[index].material.name  + suffix
dst = path / dst_string
print(str(src), str(dst))
src.rename(dst)


Paste it into the text editor in the Scripting workspace. Make sure you've selected the object that has your geometry nodes as the active object. After you've generated the png files, hit the run button.

• I don’t know what I did wrong. 🤔😪 I select the cube. – I paste the script – I render the animation – and I hit the run – I generate again - …… Can you tell me? @Marty Fouts Apr 19 at 17:09
• @Kalthoum what do you mean by "I generate again"? When I said "hit run" I meant the triangle shaped "run" button in the text editor. Apr 19 at 17:14
• exact I run the scrip with the play_triangle, and generate the rendering. Is that wat I suppose to do? Apr 19 at 17:16
• First you render, so that all of the files will exist with the 0000.png, 0001.png, etc names. Then you run the script. The names should change to match the materials unless I don't understand your description of how you animated. Apr 19 at 17:17
• It works IT WORKSSSSSSSSSS The rendering images started by 0001.png And the script looks for 0000.png So, I renamed the first render 0000.png. and the magic happened You don’t know how this is important for me, and how much you helped me Thanks again for your patience and I learned a lot… PS: I add a screenshot of the result Apr 19 at 18:39