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 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:


i get still the same value 'energy'

It's a bug or i'm doing it wrong? There is some workaround?


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)

Of the three choices my bet is that you're doing it wrong in that your o object is the lamp object, not the data part, or some other non LAMP data object.

import bpy
context = bpy.context
#o = bpy.data.objects.get("Lamp") # assumes you have an ob named Lamp
#o.data = bpy.data.lamps.get("Lamp")
o = context.active_object
if o:
    print("%s (%s)" % (o.name, o.type), getattr(o, "energy", "Has NO energy property"))
    o = o.data
    if o:
        print("%s (%s)" % (o.name, o.type), getattr(o, "energy",  "Has NO energy property"))

If you grab a datapath from the DATA Properties panel, eg mesh panel for mesh objects, the datapath will be resolvable on the data part. context.active_object.data (except for empties, whose data part is None)


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.