1

Using Blender 2.90alpha, I already have some fancy python code to set some keyframes on an object + data_path from my external data source. It creates obj.animation_data.action then calls obj.animation_data.action.fcurves.new(path, index) for each channel, and then inserts points into the fcurves. That works fine for objects. I'd like to do the same for shader nodes; but the examples I've seen all use a different method:

shader_node.inputs[1].default_value = 1
shader_node.inputs[1].keyframe_insert("default_value", frame=10)

and then apparently you can get the fcurve afterward using something like this (?)

action = material.node_tree.animation_data.action
data_path = 'nodes["my shader node"].inputs[1].default_value' # rooted at "node_tree" apparently
fc = action.fcurves.find(data_path)
# ... do things with fc
# apparently the fcurve is actually stored in mat.node_tree.animation_data.action.fcurves

but I'd prefer, if possible, to just create the fcurves directly with their data paths. I haven't seen any examples doing it that way and wonder if it's possible for shader nodes (before I dive into it). And if so, how can I make sure I get those data paths right -- is there any API to get the data path for a value?

GaryO
  • 545
  • 3
  • 13
  • Some examples of "doing it that way" https://blender.stackexchange.com/questions/111644/fast-keyframe-insertion https://blender.stackexchange.com/questions/64447/how-do-i-add-keyframes-to-a-newly-created-action-with-no-associated-objects https://blender.stackexchange.com/questions/55880/is-it-possible-to-create-instance-with-different-scale-animation-data-but-the-sa https://blender.stackexchange.com/questions/135759/is-it-possible-to-create-an-animation-in-blender-2-8-using-python-that-its-no – batFINGER Jun 12 '20 at 02:41
  • See also https://blender.stackexchange.com/a/111326/15543 shader node py console example D.materials['Material'].node_tree.nodes['Principled BSDF'].inputs['Roughness'].path_from_id('default_value') returns 'nodes["Principled BSDF"].inputs[7].default_value' ie the datapath from ID object, in this case the materials shader node tree. – batFINGER Jun 12 '20 at 03:02

0 Answers0