11

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?

Animatoring
  • 1,430
  • 3
  • 26
  • 38

5 Answers5

14

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).

vklidu
  • 36,165
  • 1
  • 61
  • 135
JakeD
  • 8,467
  • 2
  • 30
  • 73
  • 2
    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 => https://blenderartists.org/t/2-80-cheat-sheet-for-updating-add-ons/1148974

    – Furkan Mustafa Sep 28 '19 at 06:58
  • Answer edited with Furkan's comment ... Thanks man :) BTW - How to number like 01, 001 style? – vklidu Jan 15 '22 at 10:04
  • @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? – JakeD Jan 18 '22 at 16:37
10

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

Mobin
  • 1,637
  • 7
  • 18
  • Yes, but there is not a way to add sequential numbering (if it is not hidden under "Regular Expression" :) – vklidu Jan 24 '21 at 21:12
  • CTRL+F2 does not work since 2.90 apparently – phil123 Jan 13 '22 at 11:01
  • @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. – Mobin Jan 14 '22 at 19:54
  • @vklidu updated – Mobin Jan 14 '22 at 19:59
  • 1
    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 https://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 – vklidu Jan 15 '22 at 09:47
6

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

Greg Zaal
  • 10,856
  • 3
  • 47
  • 86
0

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()

  • 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) – Martynas Žiemys Nov 29 '22 at 16:59
0
  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
YSLdev
  • 1