I'm trying to select the top and bottom face of meshes and delete them.
So far, the code I have just deletes to first face but not the second. It would probably be more efficient to select both top and bottom together and delete them in one go rather than one, then the other, but I'll be happy with whatever just works. Any help anyone can offer would be most appreciated. Thanks
import bpy
from mathutils import Vector
def NormalInDirection( normal, direction, limit = 0.5 ):
return direction.dot( normal ) > limit
def GoingUp( normal, limit = 0.5):
return NormalInDirection( normal, Vector( (0, 0, 1 ) ), limit )
def GoingDown( normal, limit = 0.5):
return NormalInDirection( normal, Vector( (0, 0, -1 ) ), limit )
def GoingSide( normal, limit = 0.5):
return GoingUp( normal, limit ) == False and GoingDown( normal, limit ) == False
obj = bpy.context.object
#bpy.ops.object.editmode_toggle()
prevMode = obj.mode
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
#Selects faces going up
for face in obj.data.polygons:
face.select = GoingUp( face.normal )
bpy.ops.object.mode_set(mode=prevMode, toggle=False)
bpy.ops.mesh.delete(type='FACE')
#Selects faces going down
for face in obj.data.polygons:
face.select = GoingDown( face.normal )
bpy.ops.object.mode_set(mode=prevMode, toggle=False)
bpy.ops.mesh.delete(type='FACE')