Forum

Author Topic: Python scripts stopped working in 1.6  (Read 2586 times)

codywils101

  • Newbie
  • *
  • Posts: 1
    • View Profile
Python scripts stopped working in 1.6
« on: February 12, 2020, 06:46:50 PM »
Hey all,

We have been using the same scripts for a few years now with no issues, including the update to Metashape. Since we recently updated to version 1.6, the scripts no longer work. We get an error that reads "Module 'Metashape' has no attribute '****' "

I tried this in version 1.6.0 and 1.6.1 and get the same error. After reverting to 1.5.4 (The last version we had) there is no issues.

I will attach one of this scripts here. The message with this reads specificaly "Module 'Metashape' has no attribute 'Mediumquality' "

Is this an error with our python install? Or will we need to revamp the scripts for version 1.6 and up?

 
Code: [Select]
import PhotoScan
import os

doc = PhotoScan.app.document


def get_save():
    path = PhotoScan.app.getSaveFileName("Save project as")
    try:
        doc.save(path)

    except RuntimeError:
        PhotoScan.app.messageBox("Can't Save Project")


def check_save():
    if doc.path is not "":
        print("save exists")
    else:
        print("no save file")
        get_save()


def align(chunk):
    chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy,
                      generic_preselection=True,
                      reference_preselection=False,
                      keypoint_limit=55000,
                      tiepoint_limit=5000
                      )
    chunk.alignCameras()


def align_all():
    for chunk in doc.chunks:
        align(chunk)
    doc.save()


def duplicate(chunk):
    name = chunk.label
    new = chunk.copy()
    new.label = "3D_PDF_{}".format(name)


def duplicate_all(export=True):
    for chunk in doc.chunks:

        # Max
        name = chunk.label
        chunk.label = "Max_{}".format(name)

        # Rhino
        rhino = chunk.copy()
        rhino.label = "Rhino_{}".format(name)
        rhino.decimateModel(1500000)
        rhino.buildUV(mapping=PhotoScan.GenericMapping)
        rhino.buildTexture(blending=PhotoScan.MosaicBlending,
                           size=4096)
        if export is True:
            ext = ".wrl"
            file = format_file(ext, rhino)
            rhino.exportModel(file)

        # PDF
        pdf = chunk.copy()
        pdf.label = "3D_PDF_{}".format(name)
        pdf.decimateModel(100000)
        pdf.buildUV(mapping=PhotoScan.GenericMapping)
        pdf.buildTexture(blending=PhotoScan.MosaicBlending,
                         size=4096)
        if export is True:
            ext = ".pdf"
            file = format_file(ext, pdf)
            pdf.exportModel(file)
        doc.save()


def process(chunk):
    chunk.buildDepthMaps(quality=PhotoScan.MediumQuality,
                         filter=PhotoScan.AggressiveFiltering)
    chunk.buildDenseCloud()
    chunk.buildModel(surface=PhotoScan.Arbitrary,
                     interpolation=PhotoScan.EnabledInterpolation,
                     face_count=0)
    chunk.buildUV(mapping=PhotoScan.GenericMapping)
    chunk.buildTexture(blending=PhotoScan.MosaicBlending,
                       size=4096)
    doc.save()


def process_all():
    for chunk in doc.chunks:
        process(chunk)


def decimate_pdf(chunk):
    chunk.decimateModel(100000)


def get_folder(chunk):
    pic = chunk.cameras[0].photo.path
    path = os.path.dirname(pic)
    return path


def format_file(ext, chunk):
    path = get_folder(chunk)
    file = "{}/{}{}".format(path, chunk.label, ext)
    return file


def main():
    check_save()
    align_all()


if __name__ == "__main__":
    main()

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14004
    • View Profile
Re: Python scripts stopped working in 1.6
« Reply #1 on: February 12, 2020, 07:39:10 PM »
Hello codywils101,

There were some changes in Python API 1.6, please check the reference PDF: https://www.agisoft.com/pdf/metashape_python_api_1_6_1.pdf

For image matching accuracy and depth maps quality you should use "downscale" argument now which takes int values.
Highest accuracy = 0, High = 1, Medium = 2, Low = 4
Ultra quality = 1, High = 2, Medium = 4, Low = 8

For buildDepthMaps method use "filter_mode" instead of "filter" argument.
For buildModel - use "surface_type" instead of "surface".
For buildUV - use "mapping_mode" instead of "mapping".
For buildTexture - use "texture_size" instead of "size" and "blending_mode" instead of "blending".
Best regards,
Alexey Pasumansky,
Agisoft LLC

darkl1ght

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Python scripts stopped working in 1.6
« Reply #2 on: November 02, 2020, 11:44:29 AM »
Hi Alexey,

Where can we get the reference for this downscale values for similar other parameters?

It's not present there in the python API documentation(version 1.6.x).

Thanks

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14004
    • View Profile
Re: Python scripts stopped working in 1.6
« Reply #3 on: November 04, 2020, 08:03:40 PM »
Hello darkl1ght,

I have listed them here:
https://www.agisoft.com/forum/index.php?topic=11697.msg52465#msg52465
Quote
For matching accuracy the correspondence should be the following:
Highest = 0
High = 1
Medium = 2
Low = 4
Lowest = 8

For depth maps quality:
Ultra = 1
High = 2
Medium = 4
Low = 8
Lowest = 16
Best regards,
Alexey Pasumansky,
Agisoft LLC