I have a list of names for 50 objects. How can I apply those names from the list to my 50 objects at once?
All my object names are numbered from 1 to 50, so my list is like this:
1: blue small car
2: red small car
3: green small car
etc…
So I just need to replace the names with the numbers from 1-50.
Is it possible to do it with a script?
Something like this?
Before
After
Code Snippet
import bpy
OBJ_NAMES = ["Red", "Green", "Blue"]
for i in range(0,3):
for o in bpy.data.objects:
if o.name == str(i):
o.name = OBJ_NAMES[i]
break
2 Likes
Thank you. yes but with 50 objects and different names, can i just past my list there and change the numbers?
Yes, of course. Just change the “3” to “50” and replace the OBJ_NAMES list with your own list and everything should work fine.
I’ll expand on @RPaladin’s answer. Another possibility, IF all your objects names map 1-1 to the indices of your names list. Otherwise it will throw an error.
We make a copy of bpy.data.objects
otherwise we modify the container as we iterate over it which is prone to error.
import bpy
OBJ_NAMES = ["Red", "Green", "Blue"]
for obj in bpy.data.objects[:]:
obj.name = OBJ_NAMES[int(obj.name)]
1 Like