1
$\begingroup$

I have hundreds of objects within a collection (Blender 2.8) and would like to avoid manually renaming each object via the UI. I'm new to Blender and noticed there is scripting support. Could anyone help me produce a script to rename my objects?

For example, I would like to rename the objects in my "Water" collection. The current names do not follow a well defined pattern (even though the screenshot may make it look that way). When renaming is done, I do not care about retaining any semblance of the current name. My only requirement is adding a custom prefix. I'm envisioning the renaming to result in object names like: Water1, Water2, etc.

enter image description here

$\endgroup$
  • $\begingroup$ This might help blender.stackexchange.com/questions/71993/…. Also, googling 'Blender Bulk Rename' seems to give some good results. $\endgroup$ – AshKB Feb 20 '19 at 2:31
  • $\begingroup$ Yes, I read some of the related questions and answers, and although they do give hints to part of my question, the main missing aspect is how to target a specific collection in script. I cannot find a Blender 2.8 specific answer surrounding collections. $\endgroup$ – Scott Lin Feb 20 '19 at 5:53
  • $\begingroup$ If you can select the objects within the viewort, you can try this addon. Recently updated for 2.8x. $\endgroup$ – p2or Feb 20 '19 at 11:01
1
$\begingroup$

Iterate over collection objects.

This example is a reasonably simple introduction into scripting blender's python API.

import bpy

wcol = bpy.data.collections.get("Water")
if wcol:
    for i, o in enumerate(wcol.objects):
        o.name = "Water%d" % i

To ensure they keep their previous name order, and to have "Water1" first rather than "Water0"

import bpy

wcol = bpy.data.collections.get("Water")
if wcol:
    for i, o in enumerate(sorted(wcol.objects[:], key=lambda o: o.name)):
        o.name = "Water%d" % (i + 1) # to start from 1
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.