[Bf-committers] Constraints API

Ken Hughes khughes at pacific.edu
Tue May 9 03:48:31 CEST 2006


malefico andauer wrote:
> Hi Ken,
> 
> We are playing with Constraint module, but the fact
> that is an attribute of poses instead of bones,
> confuses us a little...
> 
> We tried the example script in the docs and got error.
> 
> Sorry my ignorance, but shouldn't this be more logical
> if we just iterate around the bones in an armature and
> get the constraints each bone has ? Don't really get
> what the poses mean and why this is the way to access
> to constraints...

The design is based on explanations from Joseph Gilbert and Ton, and 
from Ton's description here:

http://www.blender.org/cms/How_Armatures_work.634.0.html

Short version: the armature defines the bones, but the pose (which 
belongs to an object) describes the position of the bones.

> Can you check the example you posted in the docs and
> explain it or provide some other example ?
> 
> The code in the docs is:
> 
> ---------
> from Blender import *
> 
> ob = Object.Get('Armature')
> for bonename in pose.bones.keys():
>   bone = pose.bones[bonename]
>   for const in bone.constraints:
>     print bone.name,'=>'const.type
> ----------
> 
> We changed it to:
> 
> ------------
> from Blender import *
> 
> pose = Armature.Get('Armature')
> for bonename in pose.bones.keys():
>   bone = pose.bones[bonename]
>   for const in bone.constraints:
>     print bone.name,'=>',const.type
> -------
> 
> ...to get rid of some error messages, but we're stuck
> on "
> 
> Traceback (most recent call last):
>   File "test_constraint.py", line 6, in ?
>     for const in bone.constraints:
> AttributeError: 'Bone' object has no attribute
> 'constraints'


Sorry: the example should be:

   from Blender import *

   ob = Object.Get('Armature')
   pose = ob.getPose()
   for bonename in pose.bones.keys():
     bone = pose.bones[bonename]
     for const in bone.constraints:
       print bone.name,'=>',const

I've updated CVS with the correction.

Ken



More information about the Bf-committers mailing list