4
$\begingroup$

I'm trying to animate the colour and strength properties of an emission shader based on external data using script. I add a cube and give it an emission shader. I can alter the strength property using:

bpy.context.active_object.active_material.node_tree.nodes['Emission'].inputs['Strength'].default_value=1

I then try to add a keyframe on the strength property using:

bpy.context.active_object.active_material.keyframe_insert(data_path="nodes[\"Emission\"].inputs[1].default_value",frame=10)

But I can't get the correct data_path. I must be missing something fundamental here. I have quite limited scripting experience in blender.

Code suggestions gratefully received.

$\endgroup$

1 Answer 1

3
$\begingroup$

You need to get a bit closer to what you want to keyframe. It is the socket that keyframes one of it's values, not the material. So you want to tell the input socket to insert a keyframe.

So this slight variation of what you have will work (only over two lines for clarity) -

node = bpy.context.active_object.active_material.node_tree.nodes['Emission']
node.inputs[1].keyframe_insert(data_path="default_value",frame=10)
$\endgroup$
1
  • $\begingroup$ This makes sense, I tried a variation of this but wasn't getting the data path correct; seems obvious now! Much appreciated. $\endgroup$
    – user3556
    Commented May 28, 2014 at 14:15

You must log in to answer this question.

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