Change the Bone Rotation (Quaternions) of an Armature in text script 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
Might be hard finding someone that remembers how to use python in 2.49. The 2.49 api docs are still available here.

The second example on the armature page might be what you are looking for - while the docs list Get() as a function the example uses arm_ob.getData()

scn= Scene.GetCurrent()
arm_ob= scn.objects.active
arm_data= arm_ob.getData()
bones= arm_data.bones.values()

for bone in bones:
    # use bone here