I have a collection of over 2000 small meshes. I want to automatically have them joined in case meshes touch each other. So, after running python code, I want to end up with fewer meshes.
I tried the following script (chatGPT):
import bpy
# Get a list of all the meshes in the scene
meshes = bpy.data.meshes
# Loop through each mesh
for mesh in meshes:
# Create a list of all the other meshes that are touching this mesh
touching_meshes = []
for other_mesh in meshes:
if mesh != other_mesh:
for edge in mesh.edges:
if edge.vertices[0] in other_mesh.vertices or edge.vertices[1] in other_mesh.vertices:
touching_meshes.append(other_mesh)
break
# Join this mesh with all the other touching meshes
for other_mesh in touching_meshes:
bool_modifier = mesh.modifiers.new('bool', 'BOOLEAN')
bool_modifier.object = bpy.data.objects[str(other_mesh.name)]
bool_modifier.operation = 'UNION'
bpy.ops.object.modifier_apply(modifier=bool_modifier.name)
but I get this error :
Python: Traceback (most recent call last): File "C:\Users\bartdh\AppData\Local\Temp\7zOC3093EA1\TsD0209-2.blend\Text.001", line 14, in TypeError: bpy_prop_collection.contains: expected a string or a tuple of strings
Thank you for any help.