# How to apply list of rotations to multiple bones using animation nodes

Currently I am using Expression node to apply rotation to a single bone, is there a way to apply a list of rotations to multiple bones using a single Expression node? I have tried everything, but this expression doesn't accept lists

The order of rotations and the bones is the same.

While it is not encouraged, you can technically use list comprehensions as follows. A list comprehension takes the form:

[element.attribute for element in elements]


element.attribute has to be an actual object, thus writing an assignment operator instead like bone.rotation_quaternion = quat won't work, because assignment operators won't return anything. However, if you used the setattr() function, it will execute and return None. In conclusion, you can write the expression as follows:

[setattr(bone, "rotation_quaternion", quaternion) for bone, quaternion in zip(object.pose.bones, quaternions)]


If you want to assign the quaternion only to the bones at the indices defined by an integer list, you would use an expression as follows:

[setattr(object.pose.bones[i], "rotation_quaternion", quaternions[i]) for i in indices]


Instead of looping over the bones and quaternions themselves, you loop over the indices and get the bones and quaternions at the current index.

If you quaternion list is masked based on the indices, then you should loop over the quaternions directly as follows:

[setattr(object.pose.bones[i], "rotation_quaternion", quaternion) for i, quaternion in zip(indices, quaternions)]


• Thank you Omar, bone can be an index or bone name lists, right? Sep 3 '18 at 20:34
• @Denis No, bone is an object (Python object). Your inputs to the expression node should be 1. object: Your armature. 2. quaternions: Your quaternion list. Sep 3 '18 at 20:37
• That works perfect, but how would I modify the expression if I want to filter the bones? Sep 3 '18 at 20:49
• @Denis What do you mean by "filter the bones"? You want to apply the assignment to only a number of specific of bones? What should define whether a bone should have an assignment or not? Based on its name? A boolean list? A list of indices? Sep 4 '18 at 9:52
• I apply the rotation to specific bones and use a list of indices, for example: [2,3,4,7,8,9] Sep 4 '18 at 14:31