As the title says, I am using bmesh.verts to load in all the vertices of a mesh to then check if their coordinates are within a certain box, and if they are select them. The problem is that the function seemingly doesn't load in all of the vertices of the mesh, but only roughly a couple tens of thousands when I have over a million vertices in the mesh. I figured this out by counting the amount of vertices where loaded in by the function at hand.

Is this a problem that can be solved somehow? Is this dependent on the amount of RAM used or some other memory related issue?

Important notice: This works perfectly fine if you copy and paste each command into the python console, but does not work when the script is run by itself.

This is the syntax:

def SelectVerticesInBound(object, vector1, vector2):
# get the mesh data from the object reference
mesh = object.data
# get the bmesh data
if mesh.is_editmode:
bm = bmesh.from_edit_mesh(mesh)
else:
bm = bmesh.new()
bm.from_mesh(mesh)
print(len(bm.verts))
# cycle through all vertices
for vert in bm.verts:
# check if the vertice is in the bounding vectors
# if yes, select it
# if no, deselect it
if(IsInBoundingVectors(vert.co, vector1, vector2)):
vert.select = True
else:
vert.select = False
# update bmesh to mesh
if bm.is_wrapped:
bmesh.update_edit_mesh(mesh, False, False)
else:
bm.to_mesh(mesh)
mesh.update()
# trigger viewport update
bpy.context.scene.objects.active = bpy.context.scene.objects.active
# checks if a supplied coordinate is in the bounding box created by vector1 and vector2 and relies on vector1 being the "smaller" vector of the two
def IsInBoundingVectors(vector_check, vector1, vector2):
for i in range(0, 3):
if (vector_check[i] <= vector1[i] or vector_check[i] >= vector2[i]):
return False
return True

• Is that a million verts without modifers? Could be an issue with edit mode. In UI if you edit one object and change active object to another via code in console it doesn't work as expected. Prob needs an edit mode toggle operator (yuck) Not a fan of one mode suits all bmesh code. Suggest instead passing bmesh to method, akin to a bmesh operator. Handle the saving outside based on mode. On a style side vert.select = sometest(vert) saves the need for if then true else false. – batFINGER Nov 22 '18 at 9:42
• I thought this handled the edit mode saving issue: ´if bm.is_wrapped: bmesh.update_edit_mesh(mesh, False, False) else: bm.to_mesh(mesh) mesh.update() # trigger viewport update bpy.context.scene.objects.active = bpy.context.scene.objects.active´ Otherwise, I don't really understand what you suggest I might do, I'm quite new to the scripting realm of Blender. This is a borrowed solution from a while back, so I suppose it might not work now. – Lycan Nov 22 '18 at 14:27