Forum

Author Topic: Behavior of Document.save()  (Read 6691 times)

Miles_WADNR

  • Newbie
  • *
  • Posts: 5
    • View Profile
Behavior of Document.save()
« on: April 04, 2018, 06:32:21 PM »
Hi there,
I have a question about the correct use of the Document.save() function in 1.4.x. In a script, I’m creating a new PhotoScan.Document() instance, and saving it to a path:
Code: [Select]
current_doc = PhotoScan.Document()
    current_chunk = current_doc.chunk
    if current_chunk == None:
        current_chunk = current_doc.addChunk()
    current_doc.save(path=project_doc, chunks=[current_chunk])

The script aligns the images (and saves, using the same command), and then tries to build a DEM, but I keep getting an “Empty Frame Path: Please save in .PSX format” error. I’ve tried just using current_doc.save(), using PhotoScan.app.document as current_doc, and pretty much every permutation of .save() I can think of, without success.

I’ve noticed that, if I’m just opening a previously created document, using .save() works the way I would expect, but when I’ve created a new document and saved it using (path=…), it doesn’t.

How can I create a new document and save it in a way that .buildDem() can recognize?

Thanks! And apologies if this is a novice question.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Behavior of Document.save()
« Reply #1 on: April 04, 2018, 07:13:25 PM »
Hello Miles_WADNR,

When you are passing some path argument to doc.save() function, it works similar to Save As operation (providing that PSX format is used), so the document is re-opened, it means that you need to re-assign all variables related to the chunk. Otherwise, it appears that you are trying to build the DEM for the chunk that is not in the saved (re-opened) document.

I would rather suggest to use doc.save(path) in the beginning of the script right after creating PhotoScan.Document() instance. Later on use doc.save() function without arguments.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Miles_WADNR

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Behavior of Document.save()
« Reply #2 on: April 04, 2018, 07:39:02 PM »
Hi Alexey,
Thanks for the quick response.
If I convert the doc.save(path=...) function to one without arguments, I get this error:

2018-04-04 09:31:47 Traceback (most recent call last):
2018-04-04 09:31:47   File "//dnrfsoly110/uas_data/scripts/mmic490/FullyAutomated/PhotoScan_InitializeProject.py", line 52, in <module>
2018-04-04 09:31:47     current_doc.save()
2018-04-04 09:31:47 RuntimeError: Can't replace file or directory: Access is denied (5): C:/Program Files/Agisoft/PhotoScan Pro
2018-04-04 09:31:47 Error: Can't replace file or directory: Access is denied (5): C:/Program Files/Agisoft/PhotoScan Pro

I'm not sure I've understood correctly how I should be reassigning variables after using doc.save(path). Here's my code to the point of the above error:
Code: [Select]
    current_doc = PhotoScan.Document()
    current_chunk = current_doc.chunk
    if current_chunk == None:
        print("Adding chunk")
        current_chunk = current_doc.addChunk()
    current_doc.save(path=project_doc, chunks=[current_chunk])
    current_chunk = current_doc.chunk

    #Add photos
    photo_list = []
    for photo in os.listdir(input_folder):
        photo_list.append(os.path.join(input_folder, photo))
    print("Adding {} photos".format(len(photo_list)))
    current_chunk.addPhotos(photo_list)
##    current_doc.save(path=project_doc, chunks=[current_chunk])
    current_doc.save()

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Behavior of Document.save()
« Reply #3 on: April 04, 2018, 08:38:53 PM »
Hello Miles_WADNR,

I mean something like the following:

Code: [Select]
current_doc = PhotoScan.Document()
current_doc.save(path=project_doc)
...
...
...
current_doc.save()

So create the document, save it to some location and only then perform other actions with the document (create chunk, perform processing and etc.)
Best regards,
Alexey Pasumansky,
Agisoft LLC

Miles_WADNR

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Behavior of Document.save()
« Reply #4 on: April 04, 2018, 11:17:16 PM »
Aha! I understand now. Thanks Alexey, that's just what I needed.

Geend

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Behavior of Document.save()
« Reply #5 on: April 24, 2018, 03:56:36 PM »
Hello Miles_WADNR,

I mean something like the following:

Code: [Select]
current_doc = PhotoScan.Document()
current_doc.save(path=project_doc)
...
...
...
current_doc.save()

So create the document, save it to some location and only then perform other actions with the document (create chunk, perform processing and etc.)


Hello Alexey,
this issue seems to occure quiet often. It happedn to Miles_WADNR, it happend to Henry (http://www.agisoft.com/forum/index.php?topic=8751.0) and it happend to me (http://www.agisoft.com/forum/index.php?topic=8449.0).


I suggest you include this in the documentation of Document.save(...) in the python api reference document.

Best regards,
Torben

jvduijvenbode

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Behavior of Document.save()
« Reply #6 on: January 10, 2019, 08:47:37 PM »
I first save to a specific psx file, after which i only use doc.save(). i use version 1.5.0. Even though i first specified the psx file, everytime i use the simple doc.save later in the process i get
Error: Can't create file: Access is denied (5): C:/Program Files/metashape.tmp

for some reason it is not remembering that i did specify a doc.save before. as also stated in other topics, when i give the path as an argument everytime i use doc.save i end up with an empty project. So what do i do here?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Behavior of Document.save()
« Reply #7 on: January 11, 2019, 01:04:56 PM »
Hello jvduijvenbode,

Can you please post all the lines related to doc creation, doc.open and save.save operations from your script?
Best regards,
Alexey Pasumansky,
Agisoft LLC

jvduijvenbode

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Behavior of Document.save()
« Reply #8 on: January 16, 2019, 05:36:09 PM »
Hi Alexey,

It works now, i only save after building the model with a specified save location, before building the orthomosaic. I removed everything conserved to saving between starting and aligning the images. Don't know why but i don't want to touch it anymore. thanks for your reply