Selecting the local left half
Which half? top, bottom, front, back, left or right... or other..
Here is a test script, run in edit mode, selects the local left half of edit object including those on centre plane.
A plane can be defined by a point in space plane_co
, and its normal plane_no
.
The mathutils.geometry.distance_point_to_plane(point, plane_co, plane_no)
returns how far a point is from a plane along its normal. Will be negative if on other side to which normal is facing.
The plane coordinate is the centre of the bounding box, the normal is one of the 3 axes made from a corner.
For this example the x axis of bounding box is chosen, to give left - right selection. Choose y for front-back, and z for top-bottom.
import bpy
import bmesh
from mathutils.geometry import distance_point_to_plane
from mathutils import Vector
context = bpy.context
def bbox(ob):
return (Vector(b) for b in ob.bound_box)
def bbox_center(ob):
return sum(bbox(ob), Vector()) / 8
def bbox_axes(ob):
bb = list(bbox(ob))
return tuple(bb[i] - bb[0] for i in (4, 3, 1))
ob = context.edit_object
o = bbox_center(ob)
x, y, z = bbox_axes(ob)
print(o, x, y, z)
# select left right
me = ob.data
bm = bmesh.from_edit_mesh(me)
for v in bm.verts:
v.select = distance_point_to_plane(v.co, o, x) >= 0
bmesh.update_edit_mesh(me)
Test run on Suze
(0, 0)
, the top RH corner(context.region.width, context.region.height)
$\endgroup$