Getting a bone as an object

Okay, bit of background: I’m relatively new to python, but I’ve coded a little application that lets the user pose his/her armatures and therefore models using the Xbox Kinect for 360. It works via the game engine so the user could theoretically make a game that is controlled by the player’s physical bodily movements.

All that works fine, but now I want the python script to record the bone animations onto the timeline so they can be accessed after the game engine has closed.

So far, I’ve got the code that’ll add a keyframe, which goes something like this:

obj = bpy.data.objects["Armature"]
obj.keyframe_insert(data_path="location", frame=1.0, index=2)
obj.location[2] = 1.0
obj.keyframe_insert(data_path="location", frame=2, index=2)

Of course, that only makes a key-frame for the armature, not the bones. What I want to know is, how can I create a variable of the same type of obj, but that represents the bones contained within the armature?

Sorry if my explanation isn’t very good, but can anyone help plz?

Thanks!

hm… do you wanna know how to create armature bones?
Here are a few code snippets:
http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Code_snippets/Armatures

I discourage using keyframe_insert, it’s too slow compared to the low-level functions, see:
http://www.blender.org/documentation/blender_python_api_2_66_release/info_quickstart.html#animation

Thx, will give it a try with the low-level functions :slight_smile:

I don’t want to create the bones, they already exist. I want to create a keyframe for a bone’s new location. I’ll try using the low-level code. Any idea how that works with respect to bones, though, not objects? When I try getting a bone via
bpy.data.objects[“BoneName”] it says it can’t find the object, and when I try doing it with a bone that I’ve got by doing ow.channels[“BoneName”], where ow is the owner of the function that I’ve got running, it says that .animation_data_create() isn’t a function for the type. Help?