Deleting islands (lose parts) of mesh with Python My Goal is it to remove Islands from an 3D scanned object (3D printer purpose) with python. I was thinking something like:


Getting all vertices
Iterate through all vertices


Save linked vertices and number of linked vertices
Remove all already scanned vertices from iteration
Compare with old maxLinked, if lower delete vertices   





If someone could point me to a solution it would be great.
Use the Separate into Loose Parts Operator.

Possibly the quickest and simplest way to do this is to run the bpy.ops.mesh.separate(type='LOOSE') operator to split the single mesh into loose parts.  Then remove all but the object with the most vertices.

import bpy

context = bpy.context
# edit mode
bpy.ops.object.mode_set(mode='EDIT')
# split into loose parts
bpy.ops.mesh.separate(type='LOOSE')
# object mode
bpy.ops.object.mode_set(mode='OBJECT')

parts = context.selected_objects
# sort by number of verts (last has most)
parts.sort(key=lambda o: len(o.data.vertices))
# print
for part in parts:
    print(part.name, len(part.data.vertices))
# pop off the last
parts.pop()
# remove the rest
for o in parts:
    bpy.data.objects.remove(o)


There are a number of methods for doing this without the operator in answers to  How to find the number of loose parts with Python? including my answer which returns a list of verts for each island in selection which would be ideal for making an interactive tool to do this per selection, to clean "splatter-cake" verts.