Skip to main content
Notice removed Authoritative reference needed by quellenform
Bounty Ended with Marty Fouts's answer chosen by quellenform
Tweeted twitter.com/StackBlender/status/1517609211596791808
Notice added Authoritative reference needed by quellenform
Bounty Started worth 50 reputation by quellenform
Refined answer
Source Link
quellenform
  • 39.5k
  • 10
  • 56
  • 149

How can I distinguish the type of node in Python when importing node groups from other files?

I want, after I read a folder with blend files and search in the files for objects of type node_groups, to set a different action depending on the type of the group.

The crucial thing is: The type of the nodes must be clearly recognizable in this case BEFORE the node has even been imported!

Finally there are GeometryNodeTree, ShaderNodeTree, CompositorNodeTree and TextureNodeTree, but I somehow can't find a way to query this type.

This is the code I use to read the files:

for fn in os.listdir(dirpath):
    if fn.endswith(".blend"):
        filepath = os.path.join(dirpath, fn)
        with bpy.data.libraries.load(filepath) as (data_from, data_to):
            for group_name in data_from.node_groups:
                print("Very well, and what type are we talking about here?")

What do I need this for?

I would like to improve the addon Node Presets and here it needs a distinction of the nodes, so that not for each node type a separate path must be specified: How can I use custom node groups as node templates/presets?

How can I distinguish the type of node in Python when importing node groups from other files?

I want, after I read a folder with blend files and search in the files for objects of type node_groups, to set a different action depending on the type of the group.

Finally there are GeometryNodeTree, ShaderNodeTree, CompositorNodeTree and TextureNodeTree, but I somehow can't find a way to query this type.

This is the code I use to read the files:

for fn in os.listdir(dirpath):
    if fn.endswith(".blend"):
        filepath = os.path.join(dirpath, fn)
        with bpy.data.libraries.load(filepath) as (data_from, data_to):
            for group_name in data_from.node_groups:
                print("Very well, and what type are we talking about here?")

How can I distinguish the type of node in Python when importing node groups from other files?

I want, after I read a folder with blend files and search in the files for objects of type node_groups, to set a different action depending on the type of the group.

The crucial thing is: The type of the nodes must be clearly recognizable in this case BEFORE the node has even been imported!

Finally there are GeometryNodeTree, ShaderNodeTree, CompositorNodeTree and TextureNodeTree, but I somehow can't find a way to query this type.

This is the code I use to read the files:

for fn in os.listdir(dirpath):
    if fn.endswith(".blend"):
        filepath = os.path.join(dirpath, fn)
        with bpy.data.libraries.load(filepath) as (data_from, data_to):
            for group_name in data_from.node_groups:
                print("Very well, and what type are we talking about here?")

What do I need this for?

I would like to improve the addon Node Presets and here it needs a distinction of the nodes, so that not for each node type a separate path must be specified: How can I use custom node groups as node templates/presets?

Source Link
quellenform
  • 39.5k
  • 10
  • 56
  • 149

How do I find out the node type?

How can I distinguish the type of node in Python when importing node groups from other files?

I want, after I read a folder with blend files and search in the files for objects of type node_groups, to set a different action depending on the type of the group.

Finally there are GeometryNodeTree, ShaderNodeTree, CompositorNodeTree and TextureNodeTree, but I somehow can't find a way to query this type.

This is the code I use to read the files:

for fn in os.listdir(dirpath):
    if fn.endswith(".blend"):
        filepath = os.path.join(dirpath, fn)
        with bpy.data.libraries.load(filepath) as (data_from, data_to):
            for group_name in data_from.node_groups:
                print("Very well, and what type are we talking about here?")