Hello Andreas,
Here's modified script:
#creates scale bars from the camera pair with the following naming convention: "NM_links..." + "NM_rechts..."
#compatibility PhotoScan Pro 1.1.2
import PhotoScan
from PySide import QtCore, QtGui
doc = PhotoScan.app.document
chunk = doc.chunk
print("Script started...")
links, rechts = {}, {}
for camera in chunk.cameras:
if camera.label[0:2].isdecimal() and len(camera.label) > 8:
if "_links" == camera.label[2:8]:
links[int(camera.label[0:2])] = camera
elif "_rechts" == camera.label[2:9]:
rechts[int(camera.label[0:2])] = camera
processed = 0
for num in links.keys():
if num in rechts.keys():
chunk.addScalebar(links[num], rechts[num])
processed += 1
if processed:
print(str(processed) + " scale bars created.")
else:
print("No matching pairs!")
app = QtGui.QApplication.instance()
parent = app.activeWindow()
msg = "Do you wish to import distance values?"
reply = QtGui.QMessageBox.question(parent, 'Message', msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if (reply == QtGui.QMessageBox.Yes) and chunk.scalebars:
path = PhotoScan.app.getOpenFileName("Select input text file:")
file = open(path, "rt")
scalebars = {}
for scalebar in chunk.scalebars:
scalebars[scalebar.label] = scalebar
eof = False
line = file.readline()
while not eof:
label, dist = line.split()[0], line.split()[1]
if label in scalebars.keys():
scalebars[label].reference.distance = float(dist)
line = file.readline() #reading the line in input file
if not len(line):
eof = True
break
file.close()
PhotoScan.app.update()
print("Script finished")
else:
print("Script finished")
The first part is the same, then after the scalebars are created you'll be asked if you wish to import the distances, if you choose Yes, you'll be asked to specify the path to the text file.
In such file on each line you need to have the scalebar label (the same as in Reference pane) and the corresponding distance. I suggest to use "tab" or "space" delimiter.