Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/PERPdemo.py
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/11173403 to your computer and use it in GitHub Desktop.
Save zeffii/11173403 to your computer and use it in GitHub Desktop.
import bpy
import bmesh
import mathutils
import math
from mathutils import Vector
obj = bpy.context.object
me = obj.data
bm = bmesh.from_edit_mesh(me)
verts = [v for v in bm.verts if (v.select and not v.hide)]
#if not len(verts) == 2:
# msg = "select two vertices"
# self.report({"WARNING"}, msg)
# return
v1, v2 = [v.co for v in verts]
print('vectors found:\n', v1, '\n', v2)
mid_vec = v1.lerp(v2, 0.5)
plane_no = v2-mid_vec
plane_co = mid_vec
dist = 0.0001
# hidden geometry will not be affected.
visible_geom = [g for g in bm.faces[:]+bm.verts[:]+bm.edges[:] if not g.hide]
bmesh.ops.bisect_plane(
bm,
geom=visible_geom,
dist=dist,
plane_co=plane_co, plane_no=plane_no,
use_snap_center=False,
clear_outer=False,
clear_inner=False)
bmesh.update_edit_mesh(me, True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment