1
$\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$
0
$\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$
  • $\begingroup$ not sure if there is a better way to find the socket $\endgroup$ – Hikariztw Aug 26 '19 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 Aug 26 '19 at 11:47

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.