Constraints may be applied to objects as well as to bones. In both instances a new constraint is added by calling the append()
method of the constraints
attribute. Our next example will show how we may restrict the movement of the clock hands from the rigged clock (fromChapter 3, Vertex Groups and Materials) to rotate around the z-axis. The code defining the function to accomplish this starts off with two import
statements that will save us some typing:
from Blender.Constraint import Type from Blender.Constraint import Settings
The function itself will take two arguments: obbones
, a reference to a Blender object whose data is an armature (that is, not the armature object itself) and bone
, the name of the bone whose motion we would like to restrict. It is important to understand that the constraint that we will associate with a bone is not a property of the armature but of the pose of the object containing the armature. Many objects may refer to the same armature and any poses are associated with the object so different objects referring to the same armature may strike different poses.
So the function starts off by getting the pose first and then a reference to the bone that we want to constrain. The highlighted line shows how to associate the constraint (this would be similar if we would associate a constraint with a Blender object instead of a bone):
def zrotonly(obbones,bone):
poseob = obbones.getPose()
bigarmpose = poseob.bones[bone]
c=bigarmpose.constraints.append(Type.LIMITROT)
c[Settings.LIMIT]=Settings.LIMIT_XROT|Settings.LIMIT_YROT
c[Settings.XMIN]=0.0
c[Settings.XMAX]=0.0
c[Settings.YMIN]=0.0
c[Settings.YMAX]=0.0
poseob.update()
The newly appended constraint is retained as the variable c
and the subsequent lines show that the different attributes of a constraint may be accessed like a dictionary. First, we configure the LIMIT
attribute (a bitmap) to limit the rotation of the x and y axes. Next, we set the minimum and maximum of the rotations around these axes to 0.0
, as we disallow any movement. In the rigging of a realistic animal skeleton, for example, these values could be set to limit the extent of the rotation to values comparable with a real joint. Finally, to make the changes to our Pose
object visible, we call its update()
method.
18.189.170.134