So I have 1000s of old exported models but each of their materials are named standardmaterial.00x. However, when I click on each individual material the BASE COLOR has the correct name of the material. Can I make my life easier and produce a script that will pull the base color name from each material and assign that as the name of the material? Thank you in advance!
1 Answer
$\begingroup$
$\endgroup$
1
Try this. Save beforehand in case it messes up.
import bpy
def find_base_color_node(mat):
try:
for node in mat.node_tree.nodes:
if node.type == 'BSDF_PRINCIPLED':
break
return node.inputs["Base Color"].links[0].from_node
except Exception:
return None
def get_node_name(node):
try:
if node.label: return node.label
return node.image.name
except Exception:
return None
mat_names = [
mat.name for mat in bpy.data.materials
if mat.name.startswith("Standardmaterial")
]
for mat_name in mat_names:
mat = bpy.data.materials[mat_name]
node = find_base_color_node(mat)
new_name = get_node_name(node)
if new_name:
mat.name = new_name