0
$\begingroup$

I am trying to build a collection hierarchy in bpy - to mirror a product's hierarchical bill of materials.

With a mesh I can do this:

obj.users_collection

to find out what collections object obj is part of.

How do I do that with a collection? if I do

coll.users_collection

I get an error:

'Collection' object has no attribute 'users_collection'

and

coll.users_dupli_group

(which was my best guess) returns an empty list, and not at least the root collection as I expected: a behavior that is different from plain Objects.

So what should I use instead?

For context - I am trying to do the following:

  • create a new collection "A"
  • add an existing collection "B" to the new collection "A"
  • if the existing collection was in some other collection (including the top one), unlink it so "B" is in one collection only - that is, in "A"

This last step fail - as I can't seem tell what collections a collection is in.

$\endgroup$
2
  • $\begingroup$ @brockmann - yeah, it looks like it could work, I'm going to test that out later. So do I get it right that you can get the parent of an Object (with users_collection), but not of a Collection? $\endgroup$
    – simone
    Aug 9 '21 at 16:24
  • $\begingroup$ As I wrote: "As long as there is no parent property..." $\endgroup$
    – brockmann
    Aug 9 '21 at 16:28

Browse other questions tagged or ask your own question.