8
$\begingroup$

There are a few materials in a blend file I have that I don't think are necessary in the file. However, none of these materials show up in orphan data. I know something is using these materials because if I add the material to another object, it will show a 2 in the material slot (for those who don't know, this means that 2 items are using the material. One of these is the object I plugged it into and the other one is what I want to figure out.) I checked all the meshes in the file and couldn't find a single one that was using the materials I think are not needed. None of these materials have any fake users either. How can I find what is using the material so I can be sure that I can delete it?

$\endgroup$
6
  • 3
    $\begingroup$ Hard to say without seeing the file, but a material can be referenced in several places, for instance in the render passes override or in geometry nodes $\endgroup$
    – Gorgious
    Commented Jul 15, 2021 at 6:32
  • 1
    $\begingroup$ To be sure it is not assigned to anything: if you're choosing a material slot on an object and use the dropdown menu to assign a material, is the one in question there marked with a 0 in front of the name? If not, then it's assigned to something, whatever that might be (as @Gorgious pointed out, it's not necessarily a mesh object). $\endgroup$ Commented Jul 15, 2021 at 9:23
  • $\begingroup$ @GordonBrinkmann There is no 0 in front of the material $\endgroup$
    – user114833
    Commented Jul 20, 2021 at 23:09
  • $\begingroup$ Then it's most likely assigned to something... $\endgroup$ Commented Jul 20, 2021 at 23:47
  • $\begingroup$ @GordonBrinkmann How can I figure out what it is? I checked all the meshes and couldn't find any that were using the material. $\endgroup$
    – user114833
    Commented Jul 21, 2021 at 1:16

1 Answer 1

11
+25
$\begingroup$

This appears to be the same question as How to find out what is using an image except that it's for materials rather than images. The first answer there, in the form of a python script, will solve this as well; by replacing the image bits with material bits.

Copy and paste script block into text editor and run it. Output written to system console:

import bpy
from bpy.types import bpy_prop_collection

def search(ID):
    def users(col):
        ret =  tuple(repr(o) for o in col if o.user_of_id(ID))
        return ret if ret else None
    return filter(None, (
        users(getattr(bpy.data, p)) 
        for p in  dir(bpy.data) 
        if isinstance(
                getattr(bpy.data, p, None), 
                bpy_prop_collection
                )                
        )
        )
        
# report all materials and their users in the console
for mat in bpy.data.materials:
    print (20*"-")
    print(repr(mat))
    print("Users:", mat.users)         
    for users in search(mat):
        print(users)

Console output (default scene):

--------------------
bpy.data.materials['Dots Stroke']
Users: 2
("bpy.data.brushes['Airbrush']", "bpy.data.brushes['Pencil Soft']")
--------------------
bpy.data.materials['Material']
Users: 1
("bpy.data.meshes['Cube']",)

Credit goes to @batFINGER, see How to find out what is using an image in a blend file

$\endgroup$
6
  • 1
    $\begingroup$ @brockman deserves half the bounty for updating the python to use mat.* $\endgroup$ Commented Jul 21, 2021 at 21:34
  • $\begingroup$ No problem, was dead easy to adapt it. $\endgroup$
    – brockmann
    Commented Jul 21, 2021 at 21:35
  • $\begingroup$ lol, thought this was the question I answered. Cheers for the cite. Appreciate the feedback. $\endgroup$
    – batFINGER
    Commented Jul 23, 2021 at 14:34
  • $\begingroup$ Any idea how to adapt this to search for actions assigned to an armature even if they aren't the current linked action? I've created 8 actions on one rig and I want to return all those action names as a list. $\endgroup$
    – Tyler
    Commented Feb 14, 2023 at 22:35
  • $\begingroup$ No luck with bpy.context.active_object.user_of_id(bpy.data.actions['Mixamo_MocapGuy_Idle Neutral 1']). It also only works for linked actions. $\endgroup$
    – Tyler
    Commented Feb 14, 2023 at 22:48

You must log in to answer this question.