I'm trying to insert a keyframe via python to animate energy lamp but i get this TypeError:
o.keyframe_insert(data_path='energy', frame=5)
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
TypeError: bpy_struct.keyframe_insert() property "energy" not found
The data_path "energy" should be correct, as explained here how to find the data_path for scripted keyframeshow to find the data_path for scripted keyframes just rightclick the Energy property and select "Copy Data Path".
Distance property don't works too.
I tried this on several Blender version: 2.71, 2.74, 2.76b, 2.77
More: I added manually the energy lamp animation and by checking this value:
bpy.context.object.data.animation_data.action.fcurves[0].data_path
i get still the same value 'energy'
It's a bug or i'm doing it wrong? There is some workaround?
SOLVED
I was confused by the fact that the property color was animatable directly from the lamp object otherwise energy and distance can be animated by lamp.data
The correct code
o.data.keyframe_insert(data_path='energy', frame=5)