I was trying to accomplish this task for hours now and i´m not sure i can do this on my own.
On my objects are mostly many materials that were created during the script import process i made.
Every material has one texture slot with it´s UV mapped image assigned.
I want to create a new material for the active object, join all current textureslots from every single material into that newly created material.
here’s a fragment, it doesn’t work, but you can fix it I guess (I currently lack the concentration to get the indices right and stuff)
import bpy
ob = bpy.context.object
me = ob.data
mat_target = me.materials[0]
for i, mat in reversed(list(enumerate(me.materials[1:], 1))):
ts_source = mat_target.texture_slots[0]
ts = mat.texture_slots.add()
print(i, mat)
#for prop in dir(ts_source):
# Skip a few properties we can't / shouldn't copy
#if prop.startswith("_") or prop in {'bl_rna','rna_type','name'}:
#continue
#try:
#setattr(ts, prop, getattr(ts_source, prop))
#except TypeError:
#continue
ts.texture = ts_source.texture
#me.materials.pop(i)