Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: nickponline on May 14, 2014, 02:08:57 AM
-
Hi there,
When I type the following commands in the console, it works as expected:
import PhotoScan
doc = PhotoScan.app.document
chunk = doc.chunks.add()
chunk.label = 'My Chunk'
Also if I put in in a script and execute it from Tools->Run script it works.
BUT, if I put those command in a script in ~/Library/Application\ Support/Agisoft/PhotoScan\ Pro/scripts and launch PhotoScan it fails with:
https://www.dropbox.com/s/4x3b9692kp8w5fo/Screenshot%202014-05-13%2016.08.09.png
-
I upgraded to Pro because I thought it would work :( what is the difference? How can I get the behavior I want from the script to run automatically.
-
Hello nickponline,
Access to PhotoScan.app.document is blocked for scripts put in autostart folder. So to start processing script it is necessary to run it from GUI via Run Script dialog or custom menu item created using autorun scripts.
-
Thanks. Ok I've finally changed my script to be run from the GUI instead of the autostart folder. Now how can I get photoscan to execute Run Script when it start automatically?
-
Hello nickponline,
Processing script should be started by the operator.
-
Hello nickponline,
Processing script should be started by the operator.
Hello,
Is there any way to run PhotoScan Python scripts in headless mode, without needing to click "Tools->Run Script"?
I'd like to setup PhotoScan on a linux server, that doesn't have Desktop installed.
It would be nice to run it from console with command like this:
xvfb-run ./photoscan -script /path/to/the/script.
best,
Dmitry
-
Hello Dmitry,
In the next version of PhotoScan Pro (v. 1.3) it would be possible to run the script from the command line using -r key and path to the script as an argument. You can download the version 1.3 pre-release from the corresponding forum thread:
http://www.agisoft.com/forum/index.php?topic=5976.0
So it should work like:
./photoscan.sh -r script.py
-
Hello Dmitry,
In the next version of PhotoScan Pro (v. 1.3) it would be possible to run the script from the command line using -r key and path to the script as an argument. You can download the version 1.3 pre-release from the corresponding forum thread:
http://www.agisoft.com/forum/index.php?topic=5976.0
So it should work like:
./photoscan.sh -r script.py
Thanks, that's great!
-
Hi Alexey Pasumansky,
What is the expected date for stable release of v1.3? Thanks!
-
Hello venkatg,
I think it would be released in the end of this year, so might be late December.
-
Hello Alexey,
The '-r' key works well in PhotoScan Pro v1.3, but I've noticed an error in its log:
'Can’t save dense project file'.
In spite of the error the project file being saved successfully.
So should I pay attention to that error or it's just a bug with console output?
---Build dense cloud...
---Save dense project: /path/to/denseprojfile.psx
SaveProject
saved project in 1.029 sec
LoadProject
loaded project in 0.004735 sec
---Can’t save dense project file
LoadProject
loaded project in 0.003707 sec
---Build digital elevation model...
---Build orthomosaic...
-
Hello Dmitry,
Can you post a part of code that is related to the following output:
---Save dense project: /path/to/denseprojfile.psx
SaveProject
saved project in 1.029 sec
LoadProject
loaded project in 0.004735 sec
---Can’t save dense project file
LoadProject
loaded project in 0.003707 sec
I see that the project is saved, but due to some additional custom messages in the console, I assume that some additional operations may be performed. Or the printing function related to the " ---Can’t save dense project file" is not properly implemented.
The difference, as I assume, may be related to the different handling of the errors in the version 1.2 and 1.3: now processing and saving operations do not return Boolean value (maybe in your script you are checking that), now if the operation fails it results in RuntimeError, for example:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-47-0b71e7b52316> in <module>()
----> 1 doc.save(__some_invalid_path__)
RuntimeError: Can't save project
So you need to catch such operations errors with try&except approach:
try:
doc.save()
except RuntimeError:
print("Oops, can't save project.")
Hope it will solve the problem.
-
@Alexey
Exactly, we just needed to replace the old Boolean code with new Try/Catch one.
Thank you!
-
Hello Dmitry,
Nice to hear that it works. If you were using some additional checks for other processing options in a similar way (like matchPhotos(), buildDenseCloud() and etc.), then you also need to replace it accordingly.