4

I have a blend file that I am using as a materials library. I have discovered that there are node groups that were not named, so I have a collection of NodeGroup.xxx groups. I would like to find the users of these groups so that I can rename them with meaningful names.

Google searches have not turned anything up.

Is there such a tool, or am I reduced to visiting each material until I find the user?

Marty Fouts
  • 33,070
  • 10
  • 35
  • 79
  • Could you be more specific? It's a bit vague. – Linguini May 19 '18 at 16:50
  • 1
    I create a new shader. In the node editor I hit A to bring up the add menu and scroll down to group. As I scroll through the groups I find groups named NodeGroup.xxx. I want to find what materials are currently using NodeGroup.xxx so that I can figure out a more descriptive name to give it. – Marty Fouts May 19 '18 at 20:32

2 Answers2

4

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"

batFINGER
  • 84,216
  • 10
  • 108
  • 233
1

It turns out the only currently viable solution is to write a python scripts that takes the node group name as input and iterates through all of the existing materials, including orphaned, looking for the name. Once you've been given at least one name of a material, you can select it and view it in the node editor.

One can modify the script from the answer to this question to produce the result. Something along these lines will work:

import bpy

# Run through all materials of the current blend file
# need to add code to get name from user into input_name
for mat in bpy.data.materials:
    # If the material has a node tree
    if mat.node_tree:
        # Run through all nodes
        for node in mat.node_tree.nodes:
            # If the node type is Ambient Occlusion 
            if node.name == input_name:
                # Print the name of the material
                print( input_name, "found in:", mat.name)
Marty Fouts
  • 33,070
  • 10
  • 35
  • 79