Inserting keyframes without ops results in property "location" not found

Hi
I’m trying to make a script where I move an object in every cycle of my for loop and then keyframe it’s location.
There are a lot of actions involved mainly over the NLA editor, so using bpy.ops.anim.keyframe_insert_menu(type=‘Location’) would not be that easy to handle. I’d much rather use:
obj.animation_data.action.keyframe_insert(data_path = ‘location’)
but no matter what I do, “Location”, “location”, ‘location’, ‘rotation_euler’ etc. it always tells me that property “location” cannot be found. Of course I also tried to define all the other arguments (index, frame, group), but always the same error.
What am I doing wrong?

You probably have to insert the keyframe using the object’s method obj.keyframe_insert . The RNA allows keyframes for many things. I think obj.animation_data.action.keyframe_insert would insert a keyframe for the action not for the object.

See the example in the api docs.

Working with NLA strips i think there is always one action assigned to an object which may contain nla tracks and keyframes.

obj.keyframe_insert inserts a keyframe for the current action assigned to obj.animation_data.action

You can get the actions from bpy.data.actions directly by their name and manipulate the fcurve’s which should be alot easier than using operators.

Thanks, that works. I looked in the docs, but only found ops. Do you happen to know if I can insert only a keyframe for x location?
The NLA is working like a charm, no problems there.

Nevermind, index = 0.