I have a script made for 3dsmax that renames bones in batch like this:

( local nameMap = #( \

    dataPair "Bip01_" "",
    dataPair "Neck01" "Neck",
    dataPair "phy_anchor_Skirt_00" "Pelvis",

And so on and so forth. How can I make the same for blender? Does anybody have something working, so I can just change the name of the bones, and press 'Run Script'?

Because as far as I can do, it only change exact names and not part of the name, this is what I've got:

import bpy
context = bpy.context
obj = context.object

namelist = [("Bip01_", "")]

for name, newname in namelist:
    # get the pose bone with name
    pb = obj.pose.bones.get(name)
    # continue if no bone of that name
    if pb is None:
    # rename
    pb.name = newname

What I would like that script to do is change ALL 'Bip01_' for nothing, like deleting a prefix.


1 Answer 1


You can have so called key-value pairs by using a dict. Script quickly tested against Rigify:

prefix_dict = {
        "Bip01_" : "",
        "Neck01" : "Neck",
        "phy_anchor_Skirt_00" : "Pelvis",
        "spine" : "Custom",

import bpy

C = bpy.context
obj = C.object

# Bone Lookup
for key_bones in obj.pose.bones.keys():
    # Check for all the keys in prefix dict
    for key_pre in prefix_dict.keys():
        repl_value = prefix_dict[key_pre]
        if key_bones.startswith(key_pre):
            # Bone found
            bone = obj.pose.bones[key_bones]
            # Rename the bone!
            bone.name = bone.name.replace(key_pre, repl_value)      

You must log in to answer this question.

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