Finding data-blocks that use other data-blocks.
How to Track Users of Data Blocks?
In your answer to getting the users of a Material data-block, can change one line
# report all materials and their users in the console
for mat in bpy.data.node_groups:
print (20*"-")
print(repr(mat))
print("Users:", mat.users)
for users in search(mat):
print(users)
To iterate over and get all the users of each node group in the blend Example output
--------------------
bpy.data.node_groups['Foo']
Users: 1
("bpy.data.node_groups['NodeGroup']",)
--------------------
bpy.data.node_groups['NodeGroup']
Users: 1
("bpy.data.materials['Material']",)
The node group "NodeGroup" is being used by "Material". The node group "Foo" is a group in "NodeGroup" as shown by being a user.
Can we consider "Material" a user of "Foo"
I would consider the group "Foo" as a necessary ingredient in the material "Material"
Only looking at nodes in material nodes is purely a one level search and will miss nested nodes.
Example of recursively walking a node tree for images.
Is there an easy way in python to find the bpy.data.images that are used in a node?
minor edit to look instead for nodegroup(s).
However what we have above is enough. For each node we have a list of "parents" ie in this example trace the ancestry of node_group:"Foo" -> node_group:"NodeGroup" -> material:"Material"