OSArch Community

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

  1. T

    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()
    
    
  2. T

    Just FYI, this is for vanilla blender only, not Bonsai, and IFC materials.

Login or Register to reply.