I have an .obj file that contains hundreds of materials. These are however not correctly named. The vast majority of them are duplicates of the original materials. Somehow every instance of the original materials have been assigned their own variant of that material.
For example we have
mtl_brick, and in every other instance where that material is assigned a duplicate has been created called,
mtl_brick.001. In some cases, where that material is assigned in a lot of places, there are more than 50 variants of this.
The material variants are exactly the same they just have different names. So I tried to rename it correctly using its
Base Color texture name. So in our example,
mtl_brick would use
brick_c.png. I tried to write a simple script doing the renaming.
import bpy i = 0 while i < len(bpy.data.materials): mat = bpy.data.materials[i] if mat.name != 'Dots Stroke' and mat.name != 'Material': mat = bpy.data.materials[i] l = len(mat.node_tree.nodes['Image Texture'].image.name) mat.name = mat.node_tree.nodes['Image Texture'].image.name[l:-6] i = i + 1
This script does not work. When it encounters a duplicate it simply renames it into
The process that I want to script, and not do manually is going into the Material Properties tab, selecting the variant materials, Browse Material to be linked and Choose Material data-block to be assigned to this user, in order to reassign the variant materials to the original.
How do I use python scripting to re-assign all of these variants to its original material?