How to Batch Rename Objects in Blender with Python
Batch renaming objects in Blender using Python is an efficient way to organize scenes, manage asset libraries, and prepare 3D models for export. This guide provides a straightforward method for writing and running a custom Python script in Blender's built-in Text Editor to automatically rename multiple selected objects simultaneously with custom prefixes, suffixes, or sequential numbering.
Setting Up the Scripting Workspace
- Open Blender and switch to the Scripting workspace from the top menu bar.
- In the Text Editor panel (usually in the center), click the New button to create a new script.
- Select the objects you want to rename in the 3D Viewport or the Outliner.
Script 1: Sequential Numbering Renaming
To rename all selected objects using a specific base name followed by an incrementing number, paste the following code into the Text Editor:
import bpy
# Set your desired base name
base_name = "MyObject"
# Iterate over all currently selected objects
for index, obj in enumerate(bpy.context.selected_objects, start=1):
obj.name = f"{base_name}_{index:03d}"Click the Run Script button (play icon) at the top
right of the Text Editor. The selected objects will be renamed to
MyObject_001, MyObject_002, and so on.
Script 2: Find and Replace Text in Object Names
To replace specific text across all selected objects without changing the rest of the name, use this script:
import bpy
# Define search and replace strings
search_term = "OldName"
replace_term = "NewName"
for obj in bpy.context.selected_objects:
if search_term in obj.name:
obj.name = obj.name.replace(search_term, replace_term)Script 3: Adding Prefixes or Suffixes
To prepend or append text to existing names across all selected objects:
import bpy
prefix = "SM_"
suffix = "_LOD0"
for obj in bpy.context.selected_objects:
obj.name = f"{prefix}{obj.name}{suffix}"How the Code Works
import bpy: Imports Blender's core Python module, allowing access to scene data.bpy.context.selected_objects: Returns a list of all objects currently highlighted/selected by the user.obj.name: Directly gets or sets the identifier string of the specific object in the scene database.