I’m new to coding and am trying to put together a script which cuts selected faces by a plane, and removes geometry that is “lower” than that plane (from the selected faces).
So far I have a script that will bisect the selected faces by the active face. What I want to do is remove or “clip off” the geometry below the bisect line (using the active face’s opposite normal direction).
I’ve been up all night look for ways to do this and trying a lot of things, to no avail.:no: I’m not experienced enough in coding to select by direction. I could very much use some assistance!
this is my code so far:
import bpy, bmesh
#Get the active mesh
obj = bpy.context.edit_object
me = obj.data
#Get a BMesh representation
bm = bmesh.from_edit_mesh(me)
#Get selected geometry:
edges = [e for e in bm.edges if e.select]
faces = [f for f in bm.faces if f.select]
geom = []
geom.extend(edges)
geom.extend(faces)
selected_faces = [f for f in bm.faces if f.select]
#Get active face as the cutter:
active_face = bm.faces.active
active_normal = active_face.normal
active_location = active_face.calc_center_median()
#I can’t figure out this part
for f in selected_faces:
face_location = f.calc_center_median()
if face_location < active_location:
f.select = True
else:
f.select = False
geom_faces = [f for f in result['geom'] if isinstance(f, bmesh.types.BMFace)]
bm.select_mode = {'FACE'}
for f in bm.faces:
if not f in geom_faces:
f.select = False
continue
v = f.calc_center_median() - active_location
if v.dot(active_normal) < 0:
f.select = True
else:
f.select = False
I have made the following code and it seems to work fine.
geom_faces = [f for f in result['geom'] if isinstance(f, bmesh.types.BMFace)]
bm.select_mode = {'FACE'}
for f in bm.faces:
if not f in geom_faces:
f.select = False
continue
v = f.calc_center_median() - active_location
if v.dot(active_normal) < 0:
f.select = True
else:
f.select = False
bm.select_flush_mode()
bmesh.update_edit_mesh(me)
I have made the following code and it seems to work fine.
geom_faces = [f for f in result[‘geom’] if isinstance(f, bmesh.types.BMFace)]
bm.select_mode = {‘FACE’}
for f in bm.faces:
if not f in geom_faces:
f.select = False
continue
v = f.calc_center_median() - active_location
if v.dot(active_normal) < 0:
f.select = True
else:
f.select = False
bm.select_flush_mode()
bmesh.update_edit_mesh(me)