If I have n number of node group how do I find the principle bsdf?
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.
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.
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.
Indeed i overlooked this… anyway: What ?
i pretty much need to check the different input values of principled node regardless of which node group it is located in
Provided you have some material and know the name of the Principled node:
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:
def find_all_princ_nodes(tree):
return [n for n in tree.nodes if n.type == 'BSDF_PRINCIPLED']
Hope this will help you
that’s not my question. my question was how do i get reference to principle bsdf if it’s located in a node group
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.
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
Exactly what I needed thanks