Can you animate edit_bones using python?

So I’m(noob in blender) trying to make a script that reads points and makes an animation for armature. I was thinking I can change edit_bones tail and head location and make framekeys for location, rotation and scale for armature.pose.bones, but it didn’t work for me. Is it even posible or there is another way to animate bones from script?

My code look like this:

import bpy

def set_edit_mode(check = True):
    if check:
        if bpy.context.active_object.mode == 'OBJECT':
            bpy.ops.object.editmode_toggle()
    else:
        if bpy.context.active_object.mode == 'EDIT':
            bpy.ops.object.editmode_toggle()

armature = bpy.data.objects['Armature']
armature.select_set(True)

armData = armature.data

set_edit_mode()
ebone = armData.edit_bones['Bone']

pbone = armature.pose.bones['Bone']

bpy.context.scene.frame_current = 0

ebone.tail = (0,0,1)
ebone.head = (0,0,0)

pbone.keyframe_insert('location', frame = 0)
pbone.keyframe_insert('rotation_euler', frame = 0)
pbone.keyframe_insert('scale', frame = 0)

bpy.context.scene.frame_current = 60

ebone.tail = (1,1,1)
ebone.head = (-1,-1,-1)

pbone.keyframe_insert('location', frame = 60)
pbone.keyframe_insert('rotation_euler', frame = 60)
pbone.keyframe_insert('scale', frame = 60)

It’s for one bone and no animation’s being made.
I think the location might be of an armature but why? Can some one help me?

This is not a simple topic, so be aware you’re jumping in the deep end of Blender Python. That said, these may help:

1 Like

Hello, ultimately I"m sure it’s doable, but it’s really not the way you should use bones and armatures…

I don’t think it’s possible to animate edit bones positions, but you can always manage to store the position and interpolate between keys, basically creating a small anim system within your script…

The way you can make it work properly is to add one bone per point, and animate their location in pose mode.

Then you add an armature that uses on each bones either copy location and stretch to constraints ( you can try track to as well) …
That way from the location of each points you can manage to make rotations…

That said, it’s a bit involved if you’re new to blender, I suppose you already are experienced in 3D at least ?
Nothing super complex either but it can take some time to figure everything out !

Good luck !

2 Likes

Damn, why I didn’t think of this, using the hole bone for point. Thanks I think this will do. Even if it will look junky I need at least smth.

1 Like