I always use the following code to rotate the bones.
bone.rotation_euler = 30.0 bone.rotation_euler = 30.0 bone.rotation_euler = 30.0
However, this code seems to be slow. Is there a faster way?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
Besides setting all three at once,
bone.rotation_euler = [x,y,z], if you want to change all the bones at once, you can use foreach_set to do them in a batch
data =  for bone in bones: rot_x = 30.0 rot_y = 30.0 rot_z = 30.0 data += [rot_x, rot_y, rot_z] bones.foreach_set("rotation_euler", data)
However this doesn't cause an update to the armature transforms (if you're looking at the bones in the viewport, nothing changes). The only way I could find to update is a normal assignment to any bone
# Forces armature transforms to be updated bones.rotation_euler = bones.rotation_euler
This also probably explains why assigning the rotation_euler (or other pose properties) is slow: it causes a recalculation of all armature transforms.
If by "slow" you mean slow to write, then how about using Python's tuple assignment:
bone.rotation_euler = 30.0, 30.0, 30.0
Since all values are the same, you can use a list multiplication:
bone.rotation_euler = [30.0]*3
And in this case you could use
30 instead of
30.0 - the value would be still converted to float:
>>> my_object.rotation_euler Euler((40.0, 40.0, 40.0), 'XYZ') >>> my_object.rotation_euler = *3 >>> my_object.rotation_euler Euler((30.0, 30.0, 30.0), 'XYZ')
When in console, remember you can use very effective Tab autocompletion. You can use it in text block editing too, but there it's only based on existing words in current text block.