1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| import bpy from collections import defaultdict
size_to_objects = defaultdict(list)
for obj in bpy.context.scene.objects: if obj.type == 'MESH': bpy.context.view_layer.objects.active = obj bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) volume = obj.dimensions.x * obj.dimensions.y * obj.dimensions.z size_to_objects[volume].append(obj)
for size, objs in size_to_objects.items(): collection_name = f"Size_{size:.2f}" new_collection = bpy.data.collections.new(name=collection_name) bpy.context.scene.collection.children.link(new_collection) for obj in objs: for col in obj.users_collection: col.objects.unlink(obj) new_collection.objects.link(obj)
print("分组完成!")
|