0
$\begingroup$

I have this very simple scene setup in Blender :

enter image description here

I want to duplicate the collection named 'Lights_1_50' along with its contents and I found that every object in Blender has a copy() method that can be used to duplicate the object. Blender collections also has that method and I tried to use it on the collection like so :

li= bpy.data.collections['Lights_1_50']
thingie= li.copy()

The code runs with no error but I don't see the new collection in the outliner which is weird because when I list all the collections in the console, I can see a collection named 'Lights_1_50.001' among the results :

enter image description here

and when I print thingie on the console, I have the collection as output. Also if I change the outliner type to Blender file, the collection is listed under Collections :

enter image description here

But I don't see it anywhere else, it's not visible in the viewport.

What more do I need to do to have that collection inside my scene? Is there any step I missed or maybe this is not the proper way to duplicate a collection?

Thank you for your time.

Edit :

I also figured out that my code did not duplicate the objects but just linked the originals inside the new collection which is not really what I want so maybe the copy() method is not what I'm looking for but I really have no idea of what else to try.

$\endgroup$
2

1 Answer 1

1
$\begingroup$

What was missing is that the collection needed to be appended to the scene.

The new collection was created but it didn't appear in the viewport and the outliner because it wasn't parented to anything so it was just present in the Blender file's data. It just needed this one line to be visible :

bpy.data.scenes['Scene'].collection.children.link(thingie)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .