I'm trying to do something similar as in this post, but instead of all dimensions from each object I want to know to which collection they belong.
The part of the code I changed was:
selection = bpy.context.selected_objects
iterate through the selected objects
for sel in selection:
# get collection to which the object belongs
col = bpy.context.collection
# write the selected object's name and dimensions to a string
result += "%s, %s" % (sel.name, col.name)
However, this seems to loop over the collections that are inside of the selected objects instead of the other way around. How do I change my code to see the collection the objects belongs to?


context.collectionis the active one). How to get the collection of the object: https://blender.stackexchange.com/a/134789/31447 – brockmann Jul 23 '21 at 15:32