I have a dict of 2d data and I want to generate bones (skeleton), assuming z = 0 for translation and rotation is across z axis in given dict.

data = {"bones":[{"name":"root"},

here is my blender script to iterate on the dict. I can create bones. currently placing new bone on top of each other(almost). what I can handle is, initial head position directly , on x and y coords placing tail position directly via length but

HOW to apply rotation? any ideas

Sample code for current progress..

import json,os,sys
from mathutils import Matrix
from mathutils import Vector
import bpy

def createBaseArmature():
    ob = bpy.context.object
    return ob
def createBones(amt,bonesData):
    print (str(len(bonesData)) + " bones found")
    for each in bonesData:
        bone = amt.edit_bones.new(each['name'])
        if 'parent' in each:
            bone.parent = amt.edit_bones[each['parent']]
            bone.head = bone.parent.tail
            rot = Matrix.Translation((0,0,0))
            bone.tail = rot * Vector ((0,0,each['length'])) + bone.head
            bone.head = (0,0,0)
            bone.tail = (0,0,1)

obj = createBaseArmature()
amt = obj.data

1 Answer 1


While you can adjust the head/tail/roll directly, EditBone's have a helper function for this: EditBone.transform, which I think is the most direct answer to your question, just pass a rotation matrix to it.

This is simply a python helper function, see the code.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .