Forum

Author Topic: Proper method to close project via python API  (Read 4102 times)

ashalota

  • Jr. Member
  • **
  • Posts: 93
  • Forest orthomosaics, long transects (300m agl)
    • View Profile
    • NASA: G-LiHT (Public orthomosaics)
Proper method to close project via python API
« on: January 11, 2021, 05:49:19 PM »
I've noticed I end up with a 'read-only' lock on my projects some times after I have made adjustments through my python script.

What is the correct way to close the document so it goes away when I am done working on it in python? I don't see a "close" method anywhere in the API. My best guess is to just open a blank Metashape project when I am done with my current project?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Proper method to close project via python API
« Reply #1 on: January 13, 2021, 09:02:50 PM »
Hello ashalota,

Can you please describe the common workflow that you are using, when the "read-only" lock appears? Do you perform multiple operations with the projects using scripting in the same Metashape instance?
Best regards,
Alexey Pasumansky,
Agisoft LLC

ashalota

  • Jr. Member
  • **
  • Posts: 93
  • Forest orthomosaics, long transects (300m agl)
    • View Profile
    • NASA: G-LiHT (Public orthomosaics)
Re: Proper method to close project via python API
« Reply #2 on: January 13, 2021, 09:38:31 PM »
I believe I may have solved this issue by running "Metashape.Document()" when I am done with my process.

The issue occurred because I had been opening a project, working on it, and then transferring it to another computer. The other computer then never received any information that I ultimately closed the project. I am now making sure to "close" the project within my script by running Metashape.Document() before sending it to the other computer.

3DWinter

  • Full Member
  • ***
  • Posts: 103
    • View Profile
Re: Proper method to close project via python API
« Reply #3 on: March 18, 2021, 10:15:31 AM »
Same here. After every time I ran my code, I would open the new project and it would be as read-only, which caused Metashape to be unstable!
I was looking for a close method for the document in my code, something like doc.close() but didn't find it in the API manual.

There is doc.open(project_name), and doc.save(), why not doc.close()?

Your solution of Metashape.Document(), does solve the problem. It enables me to open the project right after the code ran. I just don't know if that is what Agisoft expected us to do, or is there a more elegant way.
thanks

3DWinter

  • Full Member
  • ***
  • Posts: 103
    • View Profile
Re: Proper method to close project via python API
« Reply #4 on: February 25, 2023, 04:30:01 AM »
Hello,
Almost two years ago, it seemed like I had a bandaid to closing a Metahsape project processed completely with Python API.
The last two code lines are:
Code: [Select]
Doc.save()
Metashape.Document()
Yet,
1. If I open with the GUI I  get a message
             The project is opened in read-only mode because it is already in use by DESKTOP.... or was not closed
             properly. Do you want to edit it anyway?
2. If I open the existing project with python API I cannot save the changes
Code: [Select]
OSError: Document.save(): editing is disabled in read-only mode
So what am I doing wrong at the end of my python code after finishing processing?
« Last Edit: February 25, 2023, 04:31:35 AM by 3DWinter »

MariusB

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Proper method to close project via python API
« Reply #5 on: March 01, 2023, 10:27:10 AM »
Hello,

same problem here!
I´m still using  V1.84
I´ve tried both version (also together  ;D)
 
Code: [Select]
doc.save(path = '...psx'))
#Metashape.app.quit()
quit()

I found a way to fix it manually by deleting the lock file in the .files subfolder - but we are using Metashape with several licenses in different locations, so I won´t tell them please delete it or write a little batch to do this.

 

3DWinter

  • Full Member
  • ***
  • Posts: 103
    • View Profile
Re: Proper method to close project via python API
« Reply #6 on: March 11, 2023, 09:39:37 PM »
Thanks Marius, that is a creative solution!

Metashape team, or anyone else, is there no proper way to close to the project so it can be opened later to read and write?
Thanks