4
$\begingroup$

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.

$\endgroup$

1 Answer 1

3
$\begingroup$

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:

>>> bone = C.object.data.edit_bones.new("test")
>>> bone.head = (0, 1, 0)
>>> bone.tail = (1, 1, 0)
>>> bpy.ops.object.mode_set(mode='OBJECT')
# The new bone won't disappear after exiting edit mode.
$\endgroup$
1
  • $\begingroup$ I have the same problem but I want to use a matrix, how do I do that? $\endgroup$
    – majidarif
    Commented Sep 13, 2016 at 13:28

You must log in to answer this question.

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