I wrote a script that can detect similar objects based on the selected objects but can't put them in a collection named after selected objects.
It's not working.
import bpy
selected_objects = bpy.context.selected_objects
for selected_object in selected_objects:
name = selected_object.name
collections = bpy.data.collections.new(name)
bpy.context.scene.collection.children.link(collections)
bpy.ops.object.select_pattern(pattern=f"*{name}*")
objs = bpy.context.selected_objects
coll = bpy.data.collections[name]
for obj in objs:
cols = obj.users_collection
coll.objects.link(obj)
for col in cols:
col.objects.unlink(obj)
I want from:
To: