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$
2
$\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$
  • $\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 May 28 '14 at 14:15

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.