hi
I am trying to find the closet face to another object with python script. I ran into one problems:
- the face was not selected.
here is my code:
import bpy
import subprocess
import mathutils
find closest face of ob1 to ob2
def closest_face(ob1,ob2):
d=9999999999999.9
f=0
for f1 in ob1.data.polygons:
p1=ob1.matrix_worldf1.center
for f2 in ob2.data.polygons:
p2=ob2.matrix_worldf2.center
p=p1-p2
if (p.xp.x+p.yp.y+p.zp.z) < d:
f=f1
d=(p.xp.x+p.yp.y+p.zp.z)
return f
def test():
ob1=bpy.data.objects[‘Torus’]
ob2=bpy.data.objects[‘Sphere’]
f=closest_face(ob1,ob2)
bpy.ops.object.mode_set(mode = ‘EDIT’)
bpy.context.tool_settings.mesh_select_mode = [False, False, True]
bpy.ops.mesh.select_all(action = ‘DESELECT’)
f.select=True
ob1.data.polygons.active=f.index
test()