I’m trying to write a script that will change the name of a parent bone. However digging for data I’m not getting what I suspected to get. I realize that to change data I will have to do it through Edit_Bones not data.bones, I’m just searching for names at this point.
My code currently looks like this:
bpy.ops.object.mode_set(mode="OBJECT")
for ob in bpy.data.objects:
if ob.type == "ARMATURE" and ob.users !=0:
for bone in ob.data.bones:
print('%s, %s' %(bone.name, bone.parent))
What it returns look like this:
pelvis, None
spine_01, <"bpy_struct, Bone("pelvis")>
spine_02, <"bpy_struct, Bone("spine_01")>
spine_03, <"bpy_struct, Bone("spine_02")>
spine_04, <"bpy_struct, Bone("spine_03")>
The return is correct, but I want to be able to just return the parent bone name and be able to change it to something else.
If I try to use bone.parent.name
the script errors out on the Root (Pelvis) Bone with a NoneType Error.
Traceback (most recent call last): File "C:\Users\ME\Desktop\PKTEST\Clown_REdo.blend\toTxt_BoneRolls.py", line 41, in AttributeError: 'NoneType' object has no attribute 'name' Error: Python script fail, look in the console for now...
How would I get just the Parent name (Right side of the comma) for the bone on the left?
None
indicates no parent bone. Something likegetattr(bone.parent, "name", "None")
will return "None" if thebone.parent is None
. $\endgroup$