Home > database >  Is it possible to split the elements of a list?
Is it possible to split the elements of a list?

Time:10-05

>>> a = bpy.context.selected_objects
>>> a[:2]
[bpy.data.objects['Sphere.001'], bpy.data.objects['Sphere.010']]

>>> 

Two list results.

what i need is It is to move the number after Sphere to notepad. I do not know.

001 and 010

thank you.

CodePudding user response:

Is this what you want?

for a in bpy.context.selected_objects:
    print(a.name.split(".")[-1])

In Blender, you can just split the object's name on the '.' and take the last element in the resulting list. That should print out all those numbers that you want to copy.

CodePudding user response:

@Matti is probably giving you good information on Blender, and the loop will work, but the most direct route to the general case of getting a modified version of each item in a list is by using a list comprehension.

x = ["Sphere.001", "Sphere.010"]
print([y.split(".")[-1] for y in x])
  • Related