Bones have two rotations. One is the rest orientation, and the other is the pose orientation.
The pose orientation is manipulated something like
obj.pose.bones[0].rotation_mode = 'QUATERNION'
obj.pose.bones[0].rotation_quaternion = q
But the rest orientation requires you to be in edit mode, and you have two choices. You can manipulate the head, the tail, and the roll (requires extra math). Or you can set the head and tail to a base state and use functions to transform the bone (and let those functions do the math for you). Here's an excerpt from http://web.purplefrog.com/~thoth/blender/python-cookbook/bone-orientation-demo.html
translate = Vector([0,0,1])
bpy.ops.object.mode_set(mode='EDIT')
bone = obj.data.edit_bones[0]
bone.head = [0,0,0]
bone.tail = [0,1,0] # Using the Y axis is pretty important, otherwise we can't use the inverse of Q to pose the cube to an unrotated state
bone.transform(q.to_matrix())
bone.translate(translate)
I learned about EditBone.transform from How to rotate an EditBone? is it possible .
I'll just jump to the conclusion that you want to alter the pose. The other weird problem with your code is that it looks like you are setting the orientation of each bone several times (handIndices) and replacing a keyframe each time. Since you are having difficulty updating your code to use the techniques in my examples, here is a rewritten version of your code with a couple of alternative implementations to choose from:
scn = Scene.GetCurrent()
arm_ob = scn.objects.active
bones = arm_ob.pose.bones
if False:
#more like the original code
for bone in bones:
# use bone here
for handIdx in handIndices:
# why are we setting the rotation several times for the same bone?
pos = dataStore['Bone'][handIdx-1][frameIdx]
bone.rotation_quaternion = pos
bone.insertIpoKey(Object.IpoKeyTypes.LOCROTSIZE)
else:
# maybe handIndices is a list of bone indices?
for handIdx in handIndices:
pos = dataStore['Bone'][handIdx-1][frameIdx]
bone = bones[handIdx-1]
bone.rotation_quaternion = pos
bone.insertIpoKey(Object.IpoKeyTypes.LOCROTSIZE)
Scene.GetCurrent().update()