# How do I connect a bone to another bone via python script

I'm trying to make a chain of "segments", meaning I have 3 bones in a setup and I'd like to replicate them along the z-axis. I use a for loop to duplicate the entire armature, my object and then rename the bones of each segment. Which works best for vertex groups assignment.

I then use CtrlJ to join the meshes as well as the armatures. When I go into Edit Mode for the mesh, I can just use Remove Doubles to connect the pieces, but here is my problem:

When I join the armatures, I have a chain of bones that are not parented, so I was trying to find a method that does something like this:

for bone in arm.pose.bones:
i += 1
bone[i].parent = bone[i-1]


(pseudocode, but I hope you know what I mean)

But bone parent is read-only and the ops.pose.parent_set() only works if there is an active bone, but I could not figure out how to change the active bone. bone.select seems to always be True, so I'm not entirely sure how to us the ops. I hope there is a better way, like with objects, where you can just assign your parent object/bone.

## 1 Answer

Parenting is done in edit mode where you setup the armature.

arm.pose.bones already indicates it is related to posing bones.

Try:

arm.data.edit_bones['yourBone'].parent = arm.data.edit_bones['parentBone']

• Thanks for your quick reply, I didn't get that edit_bones was a collection, I thought it was a method and didn't look into it deep enough, so thanks. – Spiderguy Feb 18 '14 at 8:32