Inserting Keyframes

Greetings. I’ve been working with Blender scripting for a few days now. I’m familiar with Python and have been getting more used to working with it in Blender. However regardless of what I search I cannot find more of a direct answer on the issue I am encountering. Now I know that there have been some changes in functions since Blender 2.8, but I am trying to assign a color change on my diffuse node to a key frame.

I have tried:

obj =['Cube']

node = obj.active_material.node_tree.nodes["Diffuse BSDF"].default_value

<-- I know 'node' needs to be in quotes, but Ive tried both quotes and no quotes. 
    To ensure the data_path is correct, I copied the data path by right- 
    clicking my diffuse color and choosing 'copy data path'--->

obj.keyframe_insert(data_path=node, frame=0)

I know I need to change the color first, but I cannot get the key frame to insert. I get an error showing node (the actual string output) “default_value” is not found.

I am trying to set a key frame on color change, but obj.diffuse_color (not the actual command, I know) only changes the color of the object in the viewport display. I’ve tried to get my command to recognized ‘use_object_color = True’, but nothing autocompletes to this.

Hi schultzy175!

I was looking at doing this too, and after a couple of hours googling, found this way to address the default_values in the materials nodes.

The data_path thing was a little confusing.

Here is an example of me setting an emission colour shaders strength keyframe…

node.inputs[1].keyframe_insert(data_path=“default_value”, frame = 2)

hope that helps!

Thanks for the reply. I actually was able to solve it at work today before you had responded, but the solution is exactly as you have it.
I found out using keyframe_insert() was called from whatever object/material was selected - object.keyframe_insert() or material.keyframe_insert() - and the data_path was the property that lied within the object/material in use

nodes[‘DiffuseBSDF’].inputs[0].keyframe_insert(data_path=“default_value”, frame=0)

1 Like