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.
1 Answer
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
-
-
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
node_wrangler.py
in the classNWResetNodes
. What particular part are you currently struggling with? $\endgroup$