Selection of points with x-coordinate maximum

For a personal project, I need for example on a cube that would have made ​​a rotation along z angle of PI / 4 to write a python program that will permit to select the points that have the maximum x coordinate, i mean that for example if you made ​​a list of all the x-coordinate of the vertices constituting the cube, and well most of this list will be the x-coordinate of the point I wish to select. Here is the code I use on a cube:

def sectionner1():
tx = []
truc = bpy.context.scene.objects.active
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action = ‘DESELECT’)
bm = bmesh.from_edit_mesh(truc.data)
for vert in bm.verts:
tx.append(vert.co[0])
print("+++",maximum(tx))
for vertices in bm.verts:
tx.append(vert.co[0])
if vertices.co[0] == maximum(tx):
vertices.select = True
print(vertices.co)
bpy.ops.mesh.select_all(action =‘INVERT’)
bpy.ops.mesh.delete(type=‘VERT’)
bpy.ops.object.editmode_toggle()

It selects me the good part when I’m not turning my cube, but once I made ​​a rotation, and although it does not give the correct result anymore … If someone has a solution!

You need to transform the vertex coordinate from object space to world space, e.g.:

obj.matrix_world * vert.co.to_4d()

Test on the resulting Vector and it should work.

yeah, but it shouldn’t be necessary to turn the coordinate into 4d for that

True, I just copied and pasted from a personal project.