Forum

Author Topic: Python script no longer running in Metashape 1.7.4  (Read 7316 times)

Cyberworld

  • Newbie
  • *
  • Posts: 38
    • View Profile
Python script no longer running in Metashape 1.7.4
« on: August 24, 2021, 12:54:32 PM »
Has anything changed with how Python is handled in Metashape 1.7.4? The script below worked with 1.7.3, but it no longer does.

Code: [Select]
import Metashape

chunk = Metashape.app.document.chunk

for marker in chunk.markers:
for photo in list(marker.projections.keys()):
if not marker.projections[photo].pinned:
marker.projections[photo] = None
print("Projection for "+marker.label + " removed on " + photo.label)

print("Script finished")

Any suggestions?

Cyberworld

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Python script no longer running in Metashape 1.7.4
« Reply #1 on: August 24, 2021, 01:07:13 PM »
Apparently [photo] has been replaced by [camera], and script running now requires for reasons I don't yet understand administrative rights.

The following worked:

Code: [Select]
import Metashape
chunk = Metashape.app.document.chunk
for marker in chunk.markers:
    for camera in list(marker.projections.keys()):
        if not marker.projections[camera].pinned:
            marker.projections[camera] = None

Also the print commands kept causing script failure, but once removed everything worked. All in all consider the issue resolved.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15432
    • View Profile
Re: Python script no longer running in Metashape 1.7.4
« Reply #2 on: August 24, 2021, 02:28:13 PM »
Hello Cyberworld,

The code from your initial post works fine in Metashape 1.7.4 (just copied it to Metashape Console pane for some random project).

photo is just an intermediate variable name in the provided script and can be replaced by any other label in all the occurrences, it wouldn't affect the script.

So, if you have some problems with the script, please provide some additional details - are there any error messages, for example.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Cyberworld

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Python script no longer running in Metashape 1.7.4
« Reply #3 on: August 25, 2021, 09:02:21 AM »
Hi Alexey,

I tried to reproduce the issue today with the previous code and it functions as expected, so I guess some sort of random error. The error it was giving was: "Error: Run script failed"

I did update graphic cards drivers yesterday too, because it was giving a "Can't find tile size" error too, but I'm guessing this was unrelated. In any event, it all works now.

chitty1989

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Python script no longer running in Metashape 1.7.4
« Reply #4 on: March 22, 2022, 03:11:45 AM »
Im running a script as part of a batch and im getting this message.  The scripts work when not added as part of the batch. however as soon as i put it in the batch it gives the following error

2022-03-22 11:04:44 RunScript: path = C:/Program Files/Agisoft/Metashape Pro/python/Scripts/01GradualSelect_Resize.py
2022-03-22 11:04:44 Can't open script: C:/Program Files/Agisoft/Metashape Pro/python/Scripts/01GradualSelect_Resize.py
2022-03-22 11:04:44 Finished processing in 0.741 sec
2022-03-22 11:04:44 Saving project...
2022-03-22 11:04:44 saved project in 0.001 sec
2022-03-22 11:04:45 Finished batch processing in 3.72 sec (exit code 1)
2022-03-22 11:05:38 Error: Run script failed

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15432
    • View Profile
Re: Python script no longer running in Metashape 1.7.4
« Reply #5 on: March 22, 2022, 12:58:03 PM »
Hello chitty1989,

Can you share the script that you are running via Batch Process or at least part of it that can be also used to reproduce the problem?
Best regards,
Alexey Pasumansky,
Agisoft LLC