"""Floor and ceiling height at given XY points of an opened .blend (ray casts), for placing study cameras. blender -b --factory-startup --python build/study_probe.py -- "x,y;x,y;..." [z_start] """ import json import sys import bpy from mathutils import Vector argv = sys.argv[sys.argv.index("--") + 1:] pts = [tuple(float(v) for v in p.split(",")) for p in argv[0].split(";") if p.strip()] z0 = float(argv[1]) if len(argv) > 1 else 1.5 dg = bpy.context.evaluated_depsgraph_get() sc = bpy.context.scene out = [] for x, y in pts: down = sc.ray_cast(dg, Vector((x, y, z0)), Vector((0, 0, -1)), distance=30) up = sc.ray_cast(dg, Vector((x, y, z0)), Vector((0, 0, 1)), distance=30) out.append({"xy": [x, y], "floor": round(down[1].z, 2) if down[0] else None, "floor_obj": down[4].name if down[0] else None, "ceil": round(up[1].z, 2) if up[0] else None, "ceil_obj": up[4].name if up[0] else None}) print("PROBE " + json.dumps(out))