[Bf-python] Setting Constraints to Bones (limitMin, limitMax, IKSOLVER & CHAINLEN)

kunze at informatik.uni-bonn.de kunze at informatik.uni-bonn.de
Fri Mar 2 11:37:52 CET 2007


Hi everybody,

I'm currently searching for a way to add constraints to bones via a Python
script. Below you see a script which adds an armature and two bones. I can
add the constraint IKSOLVER to the bones. But I'm not able to change
limitMin and limitMax! After executing the script, print limitMin(Max)
always results in "[0.000000, 0.000000, 0.000000](vector)"! I also want to
change the "chainlen" attribute via Pythonscript.
Does anybody know how to change these attributes?


The script:

import Blender
from Blender.Mathutils import *
from Blender import Armature as A
from Blender import *


scene = Blender.Scene.GetCurrent()

#create root-Object as an empty
root_obj = Blender.Object.New('Empty','root')
scene.link(root_obj)
root_obj.setMatrix(Matrix([1.0,0,0],[0,1.0,0],[0,0,1.0]))
root_obj.setLocation(Vector(0.0,0.0,0.0))

arm_obj = Blender.Object.New('Armature')
arm_data = Blender.Armature.Armature('ArmatureData')
arm_data.autoIK = True
arm_obj.link(arm_data)
scene.link(arm_obj)
arm_data.makeEditable()

boneA = A.Editbone()
boneA.head = Vector(0.0,0.0,0.0)
boneA.tail = Vector(0.0,0.0,10.0)
arm_data.bones['bone.001'] = boneA
boneA.options = [A.NO_DEFORM]

boneB = A.Editbone()
boneB.head = Vector(0.0,0.0,10.0)
boneB.tail = Vector(0.0,10.0,0.0)
arm_data.bones['bone.002'] = boneB
boneB.parent = arm_data.bones['bone.001']
boneB.options = [A.NO_DEFORM, A.CONNECTED]

arm_data.update()
arm_obj.loc = 0,0,0

pose = arm_obj.getPose()
Pose_boneB = pose.bones['bone.002']

Pose_boneB.constraints.append(Blender.Constraint.Type.IKSOLVER)

#Does not have any effect!!
Pose_boneB.limitMax = Vector([10.0, 10.0, 10.0])
Pose_boneB.limitMin = Vector(-10.0, -10.0, -10.0)


#always [0.000000, 0.000000, 0.000000](vector)
print "min/max = ", Pose_boneB.limitMax, Pose_boneB.limitMin



root_obj.makeParent([arm_obj], 0, 0)
Blender.Window.RedrawAll()





More information about the Bf-python mailing list