Slection vertices choosing coordinate and value by the user

Hi everyone, i’d like to know how to select vertices from one/several mesh/es by user’s value, from keyboard, from va, from drivers, from…i don’t know.
The question born to me when i have a city mesh and I would like to select all third floors of all the buildings in a neighborhood. I like to select vertices (or edges, or faces) giving user’s value of the coordinate (X, or both, or all) and a value. Thankl you

should show some pics to better explain what you mean

also are all the 3 floors at same level Z for instance ?
or variable terrain height

is this with old API or new Bmesh API ?

might be possible with

happy bl

I have my city mesh…and i want to select…all vwertices with axis x = 523.

what kind of mesh data is it using nly tri’s and quads or Bmesh with ngon?

it is easy to go through all verts and find a Z value

happy bl

try something like this

import bpy , bmesh
z1 = 0.38
zprec =0.05      #  5 %
Zmax = z1+zprec *z1
Zmin = z1-zprec *z1
vnz = 0

print ()
print (" NEw Verts list  &&&&&&&&&&&&&&&&&&&&&&&&&&")
print ()


bpy.ops.object.select_pattern(extend=False, pattern="Sphere", case_sensitive=False)
ob = bpy.context.active_object
print ('selected ob =',len(bpy.context.selected_objects))

for ob in bpy.context.selected_objects:
 print ('select ob =',ob)
#for ob in C.selected_objects:

#ob = bpy.context.active_object

vnz = 0

print ('ob name =',
if ob.type == 'MESH':
# = ob     #set active object
 print ('ob name =',
 for vert in
#  print ('Vco Z =',[2] )
  if[2] <=Zmax and[2]>=Zmin:
   print ('Z[2]=',[2], ' Zmax  =',Zmax, 'Zmin  =' , Zmin)
   vnz+=1 = True     #ensure Z vertices are selected
  else: = False

print ()
print ('Verts at Z =' ,z1 ,' + / - ',zprec*100,' %   =', vnz  )
print ()

print ()
print (" end2   Verts list  &&&&&&&&&&&&&&&&&&&&&&&&&&")
print ()


happy bl

thank you. i`ll try.

i have changed in the code Sphere by Cube.
I subdivided the Cube into 8x8. I changed 5 lines of the script code:

z1 = 0.2
zprec =0.05 # 5 %
Zmax = z1+zprec *z2
Zmin = z1-zprec *z2

I discovered that every 4 step of z2 value, the selection growed one row each time until z2= 28 maximum value.
When i subdivided the Cube into 64x64 (next subdivision from 8x8),the selection growed four row each time until z2= 28 also maximum value.
I don’t know but i think there is something good in it. Thank you.

just did a proof test on a sphere

but could be change for active selected object too

happy bl