2
$\begingroup$

enter image description here

I want to reset the alpha of all Principled BSDF nodes to 1.0 with a Python script, since it would be cumbersome to change the values all by hand.

$\endgroup$
2
  • $\begingroup$ The reset button is from the node wrangler add-on. You can take a look how they implemented it in node_wrangler.py in the class NWResetNodes. What particular part are you currently struggling with? $\endgroup$ Commented Jan 19, 2023 at 18:27
  • $\begingroup$ with the alpha it is set to 0 for every materials, i want to change to 1 (max) $\endgroup$
    – Joel Jose
    Commented Jan 19, 2023 at 18:29

1 Answer 1

3
$\begingroup$

The materials of the blend-file can be accessed through bpy.data.materials regardless which scene they are being used in. For a given material the nodes can be access through the material's node_tree. In order to ensure that you are working on the right node, you can check its bl_idname. For Principled BSDFs the bl_idname is the string "ShaderNodeBsdfPrincipled". Since alpha is an input value of the node, it is accessed through the inputs and its value is set through default_value.

import bpy

# Iterate through all materials
for mat in bpy.data.materials:
    # Some materials do not use nodes and thus don't have a node tree, skip them
    if mat.node_tree is None:
        continue
    # Get the nodes from the current material
    nodes = mat.node_tree.nodes
    # Iterate through all nodes
    for node in nodes:
        # Check if the node is a Principled BSDF
        if node.bl_idname == "ShaderNodeBsdfPrincipled":
            # If it is, set the alpha to 1.0
            node.inputs["Alpha"].default_value = 1.0
$\endgroup$
2
  • $\begingroup$ thanks a lot bruh $\endgroup$
    – Joel Jose
    Commented Jan 19, 2023 at 18:54
  • 1
    $\begingroup$ @JoelJose if the answer solved your problem you can mark it as accepted by clicking the checkmark next to it. That way other users will know which answer worked for you. $\endgroup$ Commented Jan 19, 2023 at 19:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .