1
$\begingroup$

I am trying to write a python code, that when run can change the parent of bones given in a list.

this is my code so far.

import bpy
context = bpy.context
arm = bpy.data.objects['Armature']
namelist= [["mWristLeft","mElbowLeft"]]
for parent, newparent in namelist: 
pb = arm.data.edit_bones.get(parent)
if pb is None:
 continue
 pb.parent = newparent 

I'm not sure what I'm doing wrong because the script runs but nothing happens. So for instance the script should be parenting "mWristLeft" to "mElbowLeft" if the script was running properly. any help on this would be appreciated.

$\endgroup$

1 Answer 1

1
$\begingroup$

Change to bpy.data.armatures['Armature'].edit_bones. To set a parent you need the edit_bone itself not only the name of the bone.

import bpy
context = bpy.context
#arm = bpy.data.objects['Armature']
arm = bpy.data.armatures['Armature']  # changed
namelist= [["mWristLeft","mElbowLeft"]]
for parent, newparent in namelist: 
    if arm.edit_bones[parent].parent:
        print("actual parent is:", arm.edit_bones[parent].parent)
    else:
        print("no parent - new parent is '%s'" % newparent)
        arm.edit_bones[parent].parent = arm.edit_bones[newparent]
$\endgroup$
1
  • $\begingroup$ Thank you Relaxed, sorry for the super late reply, That is what I needed! Thank you very much for your help. $\endgroup$ Nov 24, 2023 at 23:38

You must log in to answer this question.

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