6
$\begingroup$

I downloaded a model and found some images that I don't think are needed, but the images do not show up in orphan data so something is using them. How do I find out what is using the image(s).

$\endgroup$

2 Answers 2

11
$\begingroup$

Via a script.

An image, like a mesh, world, material ... in blender is an ID object. Given the image is our ID object of interest Run over all the ID objects in the blend and list and report any where ob.user_of_id(ID) is > 0

Copy and paste the script block below into the text editor and run it. Output is written to the 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
                )                
        )
        )
        

img = bpy.data.images[0] 
#img = bpy.data.images['Foo'] # an image named Foo

# report
print(repr(img))
print("Users:", img.users)         
for users in search(img):
    print(users)

Test run. Image used in material, "Material", node group "NodeGroup", reference image empty "Empty", texture "Texture" and world "World".

bpy.data.images['Screenshot from 2021-06-17 17-17-47.png']
Users: 5
("bpy.data.materials['Material']",)
("bpy.data.node_groups['NodeGroup']",)
("bpy.data.objects['Empty']",)
("bpy.data.textures['Texture']",)
("bpy.data.worlds['World']",)

.. or users of context object, edit to img = bpy.context.object

result

bpy.data.objects['Cube']
Users: 2
("bpy.data.collections['Collection 1']",)
("bpy.data.scenes['Scene']",)
$\endgroup$
2
  • $\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$ Is this impossible because blender shares data blocks by default? So after unlinking an action it has no metadata that says it was created on a specific rig? $\endgroup$
    – Tyler
    Commented Feb 15, 2023 at 0:03
1
$\begingroup$

You can use bpy.data.user_map :

import bpy

img = bpy.data.images[0]
users = bpy.data.user_map(subset=[img])
print(users[img])

This will output a dictionary with the input subset of IDs as keys and users as values.

$\endgroup$

You must log in to answer this question.