How to detect with a script, if an object touches or overlaps an other object?

Hello everybody

Is it possible to detect with a script, if an object touches or overlaps an other object? And if Yes, how to do that.
How to iterated through the list of objects is no problem. My problem is, how to check out if object A (a mesh) overlaps object B (an ohter mesh) or not? Is there a function to check that out or …?

I hope it is clear enough for everybody.

Thank you very much for any help.

Yeh I got it:

import mathutils.bvhtree
import bpy
import bmesh
from mathutils.bvhtree import BVHTree

def overlapping(obj1, obj2):
bm1 = bmesh.new()
bm2 = bmesh.new()
bm1.from_mesh(obj1.data)
bm2.from_mesh(obj2.data)
bm1.transform(obj1.matrix_world)
bm2.transform(obj2.matrix_world)
#make BVH tree from BMesh of objects
obj_1_BVHtree = BVHTree.FromBMesh(bm1)
obj_2_BVHtree = BVHTree.FromBMesh(bm2)
inter = obj_1_BVHtree.overlap(obj_2_BVHtree)
return inter;

obj1 = bpy.context.scene.objects[‘Cube’]
obj2 = bpy.context.scene.objects[‘Cube.001’]

inter = overlapping(obj1,obj2)

if inter != []:
obj1.select = True # touching
else:
obj2.select = True # not touching