Look into this answer, as it is similiar.
My example will handle an XYZ bounding box with perpendicular edges only. Otherwise look into batFINGER's suggestion.
Paste the code into Blender's Text Editor and press "Run Script".
import bpy
from mathutils import Vector
# checks if a supplied coordinate if in the bounding box created by vector1 and vector2
# vector_check the vector which is compared against the bounding box
# vector1 the vector defining the start of the bounding box
# vector2 the vector defining the end of the bounding box
def IsInBoundingVectors(vector_check, vector1, vector2):
# if vector_check is either bigger or smaller than both other, it does not lie between them
# in that case it won't be inside the bounding box; hence return false
for i in range(0, 3):
if (vector_check[i] < vector1[i] and vector_check[i] < vector2[i]
or vector_check[i] > vector1[i] and vector_check[i] > vector2[i]):
return False
return True
def SelectObjectsInBound(vector1, vector2):
# deselect all
bpy.ops.object.select_all(action='DESELECT')
# cycle through all objects in the scene
for obj in bpy.context.scene.objects:
# check if the object is in the bounding vectors
# if yes, select it
# if no, deselect it
if(IsInBoundingVectors(obj.matrix_world.to_translation(), vector1, vector2)):
obj.select = True
else:
obj.select = False
SelectObjectsInBound(Vector((0, 0, -5)), Vector((10, 15, 15)))