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?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
Object.users_collection property returns a tuple containing all linked collections:
>>> obj = bpy.context.object >>> obj.users_collection (bpy.data.collections['Collection'],)
Select this object by name and it should take you to the right collection. Selection by name is described in this section.