11
$\begingroup$

Is there a way to batch rename objects in a sequence similar to: object1, object2, object3...? Where 'object' would be any custom name?

I found the batch rename datablocks script and it was really helpful for renaming a group of objects but gives a sequence like: object.001, object.002, object.003

Is there any way to use this script to give the first kind of sequence?

$\endgroup$
2
  • 3
    $\begingroup$ Does this help? $\endgroup$
    – p2or
    Commented Jan 22, 2017 at 20:14
  • 1
    $\begingroup$ Thanks poor! Looks like either that or the script below works well. Your link gives the option of connecting it with a hotkey which can be really nice too. $\endgroup$ Commented Jan 23, 2017 at 0:12

5 Answers 5

14
$\begingroup$

Blender 2.79

import bpy

for i, obj in enumerate(bpy.context.selected_objects, 1):
    bpy.context.scene.objects.active = obj
    obj.name = "object" + str(i)

Blender 2.8+

import bpy

for i, obj in enumerate(bpy.context.selected_objects, 1):
    bpy.context.view_layer.objects.active = obj
    obj.name = "object" + str(i)

Just replace "object" with "your name" and run this in the text editor (make sure you have all objects selected that you want renamed).

$\endgroup$
3
  • 2
    $\begingroup$ This didn't work for me when using Blender 2.8. changing line 4 to bpy.context.view_layer.objects.active = obj helped. update cheatsheet here => blenderartists.org/t/2-80-cheat-sheet-for-updating-add-ons/… $\endgroup$ Commented Sep 28, 2019 at 6:58
  • $\begingroup$ Answer edited with Furkan's comment ... Thanks man :) BTW - How to number like 01, 001 style? $\endgroup$
    – vklidu
    Commented Jan 15, 2022 at 10:04
  • $\begingroup$ @vklidu What do you mean? You want to add leading zeroes all the time or you want to add a zero to each subsequent object in a sequence? $\endgroup$
    – JakeD
    Commented Jan 18, 2022 at 16:37
11
$\begingroup$

Blender users can now do batch rename with (Menu: Edit ‣ Batch Rename and Hotkey: Ctrl+F2) without any add-ons. (blender +2.80)

enter image description here

An example: enter image description here

Read this blender manual section for more info: https://docs.blender.org/manual/en/dev/files/blend/rename.html#batch-rename

$\endgroup$
5
  • $\begingroup$ Yes, but there is not a way to add sequential numbering (if it is not hidden under "Regular Expression" :) $\endgroup$
    – vklidu
    Commented Jan 24, 2021 at 21:12
  • $\begingroup$ CTRL+F2 does not work since 2.90 apparently $\endgroup$
    – phil123
    Commented Jan 13, 2022 at 11:01
  • $\begingroup$ @phil123 it did and it does for me. even on v3.0. I will add a screenshot just in case so anyone could find the short key if it does not work for them. $\endgroup$
    – Mobin
    Commented Jan 14, 2022 at 19:54
  • $\begingroup$ @vklidu updated $\endgroup$
    – Mobin
    Commented Jan 14, 2022 at 19:59
  • 1
    $\begingroup$ Nice trick :) so ... You have to do it in two steps. First to rename all objects with number ".001" included (this pushs blender's native numbering to renumber other objects sequently). Secondly use Find/Replace beginning and keep only number imgur.com/E9MUTNU (alternatively add suffix). Could you extend your edit, because OP was asking how to start name with sequential numbering ... especially point the trick here. Thank you $\endgroup$
    – vklidu
    Commented Jan 15, 2022 at 9:47
6
$\begingroup$

I'm sure there are dozens of add-ons floating around that do this since they are quite easy to code and thus a good way to learn python, but here's mine:

https://github.com/gregzaal/batch-renamer

batch renamer screenshot

$\endgroup$
0
$\begingroup$

blender 2.79 addon bulk rename example

import bpy
from bpy.props import *

import numpy as np

bl_info = {
    "name": "renameBulk",
    "author": "luis alberto rodriguez montilla",
    "version": (0),
    "blender": (2, 72, 2),
    "location": "VIEW_3D > TOOLS > Tools",
    "warning": "first select the objects",
    "description": "bulk rename",
    "wiki_url": ""
                "",
    "category": "Mesh",
}

def initSceneProperties():
    #para crear un string
    bpy.types.Scene.brStr = StringProperty(
        name = "new name")
    return
#blender tiene dos principales funciones, panel que dibuja
#y operador que ejecuta; puede haber mas de un operador
class BulkRenameUIPanel(bpy.types.Panel):
    bl_label = "change Names"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category = "Tools"
    

    def draw(self, context):
        
        layout = self.layout
        scn = context.scene
        layout.prop(scn, "brStr")
        #operator de be estar todo en minusculas y llevar un punto
        layout.operator("bulk.rename_all_objects")



class defStrBulkRename(bpy.types.Operator):

    def defineVar_(self, context):

        scn = context.scene
        brStr = scn["brStr"]
        return brStr
#los nombres de funciones deberan ser diferentes de otros noambres en addons
#de lo contrario sobreescribira los valores de las funciones anteriores
class OBJECT_OT_bukRename(bpy.types.Operator):
    bl_idname = "bulk.rename_all_objects"
    bl_label = "change bulk name"
    def execute(self, context):
        for i, obj in enumerate(bpy.context.selected_objects, 1):
            bpy.context.scene.objects.active = obj
            #aquie el (self,context) es necesario para valores entre clases
            obj.name = defStrBulkRename.defineVar_(self,context)+ str(i)
    
        return{'FINISHED'}
#dejar por defecto este tipo de registro, es funcional y funciona siempre
#que no se nesecite mas datos; si no se registra no aparecera nada

def register():
    bpy.utils.register_module(__name__)#register others class
    initSceneProperties()


def unregister():
    bpy.utils.unregister_module(__name__)#unregister others class

if __name__ == "__main__":
    register()
$\endgroup$
1
  • $\begingroup$ So much code, when only one line is needed: for i,o in enumerate(bpy.context.selected_objects): o.name = "Object" + str(i).zfill(3) $\endgroup$ Commented Nov 29, 2022 at 16:59
0
$\begingroup$
  1. Use batch rename's Set Name to ensure the naming and default numbering is correct
  2. Use batch rename's Strip Characters to remove punctuations
  3. Use batch rename's Find/Replace to remove 00s
$\endgroup$

You must log in to answer this question.

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