2
$\begingroup$

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

enter image description here

If someone could point me to a solution it would be great.

$\endgroup$
2
$\begingroup$

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.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.