I'm trying to render different images of hand gestures using python, but for some reason, I'm unable to get the hand armature bones to move. I'm using Manuel Bastoni for the model. http://www.manuelbastioni.com/

Here's the code that I have right now:

for bone in bones:
    x = bone.location[0] + random.uniform(-0.2, 0.2)
    y = bone.location[1] + random.uniform(-0.2, 0.2)
    z = bone.location[2] + random.uniform(-0.2, 0.2)
    bone.location[0] = x
    bone.location[1] = y
    bone.location[2] = z
bpy.context.scene.render.filepath = outfile_name

I saw that in the python console, bone.location = (x, y, z) works perfectly fine to manipulate the bones, but it's not working here.

Please let me know what I can do to manipulate the pose bones through a python script!



1 Answer 1


I'd avoid using ops to set the mode to Pose Mode.

Access the bones directly through the hierarchy as it is exposed through the api.

import bpy
import random

armature = bpy.context.scene.objects['Armature']

for pose_bone in armature.pose.bones:
    x = pose_bone.location[0] + random.uniform(-0.2, 0.2)
    y = pose_bone.location[1] + random.uniform(-0.2, 0.2)
    z = pose_bone.location[2] + random.uniform(-0.2, 0.2)
    pose_bone.location[0] = x
    pose_bone.location[1] = y
    pose_bone.location[2] = z
  • $\begingroup$ Hi, I was already accessing the bones using the following: rig = bpy.context.scene.objects['f_ca01_skeleton'] bones = list(rig.pose.bones) Is there any other way for me to access the armature? Thank you! $\endgroup$
    – user58033
    Commented Jun 21, 2018 at 16:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .