move a bone using python on "frame change" scriptlink?

does anyone know a working python script that will get the position, then set the position of a bone in an armature using python so it can be activated on a frame change(using scriptlinks)?

any help would be MUCH appreciated, thank you very much :slight_smile:

I found the solution:
Here’s the simple way to have constraints that arent properly updating do what they “should”

use this as the python script that is triggered on FRAME CHANGE in your SCENE SCRIPT LINKS:

import Blender

ob = Blender.Object.Get('YourArmatureNameHere)



here’s the complex solution, now constraints UPDATE AUTOMATICALLY that would otherwise need the bone to be manually moved with the G key to update in the 3D window.

import Blender
from Blender import Draw, Object, Scene, Mathutils, Noise, Armature
from Blender import *

scn = Scene.GetCurrent()
ob = Blender.Object.Get(‘NameOfYourRig’)
pose = ob.getPose()
posebone = pose.bones[‘nameOfBoneYouWantToMoveHere’]

#print posebone.poseMatrix
print "

ref1 = Blender.Object.Get(‘Rig’).getPose().bones[‘nameOfYourBoneHere’]
ref2 = Blender.Object.Pose.PoseBone


print ‘refresh3’
print (ref1)

pose = ob.getPose()

#set variable for current frame
curfx1 = frame=Blender.Get(‘curframe’)
#print variable for current frame
print curfx1

if curfx1 == 1:
posebone.loc[0] = 0.5
posebone.loc[1] = 0.5
posebone.loc[2] = 0.5
print posebone.loc[0]
print posebone.loc[1]
print posebone.loc[2]
elif curfx1 == 2:
posebone.loc[0] = 0
posebone.loc[1] = 0
posebone.loc[2] = 0
print posebone.loc[0]
print posebone.loc[1]
print posebone.loc[2]
elif curfx1 == 3:
posebone.loc[0] = 1
posebone.loc[1] = 1
posebone.loc[2] = 1
print posebone.loc[0]
print posebone.loc[1]
print posebone.loc[2]



I have a scene with objects and bones (all of which belong to the same armature) that are constrained to the objects by copy location and copy rotation.

If I add the lines in your second will it make the bones move every time the script iterates over the objects to set their coordinates in space?

Thanks a lot

Yup! It works but I can’t make a parented mesh deform itself along the way. It’s weird because it moves alright when I grab or rotate each bone manually. Do you know why that may be?

You may want to take a look at that walking ant script that was posted here a week or so ago.

Sorry I don’t have a link.

got any more clues about how to look fot it? I’ve been googling it but can’t find it.

this script I’ve posted, truly only operates properly on framechange, I tried a number of methods to get constrained objects to properly position themselves in realtime while transforming/translating another object, but in the end I had to settle on the proper result of the computed constraints working only on framechange. this doesnt mean it impossible in another more real-time form, but I just want able to get it to work that way in the many tests I created/performed.

In the end, in my opinion, 2.49x has a LOT of hacks in its underpinnings, especially with regard to python. So, yes, you do have to maybe do a “move to next frame”, then go back to the previous frame you were working on to see the proper constrained result, but at least it works. 2.5 looks already to have fixed many/all of these issues, but for 2.49, given my time constraints for the project this was needed on , this was the best i could do at the time.

If you find a new solution to this issue in 2.4x, PLEASE post your finding, I would enjoy looking through them.

I have posed a blend file here

Download and Press ALT+A
Bone Angle changing according to Frame Changed. Script Link with Frame Changed.

Procedural ANT animation.

@Atom, thanks for the link. If you’ve already tested that blend:Do you know if that solves the realtime constraint&Bone calculation without the need for a framechange?

anybodoy test this in new versions? will it work to make my character aim with the arm???