Hello lmg,
Here's a little bit more complicated version of the script that allows to export scalebars:
import PhotoScan
import math
scalebars = {"scale 1": ("point 1", "point 6"),
"scale 2": ("point 2", "point 3"),
"scale 3": ("point 4", "point 3")}
def dist(v1, v2):
result = v2 - v1
result = result.norm()
return result
print("Script started")
doc = PhotoScan.app.document
chunk = doc.activeChunk
if chunk.transform:
T = chunk.transform
else:
T = PhotoScan.Matrix().diag([1,1,1,1])
path = PhotoScan.app.getSaveFileName("Specify export path:")
file = open(path, "wt")
for frame in range(0, chunk.frame_count):
file.write("\nFrame # " + str(frame + 1) + " \n")
file.write("Markers:\n")
for marker in chunk.markers:
v = marker.positions[frame]
v.size = 4
v.w = 1
v = T * v
v.size = 3
if chunk.crs:
v = chunk.crs.project(v)
file.write( marker.label + " " + str(v.x) + " " + str(v.y) + " " + str(v.z) +"\n")
file.write("Scale-bars:\n")
for scalebar in scalebars.items():
(label, (m1, m2)) = scalebar
for marker in chunk.markers:
if m1 == marker.label:
marker1 = marker
elif m2 == marker.label:
marker2 = marker
scale = dist(marker1.positions[frame], marker2.positions[frame])
s = math.sqrt(T[0,0]*T[0,0] + T[0,1]*T[0,1] + T[0,2]*T[0,2])
file.write(label + " " + str(scale * s) + "\n")
file.close()
print("\n\nfinished")
However, you need to input scale bar labels and corresponding marker labels manually in the script body, like it is shown in the example (note that marker labels are case sensitive!).
I hope it will work fine for you.