# Get a face selected pointing upwards

I am trying to create a script that selects a face that is pointing upwards from a edge selection. It does not matter if you have several edges or one selected i only need to get one face on top selected when the operation is done.

I am OK with an operator that can select the face after you invoke the operator.

• Cool, then we can clean up the rest of the comments : ) delete them they have been acknowledged :) – zeffii Dec 15 '15 at 20:28

To select the (0,0,1) pointing face(s) attached to the currently selected edge, you could use code like this.

(See TextEditor->Templates->Python->Simple BMesh from editmode)

This script expects to be in Edit Mode with 1 edge selected.

import bpy
import bmesh
import mathutils
from mathutils import Vector

EPSILON = 1.0e-5
up_vector = Vector((0,0,1))

obj = bpy.context.edit_object
me = obj.data
bm = bmesh.from_edit_mesh(me)

edge = [e for e in bm.edges if e.select][0]
if (f.normal-up_vector).length < EPSILON:
f.select = True

bmesh.update_edit_mesh(me, True)


For simplicity i've limited the selected edges to the first, by doing [0], but you might want to add warning messages as part of your script to warn the user (mostly you) that you have more than one edge selected..

or if you do want to handle multiple selected edges

edges = [e for e in bm.edges if e.select]
for edge in edges:

This won't take into account those edges that are hidden. their edge.hide attribute evaluates to True
• was about to add an answer based on blender.stackexchange.com/a/40264/15543 , would have been much the same... Another test could be up_vector.angle(f.normal) < radians(1) for all faces with normal within 1 degree of local z axis. Perhaps a flag to use global mode be useful too? – batFINGER Dec 15 '15 at 11:54