For quickly finding and selecting objects that do not have materials, we can use the Blender Python API and write a script consisting of just a few lines.
First, we need to loop through all the objects in the scene and process only those of them that are of type “mesh”:
1 2 |
for obj in bpy.data.objects: if obj.type == 'MESH': |
In the simplest case, when a mesh can either have only one material or no material at all, we can check the mesh’s active_material property, which is the pointer to the mesh’s currently active material. If this property is not empty, then the mesh has material.
To select a mesh, we will use the select_set method, in the parameter of which we will pass an assessment of the presence of a material: False – if there is a material (such meshes do not need to be selected) and True – if there is no material.
For an active object that has no active material:
1 2 |
not bool(bpy.context.object.active_material) # True |
And all together:
1 2 3 |
for obj in bpy.data.objects: if obj.type == 'MESH': obj.select_set(not bool(obj.active_material)) |
This way we select objects that do not have active material.
However, a more complicated case is also possible, when the object has a material, but it is not active, because, it is not located in the active material slot.
Not to include such objects in our selection, let’s change the code a bit.
First, let’s check if the object has material slots. If not – select it.
1 2 |
if len(obj.material_slots) == 0: obj.select_set(True) |
If there are slots, check if there is at least one slot in which there is material, and if there is no such slot, select the object:
1 2 3 |
else: mat = any(slot for slot in obj.material_slots if slot.material) obj.select_set(not bool(mat)) |
And all together:
1 2 3 4 5 6 7 |
for obj in bpy.data.objects: if obj.type == 'MESH': if len(obj.material_slots) == 0: obj.select_set(True) else: mat = any(slot for slot in obj.material_slots if slot.material) obj.select_set(not bool(mat)) |