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.

enter image description here


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)]

Node Tree

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.

Node Tree

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)]

Node Tree

  • $\begingroup$ Thank you Omar, bone can be an index or bone name lists, right? $\endgroup$
    – Denis
    Sep 3 '18 at 20:34
  • $\begingroup$ @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. $\endgroup$
    – Omar Emara
    Sep 3 '18 at 20:37
  • $\begingroup$ That works perfect, but how would I modify the expression if I want to filter the bones? $\endgroup$
    – Denis
    Sep 3 '18 at 20:49
  • $\begingroup$ @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? $\endgroup$
    – Omar Emara
    Sep 4 '18 at 9:52
  • $\begingroup$ I apply the rotation to specific bones and use a list of indices, for example: [2,3,4,7,8,9] $\endgroup$
    – Denis
    Sep 4 '18 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.