Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get list of selected objects as string Blender python

I'm facing a rather easy to solve problem but I just don't know how to do it. I want blender to list all the objects selected as a string. Eg. if I run :

selection_names = bpy.context.selected_objects
print (selection_names)

it gives me this line:

[bpy.data.objects['Cube.003'], bpy.data.objects['Cube.002'], bpy.data.objects['Cube.001'], bpy.data.objects['Cube']]

But what I want is for selection_names is to print out as:

['Cube.001','Cube.002','Cube.003','Cube']
like image 956
Raspberry Avatar asked Dec 03 '14 07:12

Raspberry


1 Answers

The fastest way to solve this is through list comprehension :

selection_names = [obj.name for obj in bpy.context.selected_objects]

which is the exact equivalent of:

selection_names = []
for obj in bpy.context.selected_objects:
    selection_names.append(obj.name)
like image 175
Pullup Avatar answered Oct 15 '22 07:10

Pullup