Skip to main content
4 of 5
Code cleanup
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

Came up with similar to @TLousky, test code below only selects faces without the range value.

To use closest point on mesh you need to put the reference point into the calling object's object space, if not you will get undesired results when away from the origin.

Also note: use vectors to calculate distance.

import bpy
import bmesh

L = 0.5 # distance limit
sphere = bpy.data.objects.get("Sphere")
mesh_obj = bpy.context.edit_object
me = mesh_obj.data
smwi = sphere.matrix_world.inverted()

bm = bmesh.from_edit_mesh(me)

for face in bm.faces:
    v1 = mesh_obj.matrix_world * face.calc_center_median() # global face median
    localPos = smwi * v1  # face cent in sphere local space
    
    (loc, norm, face_index) = sphere.closest_point_on_mesh(localPos)
    
    v2 = sphere.matrix_world * loc
    face.select = ((v2 - v1).length > L)

test result

enter image description here

To make it more accurate consider using the normal returned to determine which point of a face to use. If the angle between the face normal and the normal to the closest point is ~ 90 use the closest edge, ~ 180 degrees it's on the inside.

batFINGER
  • 85.2k
  • 10
  • 114
  • 244