6
$\begingroup$

How to select all the edges through the YZ plane with a python script ?

enter image description here


update

I know this script which do it for faces but I don't know the equivalent for edges :

import bpy, bmesh

me = bpy.context.object.data

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

for face in bm.faces:

    center = face.calc_center_median()

    if center.x == 0:

        face.select_set(True)

bm.to_mesh(me)
bm.free()
$\endgroup$
4
  • 2
    $\begingroup$ Not sure why the question got a downvote, but I suspect because it is more like a request for script without any signs of an attempt by you to research how such a script might be put together. $\endgroup$ Commented Mar 26, 2015 at 9:47
  • 2
    $\begingroup$ how would you decide the x component of the plane? Remember scripts don't have eyes, like ours that let us immediately say ' oh of course, that vertex and edge lies on the plane '. Would your script need to find this plane autonomously or would you be giving it a helping hand by providing a pre-selection first $\endgroup$ Commented Mar 26, 2015 at 10:24
  • $\begingroup$ the x component of the plan is zero, it's at the origin. $\endgroup$ Commented Mar 26, 2015 at 10:36
  • $\begingroup$ just select the verts instead and automatically the edges are selected $\endgroup$ Commented Mar 26, 2015 at 10:53

1 Answer 1

8
$\begingroup$

Armed with the extra information consider:

import bpy, bmesh

me = bpy.context.object.data

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

EPSILON = 1.0e-5

for vert in bm.verts:
    if -EPSILON <= vert.co.x <= EPSILON:
        vert.select = True

bm.to_mesh(me)
bm.free()

Some clarification perhaps:

EPSILON represents a value that is close to 0. If you've ever inspected coordinates closely in Blender you will find a cut off point maybe at around 6 or 7 digits after the decimal where you start to encounter artefacts in the representation of that float. Because 0 and 0.0000012312423 are not the same number you can't simply do a check for equality with 0, instead you might check is the x component within EPSILON tolerance.

Here I make the significant digit 5 places after the decimal point, from practical experience i've found this to be sufficient.

>>> 1.0e-5 == 0.00001
True

The above will select just the vertices, from that point selecting the edges shouldn't be too difficult. Here's a quick implementation

import bpy, bmesh

me = bpy.context.object.data

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

EPSILON = 1.0e-5
for vert in bm.verts:
    if -EPSILON <= vert.co.x <= EPSILON:
        vert.select = True

for edge in bm.edges:
    if edge.verts[0].select and edge.verts[1].select:
        edge.select = True

bm.to_mesh(me)
bm.free()

enter image description here

$\endgroup$
5
  • 1
    $\begingroup$ As always - very nice zeffi :) $\endgroup$ Commented Mar 26, 2015 at 11:32
  • $\begingroup$ @poor thanks! I always answer these questions with at least a working solution, in the hope that someone who knows more will get agitated and offer an alternative. The more answers the merrier. $\endgroup$ Commented Mar 26, 2015 at 11:47
  • $\begingroup$ I've only thought about if there is a build-in epsilon value, remembered vaguely there was one in c++, but can't find it at the moment. $\endgroup$ Commented Mar 26, 2015 at 11:58
  • $\begingroup$ How come import bmesh as bm bm.edges will output bmesh has no attribute edges $\endgroup$ Commented Dec 11, 2020 at 18:33
  • $\begingroup$ @JuneWang because if you import bmesh as bm , then bm is just an alias for the bmesh module, and you are doing something like bm = bm.new()? look at the examples at docs.blender.org/api/blender2.8/… $\endgroup$ Commented Dec 12, 2020 at 12:05

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.