I am using Blender 2.49b. I have a hand model and I would like to set the bone rotation (in quaternions) to take values from text (Bone%i.txt); on each column of the text I have 4 values (W,X,Y,Z). My hand model consists of 25 bones, as can be seen in the following image.
So, I wrote the following script to do the job
from Blender import *
import math
# Path to data directory
dataDirectory = 'C:/Users/andarist/Desktop/Data'
# Number of frames to render
numFrames = 100
# Range of bones
handIndices = range(1,26)
# Bone file name patterns
bonePattern = 'Bone%i.txt'
# Hand object pattern
handObjectPattern = 'Bone.%03i'
# Global scale
scale = 1.0
# Global speed
speed = 1
def FrameChange():
pass
def SetIpoForFrame(frame):
frameIdx = (Get('curframe') - 1) * speed
Set('curframe', frame)
frameIdx = (frame - 1) * speed
dataStore = Registry.GetKey('MoCapImporter')
nanmap = { }
# Move bones
for handIdx in handIndices:
handObj = Object.Get(handObjectPattern % handIdx)
pos = dataStore['Bone'][handIdx-1][frameIdx]
nanmap[handObjectPattern % handIdx] = False
if(pos == None):
nanmap[handObjectPattern % handIdx] = True
pos = nanpos
handObj.setRotation(scale*pos[0], scale*pos[1], scale*pos[2], scale*pos[3])
handObj.insertIpoKey(Object.IpoKeyTypes.LOCROTSIZE)
Scene.GetCurrent().update()
def LoadFile(pattern, index):
fileName = dataDirectory + '/' + (pattern % index)
file = open(fileName)
lines = file.readlines()
output = []
for line in lines:
c = line.split()
if(c[1] == 'NaN'):
output.append(None)
else:
output.append((float(c[0]), float(c[1]), float(c[2]), float(c[3])))
file.close()
print "Read %i lines from %s" % (len(output), fileName)
return output
def Main():
dataStore = { 'Bone': [] }
# Attempt to load the data
for handIdx in handIndices:
data = LoadFile(bonePattern, handIdx)
dataStore['Bone'].append(data)
Registry.SetKey('MoCapImporter', dataStore, False)
for i in range(1, numFrames+1):
print "Frame %i/%i" % (i, numFrames)
SetIpoForFrame(i)
if((event == 'FrameChanged') or (event == 'Render')):
FrameChange()
elif(event == ''):
Main()
However, it seems that the Object.Get function cannot find the bone.%3i from Armatures hand, and I get the following error
Thanks in advance for your help and consideration.
Best Wishes,
Andreas


Blender.Object.Get(handObjectPattern % handIdx)returns a blender object, whereas you want to get a bone from the hand objects pose bone collection. Is there a getPose() and or PoseBoneDictionary()... – batFINGER Mar 02 '16 at 11:39pose = arm_ob.getPose()pbones = pose.bones.values()Agree with @sambler if you are unfamiliar with 2.49 API why not start afresh and open in recent version. – batFINGER Mar 03 '16 at 12:12