 # Splitting planes with BMesh

Hi all,

Fist post here and not at all a python guy but I have managed to get my stuff going which is exciting. I was wondering if the internet in its wisdom knew about a way of splitting planes using Bmesh.

I would like to specify a point say (0,0,0) and test if that point is within a face somewhere in the space. I am using (bmesh.geometry.intersect_face_point) which works. Once I have identified that the point projection is in that face, I want to split that face in a specific direction say, along the x-axis or parallel to it.

Ultimately if I do this for a full mesh I can knife cut it along a specific axis on a certain point. I am struggling to get a split function going (mesh.ops.split) and would like to avoid creating vertices in each individual face I find to then create edges to then delete those faces and recreate them with the included edges, it just seems like a slow process for thousands of faces. I am going for efficiency here if possible. Code below and trying to make it work with a 2x2 plane in the X-Y planes centered on (0,0,0). Commented stuff is what I have been trying.

``````import bpy
import bmesh
from mathutils import (
Vector,
Matrix,
)
import math
"""
bpy.ops.mesh.primitive_plane_add(size=0.25, enter_editmode=False, align='WORLD', location=(0, 0, 0), rotation=(0, 1.5708, 0), scale=(1, 1, 1))
bpy.ops.mesh.primitive_plane_add(size=0.25, enter_editmode=False, align='WORLD', location=(0, 0, 0), rotation=(0, 0, 0), scale=(1, 1, 1))

me = bpy.context.object.data

me1=bpy.data.objects["Plane"].data
me2=bpy.data.objects["Plane.001"].data
bm = bmesh.new()   # create an empty BMesh
bm.from_mesh(me1)
bm.from_mesh(me2)

bm.to_mesh(me)
bm.free()
#"""

highest_point=[0,0,0,0,0]
i=0

me=bpy.data.objects["Plane"].data

bm = bmesh.new()
bm.from_mesh(me)

"""
bmesh.ops.duplicate(bm,
geom = bm.faces)

bmesh.ops.rotate(
bm,
verts = bm.verts[0:4],
cent = (0,0,0),
"""

bm.faces.ensure_lookup_table()
bm.verts.ensure_lookup_table()

# Checks if the projection of the point is on the plane
point_to_check = [0.5,0.5,0]
if bmesh.geometry.intersect_face_point(bm.faces,point_to_check): # for a 2m plane in the XY planes, any Z values will contain the point as long as X or Y is <1 (also <0.999999)
print ("The point is in the face")
for v in bm.faces.verts: # all the points in that face
highest_point[i]=v.co.z
i += 1
print (v.co) # Prints the number of vertices that makes up that face
i=0

#pt1 = bm.verts.new([0,0.5,0])
#pt2 = bm.verts.new([0,1,0])
#bm.verts.ensure_lookup_table()

#bmesh.ops.connect_verts(bm,
#    verts = (pt1,pt2),
#    check_degenerate = 1)

#bm.verts.remove(pt1)
#bm.verts.remove(pt2)

bm.verts.ensure_lookup_table()
#bmesh.utils.face_split(bm.faces,bm.verts,bm.verts)

print("The hight point in the face is", max(highest_point))
print("The hight point in the face is", min(highest_point))
else:
print ("The point is NOT in the face")

bm.to_mesh(me)  # Writes the bmesh back into the mesh

bm.free() #Frees the mesh
``````

Thanks for the help!