1
$\begingroup$

I have seen this : Selecting faces within a given radius

But it's a circle, I'd like to do the same but with a square

So is there a way to select a face from a coordinate point (x,y) and then apply the script to select a square respecting a length?

Basically to something like that:

scheme

I thank you in advance for your help, attention and time. I'm a begginner and I was thinking of KDTree but I don't quite understand the documentation... So if someone may help me I'll be grateful.

$\endgroup$
4
$\begingroup$

Square select.

Here is an edit to @zeffis answer

In edit mode, with face select mode, select a face and run script.

Change space = 'GLOBAL' to space = 'LOCAL' to select square using local coordinates of the mesh

size is the side length of the square

enter image description here
Test run in GLOBAL mode

enter image description here
Test run in LOCAL mode

import bpy
import bmesh
from mathutils import Matrix

space = 'GLOBAL' 
size = 2 # 2 x 2 square
d = size / 2

obj = bpy.context.edit_object
if space == 'GLOBAL':
    M = obj.matrix_world
elif space == 'LOCAL':
    M = Matrix.Identity(4)

me = obj.data

bm = bmesh.from_edit_mesh(me)
f = bm.faces.active
if f:
    o = M @ f.calc_center_median()

    for f in bm.faces:
        f.select = (all((abs(o.x - (M @ v.co).x) <= d) for v in f.verts) 
                and all((abs(o.y - (M @ v.co).y) <= d) for v in f.verts))


    bmesh.update_edit_mesh(me, True)

Note answer written for 2.8. To run in 2.7x replace all at symbols @ with asterisk *

Notes

could extend to "cube" select by adding the z coordinate to test.

Doesn't consider the alignment of the view, either uses global or local coordinates.

Could extend to have choice to extend selection or not.

$\endgroup$
  • $\begingroup$ Thank you it works very well! But as a complement, will there be a way to enter coordinates[x,y] (locally) and then automatically select the faces without having to be in edit mode? $\endgroup$ – xDlol May 28 at 15:51
  • $\begingroup$ Simply set o = Vector((x, y, 0)) however you want. Re object mode, look up bmesh docs, Create empty bmesh, bm = bmesh.new() load the mesh bm.from_mesh(me) write result to mesh bm.to_mesh(me) Select operations are usually done in edit mode. In object mode possibly better to return a list of faces, or face indices. $\endgroup$ – batFINGER May 28 at 15:58
0
$\begingroup$

Well, I don't know how to do this, or if it's possible, but I DO know that if you press "C" you'll enter circle select mode, scroll your mousewheel up or down to increase or decrease the size of the cursor. in this mode, left click is select and middle mouse button is deselect, to exit, just right click.

On the note of wacky methods of selection, if you select one face, find the end of the line and hold CTRL, doing this allows you to jump to the end of a line. for example, if you have a line of 8 faces, select the first one, then CTRL select the last one in the line and they'll all be selected.

you can lasso select with ctrl+left mouse button, but unless you're a sniper main in TF2, it won't work out well. (meaning if you're not too hot with your mouse, the selection will be squiggly.) I'm sorry I didn't answer your question with what you were looking for, but I hope I helped.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.