Forum

Author Topic: Saving project with Python API after changing camera paths  (Read 6670 times)

anto3563

  • Newbie
  • *
  • Posts: 2
    • View Profile
Saving project with Python API after changing camera paths
« on: November 17, 2025, 09:15:04 PM »
Hi,

I’m trying to update the photo paths in my Metashape project using Python API, but the changes don’t persist after calling doc.save().

If I use doc.save(new_project_path) after modifying the paths, then the updated paths are correctly written. But using doc.save() on a project file that has already been saved once does not update the paths.

It looks like the paths are stored in frames.zip, and this archive isn’t being rewritten when using doc.save(). I also tested in Metashape GUI with 'Change Path...' option and it works well in this case, both with the save and save as options, the frames.zip file is updated.

Is there a way to force Metashape to update the paths with doc.save() directly, without having to save the project under a new name?

Thank you,
Antoine

marcel.d

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Saving project with Python API after changing camera paths
« Reply #1 on: November 24, 2025, 01:33:52 PM »
Hey,

Could you please post a minimal reproducible example of the code you're using? Maybe someone would then spot a potential source of error.

Best,
Marcel

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15635
    • View Profile
Re: Saving project with Python API after changing camera paths
« Reply #2 on: November 24, 2025, 04:30:46 PM »
Hello Antoine,

Example of code would be helpful, as it seems that the applied changes are not considered as modification of the project and therefore are ignored, when doc.save() command is called.
You may try to add some random info to camera.photo.meta for the cameras with modified paths and check, if it also triggers the modification of the project and allows to keep modified paths on document save.
For example:
import time
Code: [Select]
camera.photo.meta["PathModifyDate"] = time.ctime()
Best regards,
Alexey Pasumansky,
Agisoft LLC

anto3563

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Saving project with Python API after changing camera paths
« Reply #3 on: December 08, 2025, 06:51:18 PM »
Hi Marcel and Alexey,

Thank you for your answers and sorry for the delay in responding.

I tried the suggested solution of changing metadata to camera.photo.meta, but unfortunately it still doesn't trigger the path changes to be saved.

Here's a minimal reproducible example:

Code: [Select]
import Metashape
import os
import time

# Create a project and add photos
project_file = '/path/to/test_project.psx'
images_path = "/path/to/images"

doc = Metashape.Document()
Metashape.app.settings.project_absolute_paths = True
chunk = doc.addChunk()

# Add some photos (adjust path pattern as needed)
photo_files = [os.path.join(images_path, f) for f in os.listdir(images_path) if f.endswith(('.jpg', '.JPG', '.tif', '.TIF'))]
chunk.addPhotos(photo_files[:5])  # Just add a few for testing

# Save the project initially
doc.save(project_file)
print(f"Initial path: {chunk.cameras[0].photo.path}")
# Initial path: /mnt/nfs/labo/.../.JPG

# Now modify the photo paths
for camera in chunk.cameras:
    old_path = camera.photo.path
    # Change from Linux mount to UNC path (or any other modification)
    new_path = old_path.replace("/mnt/nfs/labo/", "//labo/")
    camera.photo.path = new_path
   
    # Try changing metadata as suggested
    camera.photo.meta["PathModifyDate"] = time.ctime()

print(f"Modified path (before save): {chunk.cameras[0].photo.path}")
# Modified path (before save): //labo/.../.JPG

# Save with doc.save() - this doesn't persist the path changes
doc.save()

# Reload the project to verify
doc.open(project_file)
print(f"Path after reload: {doc.chunk.cameras[0].photo.path}")
# Expected: The modified path (//labo/...)
# Actual: The original path (/mnt/nfs/labo/...)

# Compare with doc.save(new_path) which work:
# Modify the photo paths again
for camera in doc.chunk.cameras:
    old_path = camera.photo.path
    # Change from Linux mount to UNC path (or any other modification)
    new_path = old_path.replace("/mnt/nfs/labo/", "//labo/")
    camera.photo.path = new_path

new_project_file = '/path/to/test_project_v2.psx'
doc.save(new_project_file)  # This correctly saves the modified paths
doc.open(new_project_file)
print(f"Path in new project file: {doc.chunk.cameras[0].photo.path}")
# This shows the updated paths (//labo/...)

Best,
Antoine