(Note: I had perplexity generate this bug report as I was using it to debug and find the issue. I did not reproduce this in simple isolation as implied here. This is just to illustrate the point. I did see in my debugging session that the modified state did not become `True` again once the doc was saved, and I also confirmed the workaround to use the chunks argument. I am leaving all of this information here in case it is helpful)
Metashape Version: 2.1.1
Description:
When using the Metashape Python API, the document modification state is not being updated correctly after saving the document. This leads to subsequent changes not being saved in following save operations unless a specific workaround is used.
Steps to Reproduce:
1. Open a new or existing document in Metashape using the Python API.
2. Make initial changes to the document (e.g., add photos, align cameras).
3. Save the document using `doc.save(path)`.
4. Make additional changes.
5. Check the modification state using `doc.modified`. It is still False.
6. Save the document again using `doc.save(path)`.
7. Open the saved document to verify changes.
Expected Behavior:
After making changes in step 4, `doc.modified` should return `True`. The second save operation should include all changes made after the first save.
Actual Behavior:
After making changes in step 4, `doc.modified` remain `False`. The second save operation does not include changes made after the first save, particularly changes to camera reference data.
Workaround:
The issue can be resolved by explicitly specifying the chunks to save using the `chunks` parameter in the `save` method:
```python
doc.save(path, chunks=[doc.chunk])
This workaround ensures that all changes to the specified chunks are saved, even if the modification state is not correctly updated.
Additional Observations:
The exportReference function correctly exports the changed reference data to a CSV file, confirming that the changes are made in memory.
Even changing camera labels after the first save does not trigger the modified state or get saved in subsequent save operations without the workaround.
If the initial save operation (step 3) is omitted, all changes are saved correctly without needing the workaround.
Code Example:
import Metashape
doc = Metashape.Document()
chunk = doc.addChunk()
# Initial setup and changes
# ... (add photos, align cameras, etc.)
doc.save("project.psx") # First save
# Make changes to reference data
for camera in chunk.cameras:
camera.reference.location = [1, 2, 3]
camera.label = camera.label + "_NEW"
print("Modified state:", doc.modified) # Prints False
# Workaround: Save with explicit chunks parameter
doc.save("project.psx", chunks=[chunk]) # Second save
# Open project.psx manually to verify - changes are now saved