Multiple Object Renaming Script for Rigging

Hi!

To make it short: I was tired of constantly renaming a lot of bones and objects during the rigging process and wrote a script to do just that.
It does find & replace, prefixes, suffixes and earases starting/ending letters.

Hopefully this is useful to some people :slight_smile:


# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

bl_addon_info = {
    "name": "MultiRename",
    "author": "DeeTee",
    "version": (0,1),
    "blender": (2, 5, 5),
    "api": 32738,
    "location": "View3D > Toolbar",
    "description": "Provides a functions for renaming multiple objects and bones",
    "warning": "",
    "wiki_url": "",
    "tracker_url": "",
    "category": "Object"}

import bpy

class VIEW3D_PT_tools_multiobjectrename(bpy.types.Panel):
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    bl_context = "objectmode"
    bl_label = "Renamer"

    def draw(self, context):
        layout = self.layout

        col = layout.column(align=True)
        col.operator("object.multi_object_rename")


class VIEW3D_PT_tools_multibonerename(bpy.types.Panel):
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    bl_context = "armature_edit"
    bl_label = "Renamer"

    def draw(self, context):
        layout = self.layout

        col = layout.column(align=True)
        col.operator("object.multi_object_rename")


class VIEW3D_PT_tools_multiposebonerename(bpy.types.Panel):
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    bl_context = "posemode"
    bl_label = "Renamer"

    def draw(self, context):
        layout = self.layout

        col = layout.column(align=True)
        col.operator("object.multi_object_rename")


def doMultiObjectRename(context, eraseString, replacementString, trimStart, trimEnd, newPrefix, newSuffix):
    if context.mode == 'EDIT_ARMATURE':

        for bone in context.selected_bones:
            temp = bone.name[trimStart:]
            if trimEnd > 0:
                temp = temp[:-trimEnd]
            temp = temp.replace(eraseString, replacementString)
            temp = newPrefix + temp + newSuffix
            bone.name = temp[:]


    elif context.mode == 'OBJECT':

        for obj in bpy.context.selected_objects:
            temp = obj.name[trimStart:]
            if trimEnd > 0:
                temp = temp[:-trimEnd]
            temp = temp.replace(eraseString, replacementString)
            temp = newPrefix + temp + newSuffix
            obj.name = temp[:]

        
    elif context.mode == 'POSE':

        for bone in context.selected_pose_bones:
            temp = bone.name[trimStart:]
            if trimEnd > 0:
                temp = temp[:-trimEnd]
            temp = temp.replace(eraseString, replacementString)
            temp = newPrefix + temp + newSuffix
            bone.name = temp[:]


class MultiObjectRename(bpy.types.Operator):
    '''Find & Replace-functionality for names'''
    bl_idname = "object.multi_object_rename"
    bl_label = "Rename Objects"
    bl_description = "Operator with Find & Replace-functionality for object names and bone names"
    bl_options = {'REGISTER', 'UNDO'}
    
    eraseString = bpy.props.StringProperty(name="Find String",
        description = "The string to look for in the object names",
        )

    replacementString = bpy.props.StringProperty(name = "Replace with",
        description = "The replacement for the string given above",
        )
    
    trimStart = bpy.props.IntProperty(name="Trim Start:",
        description = "Erases the specified number of letters from the beginning of the object names",
        min = 0,
        max = 50,
        default = 0,
        )

    trimEnd = bpy.props.IntProperty(name="Trim End:",
        description = "Erases the specified number of letters from the end of the object names",
        min = 0,
        max = 50,
        default = 0,
        )

    newPrefix = bpy.props.StringProperty(name = "Prefix with",
        description = "Adds the specified letters to the beginning of the object names",
        )

    newSuffix = bpy.props.StringProperty(name = "Suffix with",
        description = "Adds the specified letters to the end of the object names",
        )

    
    @classmethod
    def poll(cls, context):
        return context.active_object != None

    def execute(self, context):
        doMultiObjectRename(context, self.eraseString, self.replacementString,
            self.trimStart, self.trimEnd,
            self.newPrefix, self.newSuffix)
        return {'FINISHED'}


def register():
    pass

def unregister():
    pass

if __name__ == "__main__":
    register()

Btw: Iโ€™m really new to python scripting, so there might be some problems, but donโ€™t worry you can always use undo if something goes wrong.