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 enter image description here enter image description here

@Marty Fouts,

enter image description here enter image description here enter image description here enter image description here

  • $\begingroup$ blender.stackexchange.com/questions/248940/… $\endgroup$
    – Kalthoum
    Apr 19, 2022 at 15:22
  • $\begingroup$ do you want to rename all the render result? $\endgroup$
    – X Y
    Apr 19, 2022 at 15:25
  • $\begingroup$ Yes Instead of having the image name : 0001.png, having the material name : RED_MATERIAL.png thanks $\endgroup$
    – Kalthoum
    Apr 19, 2022 at 16:19
  • $\begingroup$ 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. $\endgroup$
    – Kalthoum
    Apr 19, 2022 at 16:27
  • $\begingroup$ 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 $\endgroup$
    – Kalthoum
    Apr 19, 2022 at 16:40

1 Answer 1


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))

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.

  • $\begingroup$ 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 $\endgroup$
    – Kalthoum
    Apr 19, 2022 at 17:09
  • $\begingroup$ @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. $\endgroup$ Apr 19, 2022 at 17:14
  • $\begingroup$ exact I run the scrip with the play_triangle, and generate the rendering. Is that wat I suppose to do? $\endgroup$
    – Kalthoum
    Apr 19, 2022 at 17:16
  • $\begingroup$ 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. $\endgroup$ Apr 19, 2022 at 17:17
  • 1
    $\begingroup$ 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 $\endgroup$
    – Kalthoum
    Apr 19, 2022 at 18:39

You must log in to answer this question.

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