A way to bulk remove all the blender materials that are not used in the scene.

This was helpful for me. Logging here for others.
Is a way to bulk remove all the blender materials that are not used in the scene.

import bpy

def remove_unused_materials():
    # Get all materials
    materials = bpy.data.materials

    # Track the number of materials removed
    removed_count = 0

    for material in materials:
        # Check if the material has no users
        if material.users == 0:
            # Unlink and remove the material
            materials.remove(material)
            removed_count += 1

    print(f"Removed {removed_count} unused materials.")

# Call the function
remove_unused_materials()

NigelsteverugiBedson

Comments

Sign In or Register to comment.