# How do I get reference to the principle bsdf if it's inside a node group?

**URL:** <https://blenderartists.org/t/how-do-i-get-reference-to-the-principle-bsdf-if-its-inside-a-node-group/1569390>\
**Category:** Beginning Blender Code and Development\
**Tags:** scripting\
**Created:** [January 8, 2025, 12:07am UTC](https://blenderartists.org/t/how-do-i-get-reference-to-the-principle-bsdf-if-its-inside-a-node-group/1569390 "2025-01-08T00:07:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rayn\_H](https://blenderartists.org/user_avatar/blenderartists.org/rayn_h/32/1355299_2.png) [@Rayn\_H](https://blenderartists.org/u/Rayn_H)\
**Post date:** [January 8, 2025, 12:07am UTC](https://blenderartists.org/t/how-do-i-get-reference-to-the-principle-bsdf-if-its-inside-a-node-group/1569390/1 "2025-01-08T00:07:53Z")

</div>

If I have n number of node group how do I find the principle bsdf?

---

<div class="post-metadata">

**Author:** ![Okidoki](https://blenderartists.org/user_avatar/blenderartists.org/okidoki/32/1434104_2.png) [@Okidoki](https://blenderartists.org/u/Okidoki)\
**Post date:** [January 8, 2025, 12:57pm UTC](https://blenderartists.org/t/how-do-i-get-reference-to-the-principle-bsdf-if-its-inside-a-node-group/1569390/2 "2025-01-08T12:57:31Z")

</div>

What do you mean by find _ **the** _ _Principled-BSDF_ ??

A node group might not have any _Principled BSDF_ included at all. And you can open any node group with the Tab key.

---

<div class="post-metadata">

**Author:** ![jakemoyo](https://blenderartists.org/user_avatar/blenderartists.org/jakemoyo/32/971674_2.png) [@jakemoyo](https://blenderartists.org/u/jakemoyo)\
**Post date:** [January 8, 2025, 4:22pm UTC](https://blenderartists.org/t/how-do-i-get-reference-to-the-principle-bsdf-if-its-inside-a-node-group/1569390/3 "2025-01-08T16:22:11Z")

</div>

It’s a question in the Coding subcategory, so I imagine they’re asking how to find a reference to the Principled node via Python.

---

<div class="post-metadata">

**Author:** ![jakemoyo](https://blenderartists.org/user_avatar/blenderartists.org/jakemoyo/32/971674_2.png) [@jakemoyo](https://blenderartists.org/u/jakemoyo)\
**Post date:** [January 8, 2025, 4:29pm UTC](https://blenderartists.org/t/how-do-i-get-reference-to-the-principle-bsdf-if-its-inside-a-node-group/1569390/4 "2025-01-08T16:29:37Z")

</div>

I would also say we need a bit more information about what you’re trying to do exactly, because it’s fairly straightforward to get access to _a_ principled node, but getting access to a specific one in a specific group is a bit different, so we might need to know more about what you’re aiming for.

---

<div class="post-metadata">

**Author:** ![Okidoki](https://blenderartists.org/user_avatar/blenderartists.org/okidoki/32/1434104_2.png) [@Okidoki](https://blenderartists.org/u/Okidoki)\
**Post date:** [January 9, 2025, 6:52am UTC](https://blenderartists.org/t/how-do-i-get-reference-to-the-principle-bsdf-if-its-inside-a-node-group/1569390/5 "2025-01-09T06:52:38Z")

</div>

Indeed i overlooked this… anyway: What ? 😉

---

<div class="post-metadata">

**Author:** ![Rayn\_H](https://blenderartists.org/user_avatar/blenderartists.org/rayn_h/32/1355299_2.png) [@Rayn\_H](https://blenderartists.org/u/Rayn_H)\
**Post date:** [January 11, 2025, 2:17am UTC](https://blenderartists.org/t/how-do-i-get-reference-to-the-principle-bsdf-if-its-inside-a-node-group/1569390/6 "2025-01-11T02:17:38Z")

</div>

i pretty much need to check the different input values of principled node regardless of which node group it is located in

---

<div class="post-metadata">

**Author:** ![nar3d](https://blenderartists.org/user_avatar/blenderartists.org/nar3d/32/1330611_2.png) [@nar3d](https://blenderartists.org/u/nar3d)\
**Post date:** [January 11, 2025, 1:01pm UTC](https://blenderartists.org/t/how-do-i-get-reference-to-the-principle-bsdf-if-its-inside-a-node-group/1569390/7 "2025-01-11T13:01:05Z")

</div>

Provided you have some material and know the name of the Principled node:

```py
def get_node(tree,node_name):
    return tree.nodes.get(node_name)

#mat: bpy.types.Material 
#some_shadernodegroup_node_name: str
#name_of_your_principled_node:str
mat_nodes = mat.node_tree.nodes
group_node = mat_nodes.get(some_shadernodegroup_node_name)
princ_node = get_node(group_node.node_tree, name_of_your_principled_node)

```

Or, if you want to find every Principled node inside a node tree:

```py
def find_all_princ_nodes(tree):
    return [n for n in tree.nodes if n.type == 'BSDF_PRINCIPLED']

```

Hope this will help you

---

<div class="post-metadata">

**Author:** ![Rayn\_H](https://blenderartists.org/user_avatar/blenderartists.org/rayn_h/32/1355299_2.png) [@Rayn\_H](https://blenderartists.org/u/Rayn_H)\
**Post date:** [January 12, 2025, 9:15pm UTC](https://blenderartists.org/t/how-do-i-get-reference-to-the-principle-bsdf-if-its-inside-a-node-group/1569390/8 "2025-01-12T21:15:57Z")

</div>

that’s not my question. my question was how do i get reference to principle bsdf if it’s located in a node group

---

<div class="post-metadata">

**Author:** ![nar3d](https://blenderartists.org/user_avatar/blenderartists.org/nar3d/32/1330611_2.png) [@nar3d](https://blenderartists.org/u/nar3d)\
**Post date:** [January 13, 2025, 2:36pm UTC](https://blenderartists.org/t/how-do-i-get-reference-to-the-principle-bsdf-if-its-inside-a-node-group/1569390/9 "2025-01-13T14:36:26Z")

</div>

Okay, so you don’t know which tree the principle node is in? You can use the functions above to create a recursive function. I modified the find\_all function to return all node groups inside a tree.

```py
def find_all_group_nodes(tree):
    return [n for n in tree.nodes if n.type == 'GROUP']

def find_princ_node(tree,name):
    princ_node = get_node(tree,name)
    if princ_node: 
        return princ_node
    for group in find_all_group_nodes(tree):
        princ_node = find_princ_node(group.node_tree,name)
        if princ_node:
            return princ_node
    return None

```

---

<div class="post-metadata">

**Author:** ![Rayn\_H](https://blenderartists.org/user_avatar/blenderartists.org/rayn_h/32/1355299_2.png) [@Rayn\_H](https://blenderartists.org/u/Rayn_H)\
**Post date:** [January 15, 2025, 1:48am UTC](https://blenderartists.org/t/how-do-i-get-reference-to-the-principle-bsdf-if-its-inside-a-node-group/1569390/10 "2025-01-15T01:48:23Z")

</div>

Exactly what I needed thanks
