Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: 7eicher on September 08, 2013, 01:09:52 AM
-
would be interesting to know which images are selected, in the API.
e.g. to export some of them undistorted for later texture remapping in an external tool.
-
Hello 7eicher,
There is a flag camera.selected, so you can run a loop through all the cameras in the chunk.
-
Thanks Alexey, thats good news!
-
Hello,
I have a question along the same lines. I have a user that wants to be able to not only remove selected cameras from a chunk, but also delete the physical jpg/image file from the system as well. I am scripting this with the API but have run into an interesting issue. The problem is that when the script is run not all of the selected cameras are removed from the active chunk.
Code:
if cameraCount > 0:
for camera in chunk.cameras:
if camera.selected:
print(camera.label)
chunk.cameras.remove(camera)
This is simple code. If I rerun the script multiple times I am able to remove all the selected cameras, but I don't want the users to have to rerun multiple times. I am running Photoscan Professional 0.9.1 build 1714 64 bit.
Thanks!
Josh
-
Hello Josh,
I assume that the problem is in fact that you are removing elements from the list used in the loop.
I suggest to use the following loop definition:
for camera in list(chunk.cameras):
It should work correctly for the single run.
-
Fantastic! That worked. Is this a Python specific thing? Can you tell me why I had to specify that it was an array?
Thanks!
Josh
-
Hello Josh,
It's a Python trick. However, there are other methods of element removal from list while iterating overt it, but it seems the most easy one.
When you use list(chunk.cameras) it means that new lit is created and you are moving through it and not the one you are removing elements from.
Another option is to add cameras to be removed to new list and then use chunk.cameras.remove(cam_list). I think it should also work.
-
Dear friend, in python, list() will create you a copy of the camera collection. So you iterate over the temporarly copied list, while you remove the true/permanent list. If you don't do that, you will remove elements from a list, that you iterate over. Hope it gets clear? :)
-
All great information. Thank you for your help! Moving on. Next hurdle it to try to get a menu button for my script.
Thanks!
Josh
-
Hello Josh,
To add add button for your function you should use the following:
PhotoScan.app.addMenuItem("Custom menu/My script 1", new_func)
-
Hello Alexey,
Is there a way to load a script when PhotoScan opens? I would like to have this menu option available when a user opens PhotoScan.
Thanks!
Josh