Forum

Author Topic: Update script for 1.8  (Read 1418 times)

dpitman

  • Full Member
  • ***
  • Posts: 246
    • View Profile
Update script for 1.8
« on: June 02, 2022, 06:58:53 AM »
What needs to be changed to get this script to run in v.1.8 please?

Code: [Select]
# 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)

Paulo

  • Hero Member
  • *****
  • Posts: 1339
    • View Profile
Re: Update script for 1.8
« Reply #1 on: June 02, 2022, 12:45:30 PM »
Hello Dave,

I think I recognize this script! you should replace line:
Code: [Select]
if shape.type != PhotoScan.Shape.Polygon:with:
Code: [Select]
if shape.geometry.type != PhotoScan.Geometry.Type.PolygonType:
Should work.... curious why do you round your volume_yd3 and Area_ft2 to 0 decimals?
Best Regards,
Paul Pelletier,
Surveyor

dpitman

  • Full Member
  • ***
  • Posts: 246
    • View Profile
Re: Update script for 1.8
« Reply #2 on: June 02, 2022, 03:58:18 PM »
Thank you, Paul, it works now!.  I thought that you had written that script or at least modified it.

I round the yd3 because of the scale of the piles that I'm measuring. They range 500 to 30,000 yd3 and no one cares about the partials. It results in a cleaner report.

Now, 8 decimal places on a coordinate, I want that !  :)

Paulo

  • Hero Member
  • *****
  • Posts: 1339
    • View Profile
Re: Update script for 1.8
« Reply #3 on: June 02, 2022, 04:54:14 PM »
I see great!

Keep in touch
Best Regards,
Paul Pelletier,
Surveyor