Software:
Blender 2.8 | Python 3.7
Some useful short Python snippets for batch re-naming objects in Blender:
- Remove last 4 characters from selected object names:
import bpy objects = bpy.context.selected_objects for o in objects: o.name = o.name[:-4]
- Rename all selected objects to a set base name followed by a 3 digit numeric suffix:
import bpy objects = bpy.context.selected_objects for (i,o) in enumerate(objects): o.name = "some_base_name_{:03d}".format(i)
- Prefix all selected objects name with their Blender data type like renaming “SomeModel” to “MESH_SomeModel” or for example:
import bpy objects = bpy.context.selected_objects for (i,o) in enumerate(objects): o.name = "{}_{}".format(o.type,o.name)
* note that when copying and pasting a script from this example, the indentation may not be pasted correctly.
Note:
Blender 2.8 has a robust batch renaming utility that is invoked by pressing Ctrl + F2 so we don’t have to write scripts to do batch renaming of objects:
One thought on “Python for Blender – Batch renaming objects”