Orient a bone in world space?

Hi,

I tried convert_space but it does not seem to work (deprecated?)

>>> bone = C.object.pose.bones[10]
>>> bone.convert_space()
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
AttributeError: 'PoseBone' object has no attribute 'convert_space'

anybody knows what is wrong with my code ?
thanks for your help

It looks like this is the one

https://docs.blender.org/api/current/bpy.types.Bone.html?highlight=convert_space#bpy.types.Bone.convert_local_to_pose

thanks, I saw that doc too
but I dont understand why my code does not work

I mean is not an object ?

should I be in edit mode ? the whole idea is to orient a bone in world space in pose mode

This script will set a bone, in pose mode, to rotate to 90 degrees (feel free to tweak the values).

import bpy, math

# GET ARMATURE OBJECT
armature = bpy.data.objects["Armature"]
# SET MODE TO POSE
bpy.ops.object.mode_set(mode="POSE")
# GET ARMATURE BONE WHILE IN POSE MODE
bone = armature.pose.bones["Bone.001"]
# SET ARMATURE BONE ROTATION
bone.rotation_quaternion[0] = math.radians(90)
bone.rotation_quaternion[1] = math.radians(90)
bone.rotation_quaternion[2] = math.radians(0)
bone.rotation_quaternion[2] = math.radians(0)
# SET MODE BACK TO OBJECT
bpy.ops.object.mode_set(mode="OBJECT")
1 Like

thanks but these are local coordinates

my goal is to orient a bone in world space so I need to calculate matrices(invert?) multiplications from the root bone to the bone I want to orient

Could you share a few screenshots or even better a video of what you’re trying to accomplish?
I have a better picture now of what you want, but I am still having trouble figuring out what kind of rotation behavior you are expecting.