1
$\begingroup$

I'm able to modify the roughness property while inside blender to achieve different effects (renders shown below)

picture of blender settings

before setting roughness after setting roughness

However, no matter what I set the value in the code the output is always the same: enter image description here

What do I need to do in order to apply the roughness in a python script and have it stick? The code sample is below where I'm setting the roughness to 1.

for m in bpy.data.materials:
print("Going to clear out spec and metallic and roughness [%s] [%s] [%s] for %s" % (m.specular_intensity, m.metallic, m.roughness, m.name))
m.specular_intensity = 0.0
m.metallic = 1.0
m.roughness = 1.0 
$\endgroup$
0
$\begingroup$

Aha!

So in case anyone else comes across this

to debug this I checked the property path by right clicking in blender on the property and selected "copy data path" which gave me this value:

nodes["Principled BSDF"].inputs[7].default_value

So I updated my script accordingly:

for m in bpy.data.materials:
m.node_tree.nodes["Principled BSDF"].inputs[7].default_value = 1
$\endgroup$
1
  • 2
    $\begingroup$ Instead of using magic numbers, you can use m.node_tree.nodes["Principled BSDF"].inputs['Roughness'].default_value = 1, Paste m.node_tree.nodes["Principled BSDF"].inputs[ into the console and hit [tab] for a complete list. $\endgroup$ – Ron Jensen Aug 11 '20 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.