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?