2
$\begingroup$

I'm using Blender 2.80. Start in a new scene with no objects. Add a sphere, then go to the Properties panel, Material tab, and set the Base color to pure red in the Principled BSDF. Next, run this script:

    import bpy

    # Get current active object
    ob = bpy.context.active_object

    # Set the material diffuse color
    ob.material_slots[0].material.diffuse_color = (0.0, 0.0, 1.0, 1.0)

When I do this, the color of the sphere changes to blue in the viewport. However if I do a render with F12, the color of the sphere is still red. How can I set the material color for rendered images?

$\endgroup$

2 Answers 2

1
$\begingroup$

You are changing the viewport setting instead of node value.

NodeSocketColor

Use ob.material_slots[0].material.node_tree.nodes[1].inputs['Base Color'].default_value = (0,0,0,0)

$\endgroup$
2
  • $\begingroup$ not sure if there is a better way to find the socket $\endgroup$
    – HikariTW
    Commented Aug 26, 2019 at 9:00
  • $\begingroup$ Got it! You have to navigate the nodes making up the material, then get to the specific field. Thanks. $\endgroup$
    – ciric50
    Commented Aug 26, 2019 at 11:47
1
$\begingroup$

It didn't work for me on Blender 2.91 but it was a good hint. The solution that worked for me was: ob.material_slots[0].material.node_tree.nodes['Principled BSDF'].inputs['Base Color'].default_value = (0,0,0,0)

$\endgroup$

You must log in to answer this question.

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