script to move two bones

The interface, modeling, 3d editing tools, import/export, feature requests, etc

Moderators: jesterKing, stiv

sabharish
Posts: 16
Joined: Tue Oct 09, 2012 10:51 pm
Location: India

script to move two bones

Postby sabharish » Mon Oct 29, 2012 9:15 am

Hi,
Can anyone help me how to move two bones closer or farther using python script?

thanks.

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

Postby CoDEmanX » Mon Oct 29, 2012 1:56 pm

Bones, EditBones or PoseBones?
I'm sitting, waiting, wishing, building Blender in superstition...

sabharish
Posts: 16
Joined: Tue Oct 09, 2012 10:51 pm
Location: India

Postby sabharish » Mon Oct 29, 2012 6:34 pm

Edit bones...

Thanks in advance

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

Postby CoDEmanX » Tue Oct 30, 2012 8:35 am

you need to be in edit mode to have edit_bones available:

Code: Select all

# should check here for context.object, 'cause mode_set will fail if it's None
# Or set new selected/active ob
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

# move first editbone's head of 'Armature' by 1 unit on x-axis
bpy.data.armatures['Armature'].edit_bones[0].head.x += 1


So it's EditBone.head and EditBone.tail
I'm sitting, waiting, wishing, building Blender in superstition...

sabharish
Posts: 16
Joined: Tue Oct 09, 2012 10:51 pm
Location: India

Postby sabharish » Thu Nov 01, 2012 7:13 am

Hi,
I want to move both bones closer or farther at the same time. Its not that one bone is stationary and you can move other.
Thanks.

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

Postby CoDEmanX » Thu Nov 01, 2012 10:10 am

you can change how many bones you want, e.g.


Code: Select all

bpy.data.armatures['Armature'].edit_bones[0].head.x += 1
bpy.data.armatures['Armature'].edit_bones[1].head.x += 1
bpy.data.armatures['Armature'].edit_bones[0].tail +=(1.5, -0.5, 1)


but you may look into Constraints if you wanna let one bone move when the other moves.
I'm sitting, waiting, wishing, building Blender in superstition...


Return to “Interface & Tools”

Who is online

Users browsing this forum: No registered users and 0 guests