1
$\begingroup$

I am creating a lot of armatures using python. One of the things I need to do is set the rotation_mode on all the bones to be 'XYZ' instead of 'QUATERNION'.

Unfortunately the following (super-trimmed-down) code malfunctions:

import bpy

scn = bpy.context.scene
obj = bpy.data.objects.new('garbage', bpy.data.armatures['lids_armature.007'])
scn.objects.link(obj)

obj.pose.bones[0].rotation_mode = 'XYZ'

It gives me the following error:

Traceback (most recent call last):
  File "/home/thoth/art/mehndi/mehndi.blend/garbage", line 7, in <module>
AttributeError: 'NoneType' object has no attribute 'bones'
Error: Python script fail, look in the console for now...

What is the proper python technique for setting the bones' rotation_mode immediately after creation?

$\endgroup$
1
  • 1
    $\begingroup$ put a scene update in there after the link. scn.update() $\endgroup$
    – batFINGER
    Aug 9, 2016 at 18:33

1 Answer 1

1
$\begingroup$

LucaRood in IRC was the first one to suggest using scn.update() after the link(). batFINGER and my testing agree with that solution. So the proper code would be

import bpy

scn = bpy.context.scene
obj = bpy.data.objects.new('garbage', bpy.data.armatures['lids_armature.007'])
scn.objects.link(obj)

scn.update()
obj.pose.bones[0].rotation_mode = 'XYZ'
$\endgroup$

You must log in to answer this question.

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