Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- import re
- # Pattern: match names ending with _### (like _001, _002, etc.)
- pattern = re.compile(r"(.*)_(\d{3})$")
- for obj in bpy.data.objects:
- if not obj.data or not hasattr(obj.data, "materials"):
- continue
- for i, mat in enumerate(obj.data.materials):
- if mat is None:
- continue
- match = pattern.match(mat.name)
- if match:
- base, num = match.groups()
- new_name = f"{base}.{num}"
- # Check if target material exists
- new_mat = bpy.data.materials.get(new_name)
- if new_mat:
- print(f"Replacing {mat.name} → {new_name} on {obj.name}")
- obj.data.materials[i] = new_mat
- else:
- print(f"Target material not found: {new_name}")
Advertisement
Add Comment
Please, Sign In to add comment