What needs to be changed to get this script to run in v.1.8 please?
# This script outputs measurements in US survey foot
import Metashape as PhotoScan
def main():
chunk = PhotoScan.app.document.chunk #active chunk
method = "bestfit" # "mean", custom
volume_tot = "total" #"above", "below"
volume_ab = "above"
volume_be = "below"
ca = 3.2808333333 * 3.2808333333 # conversion from m2 to USft2
cv = 3.2808333333 * 3.2808333333 * 3.2808333333 / 27 # conversion from m3 to USyd3
if not chunk.shapes:
raise Exception("No shapes!")
return False
if not chunk.elevation:
raise Exception("No Elevation Model!")
return False
if not len(chunk.shapes):
raise Exception("No shapes!")
return False
path = PhotoScan.app.getSaveFileName("Specify output path:", filter ="Text / CSV (*.txt *.csv);;All files (*.*)")
if not path:
raise Exception("Invalid path!")
return False
file = open(path, "wt")
file.write("Layer Label\t Shape ID\tShape Label\t Volume-yd3 (" + volume_ab + ")\t Area-ft2\tMethod\n")
for shape in chunk.shapes:
if shape.type != PhotoScan.Shape.Polygon:
continue
label = shape.label
if not label:
label = "<no label>"
layer = shape.group.label
if not layer:
layer = "<no label>"
layer_id = shape.group.key
shape_id = shape.key
area = shape.area()
volume = shape.volume(level = method)
output = "{:11s}\t{:8d}\t{:11s}\t{:16.5f}\t{:12.5f}\t{:8s}\n".format(layer, shape_id, label, round(volume[volume_ab]*cv), round(area*ca), str(method))
file.write(output)
file.flush()
file.close()
print("Finished")
PhotoScan.app.addMenuItem("Volumes/Export measurements for polygons", main)