Forum

Author Topic: Python Doc Save doesn't save as processing progresses  (Read 1486 times)

Bolli

  • Newbie
  • *
  • Posts: 21
    • View Profile
Python Doc Save doesn't save as processing progresses
« on: February 15, 2022, 10:43:09 PM »
Hello Forum,
I'm using Metashape 1.7.0 and am trying to piece meal some python code together to process some photos into dense clouds. I've gotten the code to run all the way through but what I notice is that, despite using doc.save(path) at the beginning and doc.save() throughout the code, that the project is virtually blank when I open it up. I've seen some other forum posts like https://www.agisoft.com/forum/index.php?topic=12003.0 and https://www.agisoft.com/forum/index.php?topic=8662.0, but am struggling with figuring this out.

Here is the top part of my code before I start going into the processing and doc.save() steps where I would expect to get a .psx with my photos loaded into it:
Quote
import Metashape
import os, sys, time
import math
import json

#Definitions
img_path = sys.argv[1]
export_folder = "Exports"

proj_dir, jpeg_name = os.path.split(img_path)
base_dir, proj_name = os.path.split(proj_dir)
print()

export_path = os.path.join(proj_dir,export_folder)
#make sure the export workspace exists.  if not - make them.
if not os.path.exists(export_path):
    os.makedirs(export_path)

##Define photos list
photos = [os.path.join(img_path, file)
        for file in os.listdir(img_path)
        if file.endswith('.JPG')]

#Define which document
doc = Metashape.Document()
#Define which chunk
chunk = Metashape.app.document.chunk

doc.save(export_path + '/' + proj_name + '.psx')


#Add Photos
chunk.addPhotos(photos)
doc.save()

print(str(len(chunk.cameras)) + " images loaded")

Bolli

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Python Doc Save doesn't save as processing progresses
« Reply #1 on: February 18, 2022, 07:54:41 PM »
I think I've defined chunk incorrectly to get the save to work properly.

I'm struggling with when to use the following:

chunk = Metashape.app.document.chunk
chunk = doc.chunk
chunk = doc.addChunk()

AND

doc = Metashape.Document()
doc = Metashape.app.document



« Last Edit: February 18, 2022, 07:56:48 PM by Bolli »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Python Doc Save doesn't save as processing progresses
« Reply #2 on: February 19, 2022, 02:46:09 PM »
Hello Bolli,

Try to use the lines inthe following order:

Code: [Select]
doc = Metashape.Document()
doc.save(export_path + '/' + proj_name + '.psx')
chunk = doc.addChunk()
chunk.addPhotos(...)
doc.save()
chunk.matchPhotos(...)
...
doc.save()

Metashape.app.document and Metashape.app.document.chunk wouldn't work for the scripts started outside Metashape GUI.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Bolli

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Python Doc Save doesn't save as processing progresses
« Reply #3 on: February 25, 2022, 04:26:59 PM »
Thanks for that reply. That ends up working. I am starting all of my scripts from inside the GUI though. I don't see any of my items in the GUI but now they are saved and I can load them later. Thanks!


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Python Doc Save doesn't save as processing progresses
« Reply #4 on: February 25, 2022, 05:42:52 PM »
Hello Bolli,

If you wish to see the results in the GUI right after the script is finished, you need to replace doc = Metashape.Document() with doc = Metashape.app.document line.
Best regards,
Alexey Pasumansky,
Agisoft LLC