Hello Milderinne,
Providing that the chunk is referenced, scale bar has input (source) distance and both of it's ends are defined in space you can use the following code to get the estimated distance and errors:
chunk = PhotoScan.app.document.chunk #active chunk
for scalebar in chunk.scalebars:
dist_source = scalebar.reference.distance
if not dist_source:
continue #skipping scalebars without source values
if type(scalebar.point0) == PhotoScan.Camera:
if not (scalebar.point0.center and scalebar.point1.center):
continue #skipping scalebars with undefined ends
dist_estimated = (scalebar.point0.center - scalebar.point1.center).norm() * chunk.transform.scale
else:
if not (scalebar.point0.position and scalebar.point1.position):
continue #skipping scalebars with undefined ends
dist_estimated = (scalebar.point0.position - scalebar.point1.position).norm() * chunk.transform.scale
dist_error = dist_estimated - dist_source
print(scalebar.label,str(dist_source),str(dist_estimated),str(dist_error))