armature_add() function positioning error

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
wretch1958
Posts: 0
Joined: Thu Mar 29, 2012 6:26 am

armature_add() function positioning error

Post by wretch1958 » Sun Apr 29, 2012 8:11 am

Code: Select all

vec1 = [0, 0, 0]

bpy.ops.object.armature_add(view_align=False, enter_editmode=False, location=vec1, rotation=(0, 0, 0), layers=(True, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))

vec1 = [0, 0, 5]

bpy.ops.object.armature_add(view_align=False, enter_editmode=False, location=vec1, rotation=(0, 0, 0), layers=(True, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
Is there a bug with the armature add function, when the position vector is anything other than 0,0,0 ???? In the above code, the first armature command works fine but the second one does not put the armature above the first one along the z axis. In fact, it appears to reset the origin or something?

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX » Sun Apr 29, 2012 1:39 pm

dunno if this is a bug or a feature

It creates the Armature object at the given coordiante, but the initial bone's head gets placed at 3D cursor position, tail 1 unit in z-direction above 3d cursor.

Code: Select all

vec1 = (0, 0, 0)

bpy.context.scene.cursor_location = vec1

bpy.ops.object.armature_add(view_align=False, enter_editmode=False, location=vec1, rotation=(0, 0, 0), layers=(True, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))

vec2 = (0, 0, 5)

bpy.context.scene.cursor_location = vec2

bpy.ops.object.armature_add(view_align=False, enter_editmode=False, location=vec2, rotation=(0, 0, 0), layers=(True, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
I'm sitting, waiting, wishing, building Blender in superstition...

wretch1958
Posts: 0
Joined: Thu Mar 29, 2012 6:26 am

Post by wretch1958 » Fri May 04, 2012 9:37 am

Thanks "codemanx". !!!

ldo
Posts: 0
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand

Post by ldo » Mon May 07, 2012 1:09 pm

I hate seeing repetitive code. To generate the layers tuple, how about

Code: Select all

(True,) + 19 * (False,)
or even

Code: Select all

tuple( i == 0 for i in range(0, 20))
where the 0 can be changed to any other layer number to correctly generate a tuple that has a single True element at the right index.

If you want the object to be in more than one layer, say it needs to go on layers 1, 3 and 5, then do

Code: Select all

tuple( i in (1, 3, 5) for i in range(0, 20))
Isn’t that so much easier to write?

Post Reply