Armature bones created in python disappear after exiting edit mode I'm writing an importer for a file format with skeletal data, so I'd like to generate an armature with bones to represent it. I can put the object into edit mode and create EditBones without any trouble, but the bones then vanish as soon as I exit edit mode.

As far as I can tell, exiting Edit mode is supposed to convert EditBones to actual Bones, but that's not happening. Instead, when I exit Edit mode, the armature is reset back to the state it was in before I entered Edit mode.

Here's a test case that can be run line-by-line in Blender's Python console.

# Create a new armature, make it active, and put it into edit mode.
bpy.ops.object.armature_add( enter_editmode=True )

# Add a new bone named "test"
C.object.data.edit_bones.new( "test" )

# At this point, you can see the armature object with two bones ("Bone" and "test") in the Outliner

# Exit Edit mode by switching back to Object mode.
bpy.ops.object.mode_set( mode='OBJECT' )

# Result: the "test" bone vanishes without a trace.


I've tried a bunch of variations, all with the same end result. It feels like I'm missing a step; perhaps something to explicitly apply the edits.

I'm using Blender 2.68a and Blender 2.69.
At the point of creation, the new bone's head and tail is both (0, 0, 0), which gives zero (invalid) length. You only need to modify at least one of them, giving a valid length, to keep the new bone outside of Edit mode:

&gt;&gt;&gt; bone = C.object.data.edit_bones.new("test")
&gt;&gt;&gt; bone.head = (0, 1, 0)
&gt;&gt;&gt; bone.tail = (1, 1, 0)
&gt;&gt;&gt; bpy.ops.object.mode_set(mode='OBJECT')
# The new bone won't disappear after exiting edit mode.