I'm converting voxel art to blender for animation and render. All the cubes import automatically named cube.001, cube.002, ect. I then parent all those cubes to an empty to animate their movement and name the empty what ever the object is. only problem is when I import new objects even from other blender scenes, the imported cubes rename themselves so that they aren't duplicating names, so cube.001 becomes cube.234 and so on. Problem is that my friend is talking about potentially building a video game with these assets so accidentally renaming objects like this could be problematic in the future. Is there a way to rename all the children objects so they have a prefix that matches the parent name? For example parent: "space-bug" would rename the cubes "space-bug-cube.001" and so on.
import bpy current_object = bpy.data.objects i = 0 for ob in bpy.context.scene.objects: # check if parent exist existing_parent = current_object[ob.name].parent if existing_parent: # check if it has been already renamed from parent if not current_object[ob.name].parent.name == current_object[ob.name].name.split('.'): # change the name of the object to the name of parent current_object[ob.name].name = existing_parent.name + '_' + str(i).zfill(2) print(ob.name, existing_parent.name) i += 1 else: print('nothing to do')
this script renames the objects in the scene according to their parent. if they share already the same name (meaning probably it has been already renamed) it does nothing. far from by polished though as for know it adds a numerical sequence to all the scene not per object.
Found a solution using an add-on that batch renames all selected objects when you hit ctrl+r.