I want to delete all faces (of "Mesh") with a distance > 0.5 to the nearest point of an other object ("Sphere"). Unfortunately it deletes the whole object.
Thanks for helping!
import bpy
import bmesh
from math import sqrt
# Get the active mesh
obj_sphere = bpy.data.objects['Sphere']
obj = bpy.context.edit_object
me = obj.data
# Get a BMesh representation
bm = bmesh.from_edit_mesh(me)
for face in bm.faces:
# select face and Sphere
bpy.ops.mesh.select_all(action='TOGGLE')
face.select = True
obj_sphere.select = True
# get distance for selected objects
l = []
for item in bpy.context.selected_objects:
l.append(item.location)
distance = sqrt( (l[0][0] - l[1][0])**2 + (l[0][1] - l[1][1])**2 + (l[0][2] - l[1][2])**2)
# check distance > 0.5 and delete
if distance > 0.5:
bpy.ops.mesh.delete(type='FACE')
bmesh.update_edit_mesh(me, True)