Output list not same as reference

Hello,

I have a list ( I use as reference only), but when I try to recreate it the output is not the same.

This is the list I use as reference:
[bpy.data.objects['Cube'], bpy.data.objects['Light']]

Here is my attempt to recreate the same output:

new_list=[]
object_list=['Cube', 'Light']

prefix_ADD = "bpy.data.objects['"
suffix_ADD = "']"

for x in object_list:
    new_list.append(prefix_ADD + x + suffix_ADD)

The output I get is:
["bpy.data.objects['Cube']", "bpy.data.objects['Light']"]

Is there a way to get the same output than the reference list?

Juan.

This appears to be a list that is populated with a pair of Blender objects. The bit that is shown is just a name for the object.

What are you trying to do with them? Do you want to make additional blender objects based on them? Are you trying to create new blender objects from scratch?

Assuming bpy.data.objects is defined elsewhere in the script:

new_list = [bpy.data.objects[i] for i in ["Cube", "Light"]]

If bpy.data.objects for some reason cannot be defined here, you can instead eval the list you currently have in a scope where bpy.data.objects is defined:

new_list = ["bpy.data.objects['Cube']", "bpy.data.objects['Light']"]
actual_list = [eval(i) for i in new_list]

actual_list is now [bpy.data.objects['Cube'], bpy.data.objects['Light']].

1 Like

I would like to have my own list of objects and manipulate the data of them by avoiding having to perform a object selection.

I know that there is a cube in the blender object data, so adding the objects that exists in the data already to my own list would allow me to move them around.

Hope it makes sense.

That’s great, now is up and running, thank you.