5
$\begingroup$

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.

enter image description here

$\endgroup$
1
  • $\begingroup$ Cool, then we can clean up the rest of the comments : ) delete them they have been acknowledged :) $\endgroup$
    – zeffii
    Commented Dec 15, 2015 at 20:28

1 Answer 1

5
$\begingroup$

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]
linked_faces = edge.link_faces
if linked_faces:
    for f in linked_faces:
        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:
    linked_faces = edge.link_faces
    if linked_faces:
        for f in linked_faces:
            if (f.normal-up_vector).length < EPSILON:
                f.select = True

This won't take into account those edges that are hidden. their edge.hide attribute evaluates to True

$\endgroup$
2
  • $\begingroup$ 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? $\endgroup$
    – batFINGER
    Commented Dec 15, 2015 at 11:54
  • $\begingroup$ If you now use this code, then use the select planar command, and then select outer boundary in a row you get like a loopcut that works on all shapes! Thanks for the help! $\endgroup$ Commented Dec 15, 2015 at 14:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .