Hi ahg,
the following code would work perfectly, if your images are named as left_XXX and right_XXX with XXX being a secuential number:
import Metashape
chunk = Metashape.app.document.chunk
cameras = [camera for camera in chunk.cameras if camera.type == Metashape.Camera.Type.Regular]
while cameras:
camera1 = cameras.pop(0)
for camera2 in cameras:
if camera1.label.rsplit("_", 1)[1] == camera2.label.rsplit("_", 1)[1]:
cameras.remove(camera2)
scalebar = chunk.addScalebar(camera1, camera2)
scalebar.reference.distance = 1
break
print("script finished")
Now if you do not have a Underscore between left/right and number then you would need to modify code with something like
if camera1.label[0] == "l":
label1 = camera1.label.lstrip('left')
else:
label1 = camera1.label.lstrip('right')
do the same defining label2 for camera2 inside loop and finally test
if label1 == label2:
Maybe this can send you a good path!