I have this piece of code that I am using to remove duplicate materials. What I do is I open the Text Editor, paste it in and click Run Script. I would like to make it a Tools Shelf button. This is the code:
import bpy
mat_list = bpy.data.materials
for o in bpy.data.objects:
for s in o.material_slots:
if s.material.name[-3:].isnumeric():
# the last 3 characters are numbers
if s.material.name[:-4] in mat_list:
# there is a material without the numeric extension so use it
s.material = mat_list[s.material.name[:-4]]
I tried following the instructions here, but I get this error:
This is my first time messing around with Blender scripts, any help appreciated!
EDIT: This is my complete addon:
import bpy
bl_info = {
"name": "Remove Duplicate Materials",
"author": "Me",
"version": (1, 0, 0),
"blender": (2, 7, 8),
"location": "3D View > Tool Shelf > My Tools",
"description": "Remove duplicate materials",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "User"}
import bpy
mat_list = bpy.data.materials
for o in bpy.data.objects:
for s in o.material_slots:
if s.material.name[-3:].isnumeric():
# the last 3 characters are numbers
if s.material.name[:-4] in mat_list:
# there is a material without the numeric extension so use it
s.material = mat_list[s.material.name[:-4]]