lenght of mat list for ob ?

obj = bpy.data.objects[‘Cube’]

print ()
print (’ before mat obj.material_slots.len() =’,obj.material_slots.len())
print ()

how come i get a len = 1 whenthere is not mat on the object ?


with default scene, the cube object have a material slot working, although there is no material applied to that slot. i guess you could see the material icon in the first row of the list

but when you add a new mat you get 2 material

how an you have one mat only !


Material slots are only the holders for the actual materials – as to which material is used for each index. Have you tried len(ob.data.materials)?

just did and i still get one even if there are not mat !

if i add a new mat then i get 2
so is there a way to modify the first mat instead may be

before len mat = 1
before mat obj.material_slots.len() = 1
obj.material_slots 0 = <bpy_struct, MaterialSlot("")>


ok re did another file with new ob

and seems that there was an empty mat in normal blender for the file i had
but there was no name on it !

if i look at the default cube with no mat
the lenght mat = 0

so i’ll recheck my little script and modify my cube in scene

but this may create another problem when there is not mat
needs to add one i guess beofre using cycles!