Hello stephan,
The size of the bounding box (chunk.region) is defined in the internal coordinate system, not in the local or geographic coordinates.
Possibly the easier way is no get the distance between the corresponding markers (it is already in the internal coordinates):
dist = chunk.markers[0].position - chunk.markers[1].position
dist = dist.norm()
newreg = chunk.region
newreg.size = PhotoScan.Vector([dist, dist,dist])
Alternatively you can calculate the scale factor to be applied to the real-world distance when trying to use ab.reference.distance:
import math
T = chunk.transform.matrix
v_t = T.mulp(PhotoScan.Vector([0,0,0])
if chunk.crs:
m = chunk.crs.localframe(v_t)
else:
m = PhotoScan.Matrix().diag([1,1,1,1])
m = m * T
s = math.sqrt(m[0,0] ** 2 + m[0,1] ** 2 + m[0,2] ** 2) #scale factor
dist = ab.reference.distance
newregion = chunk.region
newregion.size = PhotoScan.Vector([dist, dist, dist]) / s
chunk.region = newregion