2
$\begingroup$

I can access objects belonging to a collection like so:

objects_in_collection = bpy.data.collections["My_Collection"].objects

How can I access the collection a specific object belongs to?

$\endgroup$
4
$\begingroup$

Object.users_collection property returns a tuple containing all linked collections:

>>> obj = bpy.context.object
>>> obj.users_collection
(bpy.data.collections['Collection'],)
| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Many thanks! I also needed to get the name of the collection and was able to do so like this: ob.users_collection[0].name $\endgroup$ – coCoKNIght Mar 21 '19 at 14:59
  • $\begingroup$ @brockmann :: Is the result always by order? e.g. [0] = direct parent? The official document in your link lacks detail. $\endgroup$ – cppBeginner Jul 18 at 4:10
  • 1
    $\begingroup$ Not sure, just test it. If not the case, you can sort it: blender.stackexchange.com/questions/146685/… @cppBeginner $\endgroup$ – brockmann Jul 18 at 18:16
-1
$\begingroup$

Select this object by name and it should take you to the right collection. Selection by name is described in this section.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.