# How to select particular edges with a python script?

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

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()

• 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. – zeffii Mar 26 '15 at 9:47
• 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 – zeffii Mar 26 '15 at 10:24
• the x component of the plan is zero, it's at the origin. – reflyon Mar 26 '15 at 10:36
• just select the verts instead and automatically the edges are selected – Chebhou Mar 26 '15 at 10:53

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()


• As always - very nice zeffi :) – p2or Mar 26 '15 at 11:32
• @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. – zeffii Mar 26 '15 at 11:47
• 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. – p2or Mar 26 '15 at 11:58