Change an Object's Material to another Material with Python [Pic Attached] I have an object named "Paper_obj"





After entering the Material tab, there are tons of materials within, "White Transmission", "Steel Mag", etc.

My main purpose is to change the "PaperTopYellow" to "PaperTopRed" by clicking on the drop down list. Can it be done with Python?




Since there are many other objects in the blend file, the hardest part for me is to first target that "Paper_obj" first and then change the "PaperTopYellow" to "PaperTopRed" within.

Thank you!
bpy.data.objects['Paper_obj'].data.materials[3] = bpy.data.materials['PaperTopRed']


The above should be the general answer.

However, what if I do not want to use the slot number but would like to target "PaperTopYellow" and replace it with "PaperTopRed"?

Sometimes, the slot number for "PaperTopYellow" may not be 3 but 2 instead.