As @X Y suggested, this can be done with ray_cast
. Coordinate x = 0 along with your y and z coordinates can be used to set the origin of the ray casts. You can then shoot one ray in the -x direction and another in the +x direction to get the intersection points p1
and p2
, which are stored in index 1 of the two cast results. I also added a two tiny spheres to verify the intersections.
import bpy
from mathutils import Vector
someObj = bpy.data.objects['SomeObject']
y = -2
z = -1
origin = Vector((0, y, z))
direction = Vector((1, 0, 0))
# ray_cast parameters: (origin, direction, distance, depsgraph) --- excluding depsgraph
cast_result1 = someObj.ray_cast(origin, -direction, distance = 10)
# -x intersection point:
p1 = cast_result1[1]
cast_result2 = someObj.ray_cast(origin, direction, distance = 10)
# +x intersection point:
p2 = cast_result2[1]
# distance between intersection points:
distance = p2.x - p1.x
bpy.ops.mesh.primitive_uv_sphere_add(radius = 0.1, location = p1)
bpy.ops.mesh.primitive_uv_sphere_add(radius = 0.1, location = p2)

ray_cast
, It has a template on the text editor. docs.blender.org/api/current/… $\endgroup$